C sockets - client continue reading after close file descriptor on server side
up vote
0
down vote
favorite
I'm going to conclude an accademic project written in C: the project consist in a multithreaded chat server using AF_UNIX sockets, so both client and server run on the same machine.
In summary the program run a main thread where happends the initialization (structures, data, ect..) and a pool of threads that serve clients request.
The problem appear when a client wait for the last of a list of messages (with a read() call) and for istance i raise a termination signal to the server while the client is still waiting (Let me clarify, this is not the normal sequence of events, but it may happend for some reason), at this point the server does all the closure procedures that it is supposed to do and after that, it finish correctly.
My doubt is about the client because when the server close the file descriptor of the socket where they comunicated before, it endlessy start to recive the second-last message that it recived but i don't know why.
I write some details that can be useful for answer:
-The server (in the main thread) uses epoll function for detecting new connections and new requests
-All messages exchange happends in threads
-Communication happneds through readv and writev
I hope I was enough clear and i will reply for all further clarification.
Thank you all in advance
c sockets epoll
add a comment |
up vote
0
down vote
favorite
I'm going to conclude an accademic project written in C: the project consist in a multithreaded chat server using AF_UNIX sockets, so both client and server run on the same machine.
In summary the program run a main thread where happends the initialization (structures, data, ect..) and a pool of threads that serve clients request.
The problem appear when a client wait for the last of a list of messages (with a read() call) and for istance i raise a termination signal to the server while the client is still waiting (Let me clarify, this is not the normal sequence of events, but it may happend for some reason), at this point the server does all the closure procedures that it is supposed to do and after that, it finish correctly.
My doubt is about the client because when the server close the file descriptor of the socket where they comunicated before, it endlessy start to recive the second-last message that it recived but i don't know why.
I write some details that can be useful for answer:
-The server (in the main thread) uses epoll function for detecting new connections and new requests
-All messages exchange happends in threads
-Communication happneds through readv and writev
I hope I was enough clear and i will reply for all further clarification.
Thank you all in advance
c sockets epoll
Are you checking the return-value yourread()calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really theread()call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)
– Jeremy Friesner
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm going to conclude an accademic project written in C: the project consist in a multithreaded chat server using AF_UNIX sockets, so both client and server run on the same machine.
In summary the program run a main thread where happends the initialization (structures, data, ect..) and a pool of threads that serve clients request.
The problem appear when a client wait for the last of a list of messages (with a read() call) and for istance i raise a termination signal to the server while the client is still waiting (Let me clarify, this is not the normal sequence of events, but it may happend for some reason), at this point the server does all the closure procedures that it is supposed to do and after that, it finish correctly.
My doubt is about the client because when the server close the file descriptor of the socket where they comunicated before, it endlessy start to recive the second-last message that it recived but i don't know why.
I write some details that can be useful for answer:
-The server (in the main thread) uses epoll function for detecting new connections and new requests
-All messages exchange happends in threads
-Communication happneds through readv and writev
I hope I was enough clear and i will reply for all further clarification.
Thank you all in advance
c sockets epoll
I'm going to conclude an accademic project written in C: the project consist in a multithreaded chat server using AF_UNIX sockets, so both client and server run on the same machine.
In summary the program run a main thread where happends the initialization (structures, data, ect..) and a pool of threads that serve clients request.
The problem appear when a client wait for the last of a list of messages (with a read() call) and for istance i raise a termination signal to the server while the client is still waiting (Let me clarify, this is not the normal sequence of events, but it may happend for some reason), at this point the server does all the closure procedures that it is supposed to do and after that, it finish correctly.
My doubt is about the client because when the server close the file descriptor of the socket where they comunicated before, it endlessy start to recive the second-last message that it recived but i don't know why.
I write some details that can be useful for answer:
-The server (in the main thread) uses epoll function for detecting new connections and new requests
-All messages exchange happends in threads
-Communication happneds through readv and writev
I hope I was enough clear and i will reply for all further clarification.
Thank you all in advance
c sockets epoll
c sockets epoll
asked Nov 12 at 17:31
Alessandro Meschi
367
367
Are you checking the return-value yourread()calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really theread()call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)
– Jeremy Friesner
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32
add a comment |
Are you checking the return-value yourread()calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really theread()call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)
– Jeremy Friesner
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32
Are you checking the return-value your
read() calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really the read() call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)– Jeremy Friesner
Nov 12 at 17:34
Are you checking the return-value your
read() calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really the read() call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)– Jeremy Friesner
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267268%2fc-sockets-client-continue-reading-after-close-file-descriptor-on-server-side%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Are you checking the return-value your
read()calls in the client and responding correctly to it? (I only ask because a lot of new network programmers will ignore the return value and just assume that a full buffer was received, which leads to them believing that they are receiving the same content over and over again when really theread()call returned 0/EOF or a negative/error value instead, and left their buffer un-modified)– Jeremy Friesner
Nov 12 at 17:34
The client is not repeatedly receiving the message. Instead, there is a bug in your client code that is causing it to repeatedly output that message.
– William Pursell
Nov 12 at 17:34
Yes you were both right. The problem was in the client code code in the return value of my readMessage() function. Thanks for your help
– Alessandro Meschi
Nov 13 at 8:32