zaphoyd/websocketpp — pull request #168 by matthewaveryusa (2012-12-18 05:06:46+00:00)
Title: concurrent thread pool fixed when spinning in a loop forever

In stop_listen, having the acceptor call close() before the join was causing handle_accept to loop with the following sequence of errors:

Starting WebSocket sleep server on port 9003 with thread pool size 2 and 2 worker threads.
2012-12-17T23:51:11 [8192] role::server listening on port 9003
2012-12-17T23:51:11 [8192] Connection created: count is now: 1
start_accept called
adding listening thread
adding listening thread
//-----> m_acceptor.close() called here
joining listening threads
2012-12-17T23:51:11 [16] async_accept returned error: system:125 (io_service operation canceled)
2012-12-17T23:51:11 [8192] terminate called from state: 0
2012-12-17T23:51:11 [8192] terminate removing connection
2012-12-17T23:51:11 [8192] Connection removed: count is now: 0
2012-12-17T23:51:11 [8192] Connection created: count is now: 1
start_accept called
2012-12-17T23:51:11 [16] async_accept returned error: system:9 (unknown)
2012-12-17T23:51:11 [8192] terminate called from state: 0
2012-12-17T23:51:11 [8192] terminate removing connection
2012-12-17T23:51:11 [8192] Connection removed: count is now: 0
2012-12-17T23:51:11 [8192] Connection created: count is now: 1
start_accept called
(repeat the previous 6 lines forever)

system:9, on my debian machine is from /usr/include/asm-generic/errno-base.h and corresponds to:
#define	EBADF	9	/* Bad file number */
I'm thinking it means that socket is closed at this point?

This may not be exactly what you want (I haven't studied the code base enough), but moving the m_acceptor.close() fixes the issue.

Thanks for the great work, this is a wonderful alternative to node and I'm looking forward to contribute/work with this a lot more!
-Matt