read(2) on Tun fd returned zero












-1















In my application, a Tun interface was created and the process keep reading the associated fd with read(2) in a select(2) loop. But, when I was debugging an issue in the application, I found that in some moments the read(2) operation on the Tun file descriptor can return zero. Is this possible and what's the condition it can happen?



Thanks in advance.
woody










share|improve this question























  • you need to provide code, no one is able to help you with a simple description like this.

    – Mox
    Nov 23 '18 at 2:09













  • Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

    – Woody Wu
    Nov 23 '18 at 5:57











  • The guideline here is that you have to show the code, else there is no way anyone can help you here.

    – Mox
    Nov 23 '18 at 5:58
















-1















In my application, a Tun interface was created and the process keep reading the associated fd with read(2) in a select(2) loop. But, when I was debugging an issue in the application, I found that in some moments the read(2) operation on the Tun file descriptor can return zero. Is this possible and what's the condition it can happen?



Thanks in advance.
woody










share|improve this question























  • you need to provide code, no one is able to help you with a simple description like this.

    – Mox
    Nov 23 '18 at 2:09













  • Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

    – Woody Wu
    Nov 23 '18 at 5:57











  • The guideline here is that you have to show the code, else there is no way anyone can help you here.

    – Mox
    Nov 23 '18 at 5:58














-1












-1








-1








In my application, a Tun interface was created and the process keep reading the associated fd with read(2) in a select(2) loop. But, when I was debugging an issue in the application, I found that in some moments the read(2) operation on the Tun file descriptor can return zero. Is this possible and what's the condition it can happen?



Thanks in advance.
woody










share|improve this question














In my application, a Tun interface was created and the process keep reading the associated fd with read(2) in a select(2) loop. But, when I was debugging an issue in the application, I found that in some moments the read(2) operation on the Tun file descriptor can return zero. Is this possible and what's the condition it can happen?



Thanks in advance.
woody







linux tun tun-tap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 2:00









Woody WuWoody Wu

705




705













  • you need to provide code, no one is able to help you with a simple description like this.

    – Mox
    Nov 23 '18 at 2:09













  • Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

    – Woody Wu
    Nov 23 '18 at 5:57











  • The guideline here is that you have to show the code, else there is no way anyone can help you here.

    – Mox
    Nov 23 '18 at 5:58



















  • you need to provide code, no one is able to help you with a simple description like this.

    – Mox
    Nov 23 '18 at 2:09













  • Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

    – Woody Wu
    Nov 23 '18 at 5:57











  • The guideline here is that you have to show the code, else there is no way anyone can help you here.

    – Mox
    Nov 23 '18 at 5:58

















you need to provide code, no one is able to help you with a simple description like this.

– Mox
Nov 23 '18 at 2:09







you need to provide code, no one is able to help you with a simple description like this.

– Mox
Nov 23 '18 at 2:09















Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

– Woody Wu
Nov 23 '18 at 5:57





Maybe I did not put it clear. Some info I provided is for giving a context, the real question in the post is: in what condition read(2) on a Tun file descriptor can return 0. If copy/paste the code, it would contain a lot of irrelevant information.

– Woody Wu
Nov 23 '18 at 5:57













The guideline here is that you have to show the code, else there is no way anyone can help you here.

– Mox
Nov 23 '18 at 5:58





The guideline here is that you have to show the code, else there is no way anyone can help you here.

– Mox
Nov 23 '18 at 5:58












1 Answer
1






active

oldest

votes


















1














Here is the information from the manpage on read(2)click here




Return Value



On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.







share|improve this answer
























  • Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

    – Woody Wu
    Nov 23 '18 at 9:14











  • EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

    – Mox
    Nov 23 '18 at 10:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439835%2fread2-on-tun-fd-returned-zero%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Here is the information from the manpage on read(2)click here




Return Value



On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.







share|improve this answer
























  • Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

    – Woody Wu
    Nov 23 '18 at 9:14











  • EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

    – Mox
    Nov 23 '18 at 10:15
















1














Here is the information from the manpage on read(2)click here




Return Value



On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.







share|improve this answer
























  • Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

    – Woody Wu
    Nov 23 '18 at 9:14











  • EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

    – Mox
    Nov 23 '18 at 10:15














1












1








1







Here is the information from the manpage on read(2)click here




Return Value



On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.







share|improve this answer













Here is the information from the manpage on read(2)click here




Return Value



On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 6:01









MoxMox

1,1881228




1,1881228













  • Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

    – Woody Wu
    Nov 23 '18 at 9:14











  • EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

    – Mox
    Nov 23 '18 at 10:15



















  • Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

    – Woody Wu
    Nov 23 '18 at 9:14











  • EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

    – Mox
    Nov 23 '18 at 10:15

















Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

– Woody Wu
Nov 23 '18 at 9:14





Yes, I knew read(2) in general. But I don't understand what means EOF for a tun device which was created by the same process that called the read(2).

– Woody Wu
Nov 23 '18 at 9:14













EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

– Mox
Nov 23 '18 at 10:15





EOF means end of file which indicates that the file offset is current at the end. This can mean there is no more data to be read.

– Mox
Nov 23 '18 at 10:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439835%2fread2-on-tun-fd-returned-zero%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]