[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

RE: [Libevent-users] Proper socket shutdown.



Hi Nick,

> >>       So, I've managed to poke around just a little since sending the
> >> example code and not really found anything interesting as of yet but
> had
> >> an
> >> evil thought.  I started wondering about the "shutdown" function being
> >> unreliable with IOCP from your information.  I can't say for sure but I
> >> started thinking about it and have a guess as to the problem which I
> will
> >> be
> >>
> >>       This certainly seems like an evil stupid thing IOCP could be
> doing
> >> here. :(
> >
> >        Nope, wasn't this.  Can't even get EOF using the
> WSASendDisconnect
> > calls, something is definitely wrong at a lower level.  Will dig into it
> > more as I find time.
> 
> Were you able to try DisconnectEx, or is that our next best bet?

	Got the fix.  Fricken IOCP strangness bites again.  You just have to
insert a call to:

	int err = setsockopt( fd, 
		SOL_SOCKET, 
		SO_UPDATE_ACCEPT_CONTEXT, 
		(char *)&listener, 
		sizeof(listener) );

	The fd is the socket you accepted from the call to AcceptEx and the
listener is of course the listener socket.  I did this in the listener
callback and don't know exactly where in libevent proper it should be added.
If you point me in the correct direction I'll post a patch if you want, or
you can drop it in there pretty easy.

	With this fix, shutdown and WSASendShutdown worked fine and I was
able to get clean disconnects as desired.

KB

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.