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!
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:
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:
Tell me if you need more of the, if I can call it, source.