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

Re: Network write() stalls with 'Resource temporarily unavailable'



> 
> > I'm wondering if it is EWOULDBLOCK by a different name... You've not got a > non blocking socket by some chance ? What is the actual value of errno ?
> 
> Non-blocking, correct. 
> 
> errno = 11
> 
Yes, EAGAIN or EWOULDBLOCK depending on which name you like to give it.
In this case its doing the correct thing.

> 
> If that's the problem, then what do you think of this as a solution:
> 
> write(fd, data, len)
> if (EWOULDBLOCK) then
>    pthread_create(do_blocking_write(),fd,data,len)
> continue ...
> 
> void do_blocking_write()
>   set_fd_blocking
>   write(fd, data, len)
>   set_fd_non_blocking
>   return
> 
You could do this certainly, as to whether its a good idea or not would
really depend upon you application. 

What it won't do for you is increase the rate at which data is sent through
the socket. You can only increase the rate by waiting for the socket to
gain round trip timing information, or by opening more than one socket
at the same time and sending in parallel.

Spawning a thread if the socket blocks
is not efficient unless the amount of data to be transferred is large (and
thus time consuming). You might want to consider pre-spawned thread pools
and also using select() to feed a number of sockets whenever they are ready.
For really high performance, I'd suggest one thread per processor (assuming
an SMP system) and select() in a loop allocating the incoming connections
to threads in a round robin fashion as a starting point.

> 
> An associated question : 
> 
> Lets say I block on the second packet, and spawn a new (blocking) thread
> to take care of it, and I want to send another packet. If I spawn a
> (blocking) thread to take care of this one, can I be certain that they
> will complete in the order the write() functions took place ?
>
You can be sure that the write() functions will take place in the order
that they are called, but to ensure that they are called in a particular
order you'd have to have some kind of synchronisation between the threads.
Probably this won't give the effect you want to acheive though,

Steve.

-----------------------------------------------------------------------------
To unsubscribe from this list, send a mail to majordomo@dreamtime.org
containing the line "unsubscribe linux-decnet"
-----------------------------------------------------------------------------