Overview
Features
Download
Documentation
Community
Add-Ons & Services

Poco::Net::ErrorNotification when will it happen?

Please post support and help requests here.

Poco::Net::ErrorNotification when will it happen?

Postby jowa » 30 Oct 2012, 21:04

We have a client/server application developed using Poco socket APIs.
On the client side, there are the following codes to add call backs to
readable and error event callbacks:

Poco::Net::SocketReactor clientReactor;
Poco::NObserver<ClientController, Poco::Net::ReadableNotification> obs(*this, &ClientController::onReadable );
Poco::NObserver<ClientController, Poco::Net::ErrorNotification> obsError(*this, &ClientController::onSocketError);
...
/*socket is a pointer of Poco::Net::StreamSocket type*/
clientReactor.addEventHandler(*socket, obs);
clientReactor.addEventHandler(*socket, obsError);

Poco::Thread notificationThread;
notificationThread.start(clientReactor);

I found that when the server is shutdown with a CTRL-C, a 'kill -9' or a network interface restart,
the ErrorNotification event did not get fired. Instead, the ReadableNotification event gets fired,
and the receiveBytes() on socket returns 0 bytes, which implies a socket shutdown.

How can a socket error condition be produced which causes the ErrorNotification event to be fired?

Thank you!
jowa
 
Posts: 6
Joined: 07 Sep 2012, 22:44

Re: Poco::Net::ErrorNotification when will it happen?

Postby alex » 30 Oct 2012, 22:58

jowa wrote:How can a socket error condition be produced which causes the ErrorNotification event to be fired?

Exact behavior will depend on POCO version, your platform and select/poll/epoll implementation.
SocketReactor will notify
Code: Select all
for (Socket::SocketList::iterator it = except.begin(); it != except.end(); ++it)
   dispatch(*it, _pErrorNotification);

whatever Socket::select() flags:
Code: Select all
rc = ::select(nfd + 1, &fdRead, &fdWrite, &fdExcept, &tv);
//...
SocketList readyExceptList;
for (SocketList::const_iterator it = exceptList.begin(); it != exceptList.end(); ++it)
{
   poco_socket_t fd = it->sockfd();
   if (fd != POCO_INVALID_SOCKET)
   {
      if (FD_ISSET(fd, &fdExcept))
         readyExceptList.push_back(*it);
   }
}

The above code is for platform select() call. Depending on POCO version and platform Socket::select() may be implemented in terms of poll() or epoll().
alex
 
Posts: 1113
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron