Overview
Features
Download
Documentation
Community
Add-Ons & Services

is Poco::Net::SocketAddress threadsafe?

Please post support and help requests here.

is Poco::Net::SocketAddress threadsafe?

Postby AngryPowman » 20 Dec 2013, 08:26

i am using Poco::Net::SocketAddress in my connection implementation, but it seems wrong when connection graceful shutdown from the peer. it looks the std::string or SocketAddress has some problems in multi-thread? it crashed when run() returned. here is my code:

Code: Select all
TcpConnection::TcpConnection(const Poco::Net::StreamSocket& socket)
    : Poco::Net::TCPServerConnection(socket),
    _socket(const_cast<Poco::Net::StreamSocket&>(socket)),
    _buffer(new byte[MAX_RECV_LEN])
{
    _socket.setBlocking(false);
}

TcpConnection::~TcpConnection()
{
    SAFE_DELETE_ARR(_buffer);
    debug_log("connection destroyed.");
}

void TcpConnection::run()
{
    try
    {
        const Poco::Net::SocketAddress& address = _socket.peerAddress();
        debug_log("connection established. peer = %s", address.toString().c_str());
        sendMessage(10001, (const byte*)"hello", 5);
        for (;;)
        {
         bool readable = _socket.poll(Poco::Timespan(30, 0), Poco::Net::Socket::SelectMode::SELECT_READ);
         if (readable == true)
            {
                int bytes_transferred = _socket.receiveBytes(_buffer, MAX_RECV_LEN);

                debug_log("received %d bytes.", bytes_transferred);

                if (bytes_transferred == 0)
                {
                    debug_log("connection graceful shutdown from the peer.");
                    break;
                }
            }
        }
    }
    catch (Poco::Exception& e)
    {
        error_log("connection exception. error");
    }
    catch (...)
    {
        error_log("unknown exception.");
    }
}



thanks.
AngryPowman
 
Posts: 2
Joined: 20 Dec 2013, 08:11

Re: is Poco::Net::SocketAddress threadsafe?

Postby AngryPowman » 20 Dec 2013, 10:18

windows 7 x64, msbuild
AngryPowman
 
Posts: 2
Joined: 20 Dec 2013, 08:11


Return to Support

Who is online

Users browsing this forum: eduquint and 3 guests