Re: sending large messages over sockets in non blocking mode

From: John Zweizig (jzweizig@ligo.caltech.edu)
Date: Thu Apr 08 1999 - 00:36:53 MEST


On Wed, 7 Apr 1999, Judith Katzy wrote:

> 
> hi John,
> 
> Root takes care of splitting the message into pieces that matches the 
> buffersize of the system  and sending them (see Fons' email to roottalk). 

That may be what he wants it to do, but it doesn't seem to be what the
code does. The appropriate function in root is 

int TUnixSystem::UnixSend(int sock, const void *buffer, int length, int flag)
{
   // Send exactly length bytes from buffer. Returns -1 in case of error,
   // otherwise number of sent bytes.

   if (sock < 0) return -1;

   int n, nsent = 0;
   const char *buf = (const char *)buffer;

   for (n = 0; n < length; n += nsent) {
      if ((nsent = send(sock, buf+n, length-n, flag)) <= 0) {
         ::SysError("TUnixSystem::UnixSend", "send");
         return nsent;
      }
   }
   return n;
}

According to my favorite Unix reference (the Solaris man pages) 

     If space is not available at the sending  socket
     to  hold  the  message to be transmitted and the socket file
     descriptor does have O_NONBLOCK set, send() will fail.   The
     select(3C)  and  poll(2)  functions can be used to determine
     when it is possible to send more data.

     ...

     Upon successful completion, send()  returns  the  number  of
     bytes  sent.   Otherwise, -1 is returned and errno is set to
     indicate the error.

So, if send doesn't have enough buffer space in a blocking socket, it will
not send the message but will return -1. Root will call SysError() and
return with -1. 

By the way, if you dig through the TSocket.h file you will find that the 
appropriate way to set the send buffer length is to call 

 TSocket::SetOption(kSendBuffer, length);

> I suspect (if I didn't do anything wrong), that something goes wrong with
> the synchronizing of these packages if the socket is in non-splitting mode.
> 
> cheers,
> Judith

Cheers,

John



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:31 MET