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

Cancelling a blocking read() from a different thread



Is there any way of forcing a blocked call to `read(s)' (where `s' is for
a socket) in a different thread, to return immediately with an error?

I've looked on various Unix/pthread newsgroups with Google, and there are
various suggestions such as closing the socket, writing to it, using
shutdown() etc. However, none of these seems to work on OpenBSD 3.2 - they
all block.

I guess I could try and use a signal, but I don't really want to get
involved in the complications involved with using signals and threads
together.

The only other way I can think of would be to open a pipe between the two
threads, and write a single byte to one end of this pipe when I want to
cancel the read. The call to read() would first do a select() on the
socket and the other end of the pipe, returning an error directly if
anything has been sent to the pipe.

Any advice would be much appreciated.

Thanks,

- Julian

-- 
http://www.op59.net