Q: Making boost::asio::ip::tcp::acceptor non-blocking I've been trying to make a non-blocking TCP server of sorts using tcp::acceptor. I've done this before using BSD sockets and C(++) but unable to set non blocking I/O using boost.
C(++):
#ifdef WIN32
  int mode = 1;
  ioctlsocket(Socket, FIONBIO, (u_long FAR *) &mode);
#else
  fcntl(Socket, F_SETFL, fcntl(Socket, F_GETFL) | O_NONBLOCK);
#endif

And I need the equivalent under the TODO:
// reuse address

m_Socket.set_option( boost::asio::socket_base::reuse_address( true ) );

// TODO: set non blocking

// listen

m_Socket.listen( );

Much obliged!

A: Use async_accept.

A: Since I'm actually refactoring old C++ code the accept() function (if could be set nonblocking) would fit quite nicely. I tried to avoid async functions due to the entire concept being unfamiliar to me:
tcp::socket *CTCPServer :: AsyncAccept( )
{
  tcp::socket *Socket = new tcp::socket( *m_Service );
  m_Socket.async_accept( *Socket, endpoint, boost::bind( &CTCPServer::HandleAccept, this ) );

  return Socket;
}

Is something like this possible (it succeeded with accept())? Basically I have a CTCPServer class which listens, if a connection is established, I make a CTCPSocket( io_service *, socket * ) which fails with "Bad file descriptor" (and it's not a problem in the io_service).
My test main:
tcp::socket *Socket;
CTCPServer Server( &io_service, 6667 );

while( true )
{
  if( ( Socket = Server.AsyncAccept( ) ) )
  {
    CTCPSocket TCPSocket( &io_service, Socket ); // fails
    TCPSocket.PutBytes( "stack overflow" );
    TCPSocket.DoSend( );
   }
}

Tell me if you need more of the, if I can call it, source.
