TCP Server and ConnectionAbortedException

Please post support and help requests here.
Posts: 14
Joined: 19 Jul 2006, 22:28

TCP Server and ConnectionAbortedException

Postby merdem » 15 Mar 2007, 17:47

Hello all,

Here is the scenario:

I have a TCPServer running and accepting connections. I implemented my own MyTCPServerConnectionFactory which keeps record of the MyTCPServerConnections it creates and dispatches. This allows me to access the MyTCPServerConnection objects when they are running.

In each MyTCPServerConnection run() method, I do something like this:

^void MyTCPServerConnection::run() {
DialogSocket dialog_socket(this->socket());
std::string msg;
try {
while(dialog_socket.receiveMessage(msg)) {
} catch (ConnectionAbortedException e) {
std::cout << "Connection closed by foreign host...

So far so good. The TCPServerConnection socket is blocking (I believe it is default). At some point I want to terminate the connection socket. Remember I can access the MyTCPServerConnection object, so I call my own method on the object:

^void MyTCPServerConnection::shutdown() {

According to the socket information I read, the call to shutdown() on a blocking socket should wake it and it does but it throws the ConnectionAborted (or WSAECONNABORTED in Winsock, I am using Windows) exception. Again according to the winsock documentation:


Software caused connection abort.

An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error.^

But the UNIX documentation on socket() does not list the EACONNABORTED as an error produced by a socket but only by the accept(). So, I am confused.

To make it more complicated, if I create a DialogSocket (as a client) and connect it to a server, read block it and call shutdown(), it does not throw any exceptions but just returns 0.

I am pretty sure I am missing something somewhere...

Thank you,


Posts: 14
Joined: 19 Jul 2006, 22:28

Re: TCP Server and ConnectionAbortedException

Postby merdem » 15 Mar 2007, 18:39


I stand corrected. In the run() method above, when the dialog_socket is blocked on the read operation and another thread calls the shutdown(), dialog_socket does NOT wake-up...

Posts: 1256
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: TCP Server and ConnectionAbortedException

Postby guenter » 16 Mar 2007, 11:55


instead of shutting down the socket, you could simply close() it, which should cause receiveMessage() to throw.
You could also call select() or poll() before you call receiveMessage(), and only call receiveMessage() if select() indicates that there is data available. If you call select() with a reasonable timeout (e.g. 100ms), you could also periodically poll a "close-connection" flag, and, instead of closing the socket from the outside (another thread), simply return from run(), which will close the socket.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests