Making AppHost.Stop() works

6 views
Skip to first unread message

debackerl

unread,
Dec 29, 2010, 3:55:14 AM12/29/10
to Manos de Mono
Hi,

I'm running manos 0.1.1 on MS.NET 4.0. I'm starting the event loop in
a new thread, and would like to stop it when the application has to
quit.

Here are the modifications I had to do to make it work:

IOLoop.HandlePrepareEvent (Loop loop, PrepareWatcher watcher,
EventTypes revents):
Don't do loop.Unloop (UnloopType.Cancel); I believe it cancels the
unloop, so I do loop.Unloop (UnloopType.All);

HttpServer.HandleIOEvents (Loop loop, IOWatcher watcher, EventTypes
revents):
When you catch SocketException, if it's not a wouldblock or tryagain,
I believe it should only happend when the server socket has been
closed. So intead of writing a message, you should do:
iowatcher.Stop(); just before the return

AppHost.Stop():
After ioloop.Stop ();, I do server.Dispose (); to close the server
socket.

So what happens now, is that AppHost.Stop will close the socket, this
will trigger an event on the socket, the event handler of HttpServer
will process it, and detect the SocketException, as a result we stop
the event loop in the prepare event.

Well this works, but it is maybe not the nicest way. Instead, we
should propose a BeginStop method closing the server socket, and some
timers, and waiting for pending I/O to complete. After a timeout
defined to BeginStop, the event loop should be cancelled if I/O are
still pending. Thay way, if manos is behind a load balancer, it will
process all received client connections, but stop receiving new ones.

Finally, why don't you dipose 'iowatcher' in the Dispose method of
HttpServer?

Remember, all this is based on manos 0.1.1. HEAD was not compiling
fine on my MS.NET 4.0.

Laurent Debacker

jacksonh

unread,
Jan 3, 2011, 2:15:38 PM1/3/11
to Manos de Mono


On Dec 29 2010, 3:55 am, debackerl <deback...@gmail.com> wrote:
> Hi,
>
> I'm running manos 0.1.1 on MS.NET 4.0. I'm starting the event loop in
> a new thread, and would like to stop it when the application has to
> quit.
>
> Here are the modifications I had to do to make it work:
>

Thanks, for this and sorry for the long delay in replying. I was
attempting to not think about webservers over the holidays.

I'll try to integrate some of this stuff into the next release. I've
also added the AsyncWatcher, so that should make things a little
simpler too.

Cheers,
Jackson
Reply all
Reply to author
Forward
0 new messages