示例#1
0
Connection::Connection(const SocketClient::SharedPtr &client)
    : mSocketClient(client), mPendingRead(0), mPendingWrite(0), mTimeoutTimer(0), mFinishStatus(0),
      mSilent(false), mIsConnected(true), mWarned(false)
{
    assert(client->isConnected());
    mSocketClient->disconnected().connect(std::bind(&Connection::onClientDisconnected, this, std::placeholders::_1));
    mSocketClient->readyRead().connect(std::bind(&Connection::onDataAvailable, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->bytesWritten().connect(std::bind(&Connection::onDataWritten, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->error().connect(std::bind(&Connection::onSocketError, this, std::placeholders::_1, std::placeholders::_2));
    EventLoop::eventLoop()->callLater(std::bind(&Connection::initConnection, this));
}
示例#2
0
void Connection::connect(const SocketClient::SharedPtr &client)
{
    assert(!mSocketClient);
    mSocketClient = client;
    mIsConnected = true;
    assert(client->isConnected());
    mSocketClient->disconnected().connect(std::bind(&Connection::onClientDisconnected, this, std::placeholders::_1));
    mSocketClient->readyRead().connect(std::bind(&Connection::onDataAvailable, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->bytesWritten().connect(std::bind(&Connection::onDataWritten, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->error().connect(std::bind(&Connection::onSocketError, this, std::placeholders::_1, std::placeholders::_2));
    mCheckTimer = EventLoop::eventLoop()->registerTimer([this](int) { checkData(); }, 0, Timer::SingleShot);
}
示例#3
0
void Connection::connect(const SocketClient::SharedPtr &client)
{
    mSocketClient = client;
    mIsConnected = true;
    assert(client->isConnected());
    auto that = shared_from_this();
    mSocketClient->disconnected().connect(std::bind(&Connection::onClientDisconnected, that, std::placeholders::_1));
    mSocketClient->readyRead().connect(std::bind(&Connection::onDataAvailable, that, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->bytesWritten().connect(std::bind(&Connection::onDataWritten, that, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->error().connect(std::bind(&Connection::onSocketError, that, std::placeholders::_1, std::placeholders::_2));
    send(ConnectMessage());
    std::weak_ptr<Connection> weak = that;
    EventLoop::eventLoop()->callLater([weak]() {
            if (auto strong = weak.lock())
                strong->checkData();
        });
}