9 #include <boost/asio.hpp> 
   10 #include <boost/bind.hpp> 
   16 using boost::asio::async_write;
 
   17 using boost::asio::buffer;
 
   18 using boost::asio::buffer_cast;
 
   19 using boost::asio::mutable_buffer;
 
   20 using boost::asio::mutable_buffers_1;
 
   21 using boost::asio::null_buffers;
 
   22 using boost::asio::placeholders::error;
 
   23 using boost::asio::placeholders::bytes_transferred;
 
   24 using boost::asio::ssl::stream_base;
 
   26 using boost::function;
 
   27 using boost::system::error_code;
 
   50                 session_->server()->stats_.read_blocked++;
 
   54                 } 
else if (!
session_->IsSslHandShakeInProgress()) {
 
   61     string Description()
 const { 
return "SslSession::SslReader"; }
 
   70                        bool async_read_ready)
 
   72       ssl_socket_(ssl_socket),
 
   73       ssl_handshake_in_progress_(false),
 
   74       ssl_handshake_success_(false),
 
   76       ssl_handshake_delayed_(false),
 
   77       ssl_last_read_len_(0) {
 
   89                                    size_t bytes_transferred) {
 
   90     Buffer rdbuf(buffer_cast<const uint8_t *>(buffer), bytes_transferred);
 
  136 #if defined(SSL_R_SHORT_READ)   
  137     if (ec.value() == ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)) {
 
  140 #elif defined(BOOST_ASIO_SSL_ERROR_STREAM_TRUNCATED)  
  141     if (ec.value() == boost::asio::ssl::error::stream_truncated) {
 
  155     return ssl_socket_->read_some(mutable_buffers_1(buffer), *error);
 
  160         async_write(*
ssl_socket_.get(), buffer(data, size),
 
  170                                       const error_code &error) {
 
  171     session->ssl_handshake_in_progress_ = 
false;
 
  173         session->SetSslHandShakeSuccess();
 
  175         session->SetSslHandShakeFailure();
 
  178     if (session->socket() != NULL && !(session->IsClosed())) {
 
  185     srand(
static_cast<unsigned>(time(0)));
 
  187     session->ssl_handshake_in_progress_ = 
true;
 
  188     if (session->IsServerSession()) {
 
  189         session->ssl_socket_->async_handshake(stream_base::server,
 
  193         session->ssl_socket_->async_handshake(stream_base::client,
 
boost::asio::io_context * io_service()
 
SslReader(int task_id, SslSessionPtr session, ReadHandler read_fn, Buffer buffer)
 
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task.
 
string Description() const
 
function< void(Buffer)> ReadHandler
 
static bool IsSocketErrorHard(const boost::system::error_code &ec)
 
size_t ReadSome(boost::asio::mutable_buffer buffer, boost::system::error_code *error)
 
virtual Socket * socket() const
 
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
 
virtual void AsyncReadSome()
 
void AsyncWrite(const uint8_t *data, std::size_t size)
 
SslSession(SslServer *server, SslSocket *socket, bool async_read_ready=true)
 
static void SslHandShakeCallback(SslHandShakeCallbackHandler cb, SslSessionPtr, const boost::system::error_code &error)
 
size_t ssl_last_read_len_
 
virtual Task * CreateReaderTask(boost::asio::mutable_buffer, size_t)
 
boost::scoped_ptr< SslSocket > ssl_socket_
 
bool ssl_handshake_delayed_
 
virtual size_t GetReadBufferSize() const
 
void TriggerSslHandShake(SslHandShakeCallbackHandler)
 
bool IsSslHandShakeSuccessLocked()
 
static void TriggerSslHandShakeInternal(SslSessionPtr ptr, SslHandShakeCallbackHandler cb)
 
bool ssl_handshake_in_progress_
 
Task is a wrapper over tbb::task to support policies.
 
EventManager * event_manager()
 
virtual int reader_task_id() const
 
virtual int GetSessionInstance() const
 
virtual void AsyncWrite(const uint8_t *data, std::size_t size)
 
static bool IsSocketErrorHard(const boost::system::error_code &ec)
 
void TriggerAsyncReadHandler()
 
virtual void AsyncReadSome()
 
virtual void OnRead(Buffer buffer)=0
 
static void AsyncWriteHandler(TcpSessionPtr session, const boost::system::error_code &error, std::size_t bytes_transferred)
 
static size_t BufferSize(const Buffer &buffer)
 
boost::asio::const_buffer Buffer
 
boost::intrusive_ptr< TcpSession > TcpSessionPtr
 
static const int kDefaultBufferSize
 
boost::asio::ip::tcp::socket Socket
 
virtual size_t ReadSome(boost::asio::mutable_buffer buffer, boost::system::error_code *error)
 
boost::intrusive_ptr< SslSession > SslSessionPtr
 
boost::function< void(SslSessionPtr, const boost::system::error_code &error)> SslHandShakeCallbackHandler
 
static uint64_t UTCTimestampUsec()