FAQ

On 2016-03-26 09:52, Jakob Borg wrote:
On 26 mars 2016, at 09:13, Peter Mogensen wrote:

Now... http.Serve() is very explicit that it insists on calling Close() on the listener on exit.
Could you not simply wrap the listener in a type of your own that pretends to Close(), and instead has an actuallyCloseForReal() method that you can use, for example?
Yes... I could. ... but I tried to avoid that.

It would break any Serve(l) implementations which did something like:

switch l.(type) {
case *net.TCPListener:
case *net.UNIXListener:
}

Or simply (as I've seen code do) type assert the net.Listener to a
*net.TCPListener to access SetDeadline()

In the end ... it seems like there's only two options here:

1) Wrap the listener as you suggest, and break any Serve(l)
implementation which depends on the specific type of the listener.

2) Have the framework maintaining the file descriptors (..., *os.Files
and/or packetconns/listeners) ensure there's a dup(2) of the file
descriptor to avoid the socket to be closed when code like
http.Server.Serve(l) calls Close(). That would mean, call File() and
then afterwards call syscall.SetNonblock(fd,true) to undo the blocking.

/Peter

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 19 of 21 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 16, '16 at 10:04a
activeMar 30, '16 at 10:56a
posts21
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase