discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: write to socket problem


From: Andreas Höschler
Subject: Re: write to socket problem
Date: Thu, 8 Apr 2010 18:53:04 +0200

Hi David,

thanks for your prompt response!

call blocks and never returns and thus renders the service inoperable. I have already spent a couple of hours with the select, write, send,... documentation but haven't found a solution for this problem yet. Any idea how I can find out whether the reading end has closed? I expected select to do this, but it does not. select returns and FD_ISSET(_sock, &fdset)) gives me TRUE. But then the send blocks!

Unfortunately, there is no good way of doing this. The connection is being closed due to a timeout (and may be closed by a NAT in the way for the same reason). The solution that we use for XMPP is to send a space character every 50 seconds of inactivity. This works because the protocol is XML and cdata in the outer scope is ignored. You might consider something similar for your protocol.

The problem you are encountering is that this is not a graceful shutdown of the connection. When the connection times out, there is no tear-down of the TCP session, the other end just gives up. When you write to the socket, your server does not know that the other end has closed, so it will send the data and wait for the acknowledgement. It then waits for its own timeout period for this to be received.

Ah, that makes sense!

On most socket implementations (not sure if this includes Solaris), the a write on a blocking socket will block once the TCP window is full. The window will start to fill up if acknowledgements are not received for packets.

I am now comparing the time before and afte rthe invocation of the method. If more than 70s have passed, i ommit the write of the response. What an ugly hack!! :-( I need make this beast faster...

Thanks a lot,

 Andreas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]