I'm trying to detect that a peer has been disconnected using the asio socket
library. Below is a source listing of a unit test that I have created (which
is one of several that I have tried; ask for more listings if nesasary) to
figure out a reliable method to do so.
I've also tried using (and have unit test listings for) the
availble(errorCode) call the sock1.remote_endpoint(errorCode); calls.
I need a way to detect that a client has been disconnected from my server
without blocking.
I've even tried using the read_some call with the io_control non_blocking
option set but the then read some returns an error every time read_some is
called.
[code]
for(int i=0;i<1;i++)
{
boost::asio::io_service ioServ1;
boost::asio::io_service ioServ2;
boost::asio::io_service ioServ3;
boost::asio::io_service ioServ4;
boost::asio::ip::tcp::socket sock1(ioServ1);
boost::asio::ip::tcp::socket sock3(ioServ3);
SocketAcceptor sA1(ioServ1,sock1,std::string("localHost"),8321);
SocketAcceptor sA2(ioServ3,sock3,std::string("localHost"),8322);
// The socket acceptor class simple starts a thread and and
accept(_mySocket,ec)
// with a boost::asio::ip::tcp::acceptor. If thread does not completed
in the time passed in
//the milliseconds then the call then the the accept call will return.
sA1.accept(10);
sA2.accept(10);
boost::asio::ip::tcp::socket sock2(ioServ2);
boost::asio::ip::tcp::socket sock4(ioServ4);
boost::asio::ip::tcp::resolver resolver1(ioServ2);
boost::asio::ip::tcp::resolver::query query1(boost::asio::ip::tcp::v4(),
"localhost", (boost::lexical_caststd::string(8321)).c_str());
boost::asio::ip::tcp::resolver::iterator iterator1 =
resolver1.resolve(query1);
boost::asio::ip::tcp::resolver resolver2(ioServ4);
boost::asio::ip::tcp::resolver::query query2(boost::asio::ip::tcp::v4(),
"localhost", (boost::lexical_caststd::string(8322)).c_str());
boost::asio::ip::tcp::resolver::iterator iterator2 =
resolver2.resolve(query2);
sock2.connect(*iterator1);
sock4.connect(*iterator2);
TS_ASSERT_EQUALS(sA1.accept(200),true);
TS_ASSERT_EQUALS(sA2.accept(200),true);
boost::system::error_code errorCode;
//std::cout<<"about to read some from socket"<