Boost.Asio, An invalid argument was supplied.

Hello. I am trying to write a simple server, and I am using an asynchronous acceptor to get clients: acceptor.async_accept(crtclient->getSocket(), boost::bind(&Server::gotClient, this, boost::asio::placeholders::error)); As soon as this is executed, my Server::gotClient gets called with ec.message()="An invalid argument was supplied." Apparently the problem is that I am supplying an invalid socket with crtClient->getSocket(), but I can't understand how can this be. crtClient is a boost::shared_ptr<Client>. class Client { ... public: Client (boost::asio::io_service &ioserv, Server &server) : socket_(ioserv), ... {} ... boost::asio::ip::tcp::socket &getSocket () { return socket_; } ... private: boost::asio::ip::tcp::socket socket_; ... }; What could be wrong? Am I constructing socket incorrectly with socket_(ioserv)? Because if I construct it with socket_(ioserv, boost::asio::ip::tcp::v4()), I get the error "Already open" in ec.message(), rather than "An invalid argument was supplied".

Hi,
The lines of code you posted seem to be ok, so the problem is somewhere in
the code you haven't posted here. Ensure that your io_service is initialized
*before* you pass it to the other asio objects, and that the socket is
initialized before you pass it to the acceptor.
Here is an example of how you should use the acceptor:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/reference/basic_soc...
2008/11/23 stefys
Hello. I am trying to write a simple server, and I am using an asynchronous acceptor to get clients: acceptor.async_accept(crtclient->getSocket(), boost::bind(&Server::gotClient, this, boost::asio::placeholders::error)); As soon as this is executed, my Server::gotClient gets called with ec.message()="An invalid argument was supplied." <...> What could be wrong? Am I constructing socket incorrectly with socket_(ioserv)? Because if I construct it with socket_(ioserv, boost::asio::ip::tcp::v4()), I get the error "Already open" in ec.message(), rather than "An invalid argument was supplied".
participants (2)
-
Igor R
-
stefys