discuss-gnustep
[Top][All Lists]
Advanced

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

write to socket problem


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

Hi all,

I have an Objective-C tool that offers its service (route-calculation) via a TCP-socket. A client connects, orders the calculation of a route and when the method has calculated the result it is written back with the following code:

      FD_ZERO(&fdset);
      FD_SET(_sock, &fdset);
switch (select(_sock+1, NULL, &fdset, NULL, (_timeout.tv_sec == 0 ? NULL : &_timeout)))
        {
         case -1:
            [_writeLock unlock];
[NSException raise:SRFileHandleWriteException format:@"poll() call in %@ returned error: %i", NSStringFromSelector(_cmd), errno];

         case 0:
            [_writeLock unlock];
[NSException raise:SRFileHandleTimeoutException format:@"poll() call in %@ timed out after %u seconds.", NSStringFromSelector(_cmd), _timeout.tv_sec];
        }
     ret = send(_sock, dataStart + pos, length - pos, 0);

This usually works. However the client disconnects after 75s (this seems to be a built-in timeout on Solaris). If this happens and calculation takes more than 75s and finally after may be 2 minutes the service tries to write the result to the (already closed on the reading end) socket, the

     ret = send(_sock, dataStart + pos, length - pos, 0);

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!

What can I do?

Thanks a lot,

 Andreas





reply via email to

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