-rob
Thanks for the comments. Let me explain a bit more about what we're
trying to do.
A server accepts client connections on a listener.
For each connection, it spawns a "handler" goroutine to deal with the
client session.
In turn, the handler spawns a "reader" and a "writer".
Then the handler sits in a loop, reading from its channel.
Messages to this handler channel can come from two places: another
goroutine in the server, or the "reader".
The reader is blocked in Read on the socket. If it reads something, it
sends a message to the handler.
If the handler wants to write to the socket, it sends a message to the
writer. Another design could have the handler write to the socket
directly. Here be trade-offs.
If the client closes the socket, the reader gets an EOF, sends a
message to the handler and shuts down.
Now the question is what happens when the server decides that one of
the handlers should terminate.
It sends a message to the handler on its channel. The handler now has
to shut down the reader.
How does it do that? Can it simply close the socket that the reader is
doing a blocking Read on? If it can, then having a reader that uses a
gob Decoder will work fine.
If not, the reader has to set a read timeout and check for a shutdown
request periodically.
Thanks.
Regards
Albert
by experiment (on macos x) this works fine.
the documentation should probably say it's ok to
do this though, as the convention is that it's
not allowable to call methods concurrently on a value.
interestingly, closing a tcp Listener does not cause
an Accept to terminate - i guess that means there's
no way to listen on a port and then stop listening on that port.
On Wed, Jan 19, 2011 at 11:30 AM, roger peppe <rogp...@gmail.com> wrote:
> On 19 January 2011 08:35, Albert Strasheim <ful...@gmail.com> wrote:
>> How does it do that? Can it simply close the socket that the reader is
>> doing a blocking Read on? If it can, then having a reader that uses a
>> gob Decoder will work fine.
> by experiment (on macos x) this works fine.
> the documentation should probably say it's ok to
> do this though, as the convention is that it's
> not allowable to call methods concurrently on a value.
Thanks for the feedback. I'll give it a try.
With regards to Accept, I think you're seeing this issue:
http://code.google.com/p/go/issues/detail?id=1059
Another related issue which can cause problems with this approach is:
http://code.google.com/p/go/issues/detail?id=1058
Regards
Albert
yes. package net works hard to make sure
Close cancels any pending Read and Write calls.
> interestingly, closing a tcp Listener does not cause
> an Accept to terminate - i guess that means there's
> no way to listen on a port and then stop listening on that port.
are you seeing this at tip? i thought we fixed that
in late december.
russ
yes i am.