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{
47 //! @param[in/out] socket use io service object
48 //! @param[in] set socket option info
49 tcp_ssl_socket(boost::asio::io_service& io,
50 boost::asio::ssl::context& context)
52 my_socket(io, context),
55 opt_info.nodelay_opt = false;
56 opt_info.cork_opt = false;
57 opt_info.quickack_opt = false;
58 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
59 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 1, "tcp_ssl_socket::tcp_ssl_socket", __FILE__, __LINE__ );
63 //! @param[in/out] socket use io service object
64 //! @param[in] set socket option info
65 tcp_ssl_socket(boost::asio::io_service& io,
66 boost::asio::ssl::context& context,
67 const tcp_socket_option_info set_option)
69 my_socket(io, context),
73 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
74 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 1, "tcp_ssl_socket::tcp_ssl_socket", __FILE__, __LINE__ );
79 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
80 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 2, "tcp_ssl_socket::~tcp_ssl_socket", __FILE__, __LINE__ );
84 //! get reference control socket
85 //! @return reference control socket
86 ssl_socket& get_socket(){
87 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
88 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 3, "tcp_ssl_socket::get_socket", __FILE__, __LINE__ );
94 //! @param[in] connect_endpoint is connection endpoint
95 //! @param[out] ec is reference error code object
96 bool connect(const boost::asio::ip::tcp::endpoint connect_endpoint,boost::system::error_code& ec);
98 //! @param[in] handshake_type is handshaking as a server or client
99 bool handshake(boost::asio::ssl::stream_base::handshake_type type);
103 //! @param[out] ec is reference error code object
104 //! @return true is socket close
105 //! @return false is not open socket
106 bool close(boost::system::error_code& ec);
107 //! set non blocking mode of the socket
108 //! @return ec is reference error code object
109 bool set_non_blocking_mode(boost::system::error_code& ec);
111 //! @param[in] buffers is wite data buffer
112 //! @param[out] ec is reference error code object
113 //! @return write data size
114 std::size_t write_some(boost::asio::mutable_buffers_1 buffers, boost::system::error_code& ec);
116 //! @param[out] buffers is read data buffer
117 //! @param[out] ec is reference error code object
118 //! @return read data size
119 std::size_t read_some(boost::asio::mutable_buffers_1 buffers, boost::system::error_code& ec);
121 //! @return true is open
122 //! @return false is close
129 ssl_socket my_socket;
130 //! socket close mutex
131 wr_mutex close_mutex;
135 tcp_socket_option_info opt_info;
136 };// class tcp_ssl_socket
139 #endif//TCP_SSL_SOCKET_H