Re: socket read,recv / signal handling
phil-news-nospam_at_ipal.net
Date: 04/14/04
- Next message: phil-news-nospam_at_ipal.net: "Re: socket read,recv / signal handling"
- Previous message: phil-news-nospam_at_ipal.net: "Re: Query a DNS in C"
- In reply to: Florian Zschocke: "Re: socket read,recv / signal handling"
- Next in thread: Barry Margolin: "Re: socket read,recv / signal handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Apr 2004 20:28:24 GMT
On 13 Apr 2004 10:47:09 GMT Florian Zschocke <edv@zschocke-berlin.de> wrote:
| Materialised <Materialised@privacy.net> wrote:
|>
|>int nbytes, sockfd;
|>char buf[1000]; //Or whatever
|>
|>//... rest of code
|>if ((nbytes = recv(sockfd, buf, sizeof(buf), 0)) <= 0) {
|> perror("recv");
|> // Do whatever else you wanna do
|>}
|>
| Thank you,
| I did test that before- sorry thought I wrote that.
| There is no value <= 0 and the socket is gone.
| In the debugger there is the last statement: recvfrom16 and the program quits with bad_access.
Are you saying that after the socket is closed by the server, that doing
a recv() gives you a return value that is not -1? If there is any error
at all, it should give you a -1 return value and put more information as
to what the error is in the variable errno. A socket closed on the other
end would be an error once the fact of that closure has reached the host
the recv() call is taking place on.
Is your program design doing a main loop waiting for some kind of event
or I/O status? A typical setup in Unix is a loop within which select()
or poll() is called on multiple file descriptors, and that call wakes up
when a condition is ready on one or more of them (or an optional timeout).
The peer closing a socket would be such an event, and doing a recv() on
that socket would get the -1 return value, and errno would have the code
for the error reason.
If OS X is not returning -1 on error in recv(), then it does not conform
to POSIX.
-- ----------------------------------------------------------------------------- | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ | | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ | -----------------------------------------------------------------------------
- Next message: phil-news-nospam_at_ipal.net: "Re: socket read,recv / signal handling"
- Previous message: phil-news-nospam_at_ipal.net: "Re: Query a DNS in C"
- In reply to: Florian Zschocke: "Re: socket read,recv / signal handling"
- Next in thread: Barry Margolin: "Re: socket read,recv / signal handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|