示例#1
0
void Server::HandleReceive()
{
    if(mCommand->IsValid())
    {
        if(mCommand->IsConnectionRequest())
        {
            // let the client know we're good to go by echoing received data
            ServerQuickResponseCode reply(mCommand->GetData().front());
            SendData(&reply);

        } else {

            mCommand->DecodeDataToCommand();

            for(auto& callback : mCallbacks)
                callback(mCommand.get(), this);
        }

    }

    mCommand->ClearData();

    if(mStopServer)
        mServerRunning = false;
    else
        StartReceive();
}
示例#2
0
文件: i2c.cpp 项目: Inode1/i2c
void I2CDevice::StartCommunication()
{
    if (!m_status) 
    {
        std::cout << "Init device fail: " << std::endl;
        return;
    }
    StartWrite();
    StartReceive();
    m_ioService.run();
}
示例#3
0
void Server::Start()
{
    if(mServerRunning)
        return;

    mServerRunning = true;
    mStopServer = false;

    StartReceive();

    mIOService.run();
}
示例#4
0
文件: i2c.cpp 项目: Inode1/i2c
void I2CDevice::HandleRead(const boost::system::error_code& ex, std::size_t length)
{
    if (ex)
    {
        std::cout << "Handle read fail: " << ex.message() << std::endl;
        m_ioService.stop();
        return;  
    }
    // The actual number of bytes received is committed to the buffer so that we
    // can extract it using a std::istream object.
    m_replyBuffer.commit(length);

    // Decode the reply packet.
    std::istream is(&m_replyBuffer);
    std:: cout << "We get next message: " << std::endl;
    std::copy(std::istream_iterator<char>(is), std::istream_iterator<char>(), std::ostream_iterator<char>(std::cout));
    StartReceive();   
}
// ---------------------------------------------------------------------------
// Second phase construction.
// ---------------------------------------------------------------------------
//
void CIkev1Receiver::ConstructL()
    {
    StartReceive();
    }