i2pd/I2CP.cpp

54 lines
1.1 KiB
C++
Raw Normal View History

2016-05-12 22:37:46 +03:00
#include "I2CP.h"
namespace i2p
{
namespace client
{
2016-05-12 23:17:10 +03:00
I2CPSession::I2CPSession (std::shared_ptr<boost::asio::ip::tcp::socket> socket):
m_Socket (socket)
{
ReadProtocolByte ();
}
void I2CPSession::ReadProtocolByte ()
{
if (m_Socket)
{
auto s = shared_from_this ();
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, 1),
[s](const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
if (!ecode && bytes_transferred > 0 && s->m_Buffer[0] == I2CP_PRTOCOL_BYTE)
s->Receive ();
else
s->Terminate ();
});
}
}
void I2CPSession::Receive ()
{
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, I2CP_SESSION_BUFFER_SIZE),
std::bind (&I2CPSession::HandleReceived, shared_from_this (), std::placeholders::_1, std::placeholders::_2));
}
void I2CPSession::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
if (ecode)
Terminate ();
else
Receive ();
}
void I2CPSession::Terminate ()
{
}
2016-05-12 22:37:46 +03:00
I2CPServer::I2CPServer (const std::string& interface, int port)
{
}
}
}