Browse Source

Merge pull request #20 from orignal/master

Merge pull request from orignal/master
pull/49/head
chertov 11 years ago
parent
commit
0c133362af
  1. 3
      HTTPServer.cpp
  2. 3
      HTTPServer.h
  3. 9
      Streaming.cpp
  4. 9
      Streaming.h

3
HTTPServer.cpp

@ -277,6 +277,9 @@ namespace util @@ -277,6 +277,9 @@ namespace util
}
}
void HTTPConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
}
HTTPServer::HTTPServer (int port):
m_Thread (nullptr), m_Work (m_Service),

3
HTTPServer.h

@ -44,7 +44,8 @@ namespace util @@ -44,7 +44,8 @@ namespace util
void Terminate ();
void Receive ();
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleWrite(const boost::system::error_code& ecode);
void HandleRequest ();

9
Streaming.cpp

@ -248,7 +248,12 @@ namespace stream @@ -248,7 +248,12 @@ namespace stream
return 0;
}
// either non-empty or we have received empty
// either non-empty or we have received something
return ConcatenatePackets (buf, len);
}
size_t Stream::ConcatenatePackets (uint8_t * buf, size_t len)
{
size_t pos = 0;
while (pos < len)
{
@ -269,7 +274,7 @@ namespace stream @@ -269,7 +274,7 @@ namespace stream
break;
}
return pos;
}
}
bool Stream::SendPacket (Packet * packet)
{

9
Streaming.h

@ -97,6 +97,7 @@ namespace stream @@ -97,6 +97,7 @@ namespace stream
void SavePacket (Packet * packet);
void ProcessPacket (Packet * packet);
size_t ConcatenatePackets (uint8_t * buf, size_t len);
void UpdateCurrentRemoteLease ();
@ -200,20 +201,20 @@ namespace stream @@ -200,20 +201,20 @@ namespace stream
void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout)
{
m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout));
m_ReceiveTimer.async_wait (boost::bind (&Stream::HandleReceiveTimer,
m_ReceiveTimer.async_wait (boost::bind (&Stream::HandleReceiveTimer<Buffer, ReceiveHandler>,
this, boost::asio::placeholders::error, buffer, handler));
}
template<typename Buffer, typename ReceiveHandler>
void Stream::HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler)
{
// TODO:
size_t received = ConcatenatePackets (boost::asio::buffer_cast<uint8_t *>(buffer), boost::asio::buffer_size(buffer));
if (ecode == boost::asio::error::operation_aborted)
// timeout not expired
handler (boost::system::error_code (), 0);
handler (boost::system::error_code (), received);
else
// timeout expired
handler (boost::asio::error::make_error_code (boost::asio::error::timed_out), 0);
handler (boost::asio::error::make_error_code (boost::asio::error::timed_out), received);
}
}
}

Loading…
Cancel
Save