OSDN Git Service

メッセージ番号修正
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / tcp_ssl_socket.h
1 /*!
2  *    @file    tcp_ssl_socket.h
3  *    @brief    tcp ssl session socket class
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24
25 #ifndef TCP_SSL_SOCKET_H
26 #define TCP_SSL_SOCKET_H
27
28 #include <bitset>
29 #include <boost/asio.hpp>
30 #include <boost/asio/ssl.hpp>
31 #include <boost/thread/mutex.hpp>
32
33 #include "tcp_socket_option.h"
34 #include "wrlock.h"
35 #include "utility.h"
36 #include "logger.h"
37
38 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket>  ssl_socket;
39
40 namespace l7vs{
41
42 //!    @class    tcp_ssl_socket
43 //! @brief    this class is tcp session object use socket.
44     class tcp_ssl_socket : private boost::noncopyable{
45         public:
46 /*
47             //! construcor
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)
52                        :
53                        my_socket(io, context),
54                        open_flag(false)
55             {
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__ );
61                 }
62             }
63 */
64             //! construcor
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)
70                        :
71                        my_socket(io, context),
72                        open_flag(false),
73                        opt_info(set_option)
74             {
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__ );
77                 }
78             }
79             //! destructor
80             ~tcp_ssl_socket(){
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__ );
83                 }
84             }
85             
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__ );
91                 }
92                 return my_socket;
93             }
94
95             //! handshake socket
96             //! @param[in]        handshake_type is handshaking as a server or client
97             bool handshake(boost::system::error_code& ec);
98             //! accept
99             void accept();
100             //! close socket
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);
108             //! write socket
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);
113             //! read socket
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);
118             //! is open
119             //! @return         true is open
120             //! @return         false is close
121             bool is_open(){
122                 return open_flag;
123             }
124
125         protected:
126             //! control socket
127             ssl_socket my_socket;
128             //! socket close mutex
129             wr_mutex close_mutex;
130             //! socket open flag
131             bool open_flag;
132             //! socket option 
133             tcp_socket_option_info opt_info;
134     };// class tcp_ssl_socket
135 }// namespace l7vs
136
137 #endif//TCP_SSL_SOCKET_H
138