Exiting blocked threads (socket.accept)

Martin Drasar drasar at ics.muni.cz
Thu Mar 28 05:27:56 PDT 2013


On 28.3.2013 11:23, Tim wrote:
> Thanks Martin and Ali. Your solution works as long as I use the
> receive()-method, but what about using SocketStreams? I replaced
> socket.receive() with socketStream.readLine() which isn't broken by the
> solution above...

If you check the documentation, you will see that the SocketStream is a
stream for blocking socket. You can't easily make it work with
nonblocking select() calls.

However, if you want to use the stream interface, you can write the
non-blocking stream yourself. If you check the SocketStream at github
(https://github.com/D-Programming-Language/phobos/blob/master/std/socketstream.d),
you will see that it is pretty small and easy. You can transfer the
interrupt code inside the readBlock() method.

However, it will probably be for the best to just write your own method
to read for socket until the end of the line.

Martin


More information about the Digitalmars-d-learn mailing list