RE: ioctl always returns 0
RE: ioctl always returns 0
- Subject: RE: ioctl always returns 0
- From: "Mahesh Vyas" <email@hidden>
- Date: Tue, 12 Apr 2005 19:14:59 +0530
- Thread-topic: ioctl always returns 0
Hi
The code below works fine if the client crashes. However, if there is a
power failure or a shut down of the client machine, the code doesn't
yield the desired result and the server machine is not able to detect
the client disconnect.
Could you suggest something for this?
Rgds
Abhishek
-----Original Message-----
From: Vincent Lubet [mailto:email@hidden]
Sent: Thursday, March 04, 2004 8:57 PM
To: Mahesh Vyas
Cc: email@hidden
Subject: Re: ioctl always returns 0
On Mar 3, 2004, at 10:59 PM, Mahesh Vyas wrote:
> ioctl(mSocket,FIONREAD,&lDgramSize) always returns 0 irrespective of
> socket is closed or open.
> Our aim is , when client quits server should find out with above API
> whethe client still running or not.
This is not the correct way to find out the peer is disconnected.
Rather you should use recv() with the MSG_PEEK flags:
n = recv(mSocket, &buffer, 1, MSG_PEEK);
if (n == -1)
if (errno == EWOULDBLOCK)
no data
else
other error handling
else if (n == 1)
data is available
else if (n == 0)
peer is disconnected
Vincent
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden