Overview
Features
Download
Documentation
Community
Add-Ons & Services

SocketReactor and SecureStreamSocket

Please post support and help requests here.

SocketReactor and SecureStreamSocket

Postby sergeylee » 09 Apr 2013, 12:24

Hello all!
We have developed our backend based on TCP/SSL connection.
Problem is in onReadable method of MyServiceHandler. After client connect to server this event fired and start executing of onReadable method, but _socket.available() equals 0. And execute while(!stream.eof()) code. :(
Why event fired? :(

Code: Select all
...
SocketReactor reactor;
SecureServerSocket svs(_port);

MySocketAcceptor acceptor(svs, reactor, writer, _requestQueue);

Thread thread;
thread.start(reactor);

while( !isStopped() )
{
    Poco::Thread::sleep(1);
}
   
reactor.stop();
thread.join();
...


Code: Select all
MyServiceHandler* MySocketAcceptor::createServiceHandler(StreamSocket& socket)
{
    SecureStreamSocket socketssl(socket);
    _writer.attachSocket(socketssl);
    _service = new MyServiceHandler(socketssl, *(this->reactor()), _requestQueue);
       
    _service->attachAcceptor(this);
    return _service;
}


Code: Select all
MyServiceHandler::MyServiceHandler(StreamSocket& socket, SocketReactor& reactor, NotificationQueue &requestQueue):
    _socket(socket), _reactor(reactor), _requestQueue(requestQueue)
{
    _reactor.addEventHandler(_socket, NObserver<MyServiceHandler, ReadableNotification>(*this, &MyServiceHandler::onReadable));
    _reactor.addEventHandler(_socket, NObserver<MyServiceHandler, ShutdownNotification>(*this, &MyServiceHandler::onShutdown));
}

void MyServiceHandler::onReadable(const AutoPtr<ReadableNotification>& pNf)
{
    try
    {
        FastMutex::ScopedLock lock(_mutex);
        SocketStream stream(_socket);
        while(!stream.eof())
        {
            MyRequest request;
            request.read(stream);
            ...
            _requestQueue.enqueueNotification(new OMRequestNotification(request));
        }
    }
    catch(NoMessageException& exc)
    {
        delete this;
        return;
    }
    catch(Exception& exc)
    {
        poco_warning(_logger, "MyServiceHandler onReadable Exception " + exc.displayText());
    }
}
sergeylee
 
Posts: 3
Joined: 05 Dec 2012, 12:17

Re: SocketReactor and SecureStreamSocket

Postby sergeylee » 09 Apr 2013, 13:59

:) I have found how to resolve this problem!

In the constructor MyServiceHandler execute completeHandshake() method of SecureStreamSocket.

Code: Select all
MyServiceHandler::MyServiceHandler(StreamSocket& socket, SocketReactor& reactor, NotificationQueue &requestQueue):
    _socket(socket), _reactor(reactor), _requestQueue(requestQueue)
{
    _socket.completeHandshake();
   
    _reactor.addEventHandler(_socket, NObserver<MyServiceHandler, ReadableNotification>(*this, &MyServiceHandler::onReadable));
    _reactor.addEventHandler(_socket, NObserver<MyServiceHandler, ShutdownNotification>(*this, &MyServiceHandler::onShutdown));
}
sergeylee
 
Posts: 3
Joined: 05 Dec 2012, 12:17


Return to Support

Who is online

Users browsing this forum: No registered users and 6 guests