1

Poco フレームワークに基づいてサーバー アプリケーションを作成しています。リアクター パターンとリクエスト ハンドラー クラスを使用するのは CSConnection です。テンプレートからクラス構造を作成しました(自殺あり)。そして今、私は尋ねます、これはスレッドプールでそれを適切に使用する方法ですか?

クラス :

class CSConnection
{
    public:
        CSConnection(StreamSocket& socket, SocketReactor& reactor);
        ~CSConnection();

        Player & getPlayer();

        bool isLogged();

        void sendBlocking(Packet * p);
        void sendNonblocking(Packet * p);

        void onReadable(const AutoPtr<ReadableNotification>& pNf);

        void onShutdown(const AutoPtr<ShutdownNotification>& pNf);

        void onError(const AutoPtr<ErrorNotification>& pNf);

        StreamSocket & getSocket()
        {
            return _socket;
        }

        void shutdownConnection();
    private:
        void sendSync();
        StreamSocket _socket;
        SocketReactor& _reactor;

        Player player = Player(_socket);
        Application & app = Application::instance();
};

そして自殺:

void CSConnection::onShutdown(const AutoPtr<ShutdownNotification>& pNf)
{
    delete this;
}

void CSConnection::onReadable(const AutoPtr<ReadableNotification>& pNf)
{
    try
    {
        char * buffer = new char[128](); //allocate incoming packet memory
        int n = _socket.receiveBytes(buffer, 128);
        if(n > 7)
        {
            Worker::getInstance().start(*new LogicHandler(_socket, player, buffer));
        }
        else
        {
            delete this;
            delete buffer;
        }
    }
    catch(Poco::Exception& exc)
    {
        delete this;
        //app.logger().log(exc);
    }
}

void CSConnection::onError(const AutoPtr<ErrorNotification>& pNf)
{
    _socket.shutdownReceive();
    delete this;
}

void CSConnection::shutdownConnection()
{
    _socket.shutdownReceive();
    delete this;
}
4

0 に答える 0