2 * @file tcp_ssl_socket.h
3 * @brief tcp ssl session socket class
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2009 NTT COMWARE Corporation.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 **********************************************************************/
25 #ifndef TCP_SSL_SOCKET_H
26 #define TCP_SSL_SOCKET_H
29 #include <boost/asio.hpp>
30 #include <boost/asio/ssl.hpp>
31 #include <boost/thread/mutex.hpp>
33 #include "tcp_socket_option.h"
38 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
42 //! @class tcp_ssl_socket
43 //! @brief this class is tcp session object use socket.
44 class tcp_ssl_socket : private boost::noncopyable{
48 //! @param[in/out] socket use io service object
49 //! @param[in] set socket option info
50 tcp_ssl_socket(boost::asio::io_service& io,
51 boost::asio::ssl::context& context)
53 my_socket(io, context),
56 opt_info.nodelay_opt = false;
57 opt_info.cork_opt = false;
58 opt_info.quickack_opt = false;
59 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
60 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 1, "tcp_ssl_socket::tcp_ssl_socket", __FILE__, __LINE__ );
65 //! @param[in/out] socket use io service object
66 //! @param[in] set socket option info
67 tcp_ssl_socket(boost::asio::io_service& io,
68 boost::asio::ssl::context& context,
69 const tcp_socket_option_info set_option)
71 my_socket(io, context),
75 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
76 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 1, "tcp_ssl_socket::tcp_ssl_socket", __FILE__, __LINE__ );
81 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
82 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 2, "tcp_ssl_socket::~tcp_ssl_socket", __FILE__, __LINE__ );
86 //! get reference control socket
87 //! @return reference control socket
88 ssl_socket& get_socket(){
89 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
90 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 3, "tcp_ssl_socket::get_socket", __FILE__, __LINE__ );
96 //! @param[in] handshake_type is handshaking as a server or client
97 bool handshake(boost::system::error_code& ec);
101 //! @param[out] ec is reference error code object
102 //! @return true is socket close
103 //! @return false is not open socket
104 bool close(boost::system::error_code& ec);
105 //! set non blocking mode of the socket
106 //! @return ec is reference error code object
107 bool set_non_blocking_mode(boost::system::error_code& ec);
109 //! @param[in] buffers is wite data buffer
110 //! @param[out] ec is reference error code object
111 //! @return write data size
112 std::size_t write_some(boost::asio::mutable_buffers_1 buffers, boost::system::error_code& ec);
114 //! @param[out] buffers is read data buffer
115 //! @param[out] ec is reference error code object
116 //! @return read data size
117 std::size_t read_some(boost::asio::mutable_buffers_1 buffers, boost::system::error_code& ec);
119 //! @return true is open
120 //! @return false is close
127 ssl_socket my_socket;
128 //! socket close mutex
129 wr_mutex close_mutex;
133 tcp_socket_option_info opt_info;
134 };// class tcp_ssl_socket
137 #endif//TCP_SSL_SOCKET_H