[comp.unix.internals] question on select

abdik@cat.syr.EDU (Ahmad Dik) (11/15/90)

I would like to know if select() can be used to find out if there is
a blocked read on a socket.

In other words, will the second parameter of the select() function
tell me if the socket's buffer is empty, and I can write to it, or  
does it tell me that there is someone blocked trying to read from the socket.

If select can not be used to tell if anyone is blocked reading on a
socket, is there any other way I can find out ??


:Ahmad Deek
abdik@cat.syr.edu

thorinn@rimfaxe.diku.dk (Lars Henrik Mathiesen) (11/16/90)

abdik@cat.syr.EDU (Ahmad Dik) writes:
>I would like to know if select() can be used to find out if there is
>a blocked read on a socket.

It can't. And if the other end of the socket is on another machine, I
don't see how any system call could help find this info if general.
The TCP protocol has no way of getting the info, and things like UDP
much less.

>If select can not be used to tell if anyone is blocked reading on a
>socket, is there any other way I can find out ??

If it's a UNIX-domain socket, you can open /dev/mem, find your own
file descriptor for the socket, find the socket, follow its peer link
and then go through the process table to find a process that's waiting
on the peer socket's receive socket buffer. That's probably the
easiest way to do it in general.

I suggest that you arrange some other form of cooperation between the
processes. If available, semaphores might be what you're looking for.

--
Lars Mathiesen, DIKU, U of Copenhagen, Denmark      [uunet!]mcsun!diku!thorinn
Institute of Datalogy -- we're scientists, not engineers.      thorinn@diku.dk

josef@nixdorf.de (Moellers) (11/16/90)

In <ABDIK.90Nov14162831@lion.cat.syr.EDU> abdik@cat.syr.EDU (Ahmad Dik) writes:


>I would like to know if select() can be used to find out if there is
>a blocked read on a socket.

>In other words, will the second parameter of the select() function
>tell me if the socket's buffer is empty, and I can write to it, or  
>does it tell me that there is someone blocked trying to read from the socket.

>If select can not be used to tell if anyone is blocked reading on a
>socket, is there any other way I can find out ??

The second parameter tells You if You can write to the socket.
That does not mean that the buffer has to be empty, just that there is
enough room to accomodate a write(). It doesn't tell You how much You'll
be able to write.
Needless to say: it's a vector with a bit for each fd.

To my knowledge there is no way of telling if anyone is blocked on the
other end of a connection as
1. the "other party" might be on a different machine far far away
2. the "other party" might not even be a UNIX box that knows what a
   "process" is or how one can "block".

--
=======
| Josef Moellers		| c/o Siemens Nixdorf Informatonssysteme AG |
|  USA: mollers.pad@nixdorf.com	| Abt. PXD-S14				    |
| !USA: mollers.pad@nixdorf.de	| Heinz-Nixdorf-Ring			    |