OSDN Git Service

#445
authoryamada <yamada@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Mon, 25 Jan 2010 06:02:32 +0000 (06:02 +0000)
committeryamada <yamada@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Mon, 25 Jan 2010 06:02:32 +0000 (06:02 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel@9864 1ed66053-1c2d-0410-8867-f7571e6e31d3

l7vsd/include/tcp_ssl_socket.h
l7vsd/src/tcp_session.cpp
l7vsd/src/tcp_ssl_socket.cpp

index 7d1e445..8b3f7f7 100644 (file)
@@ -50,15 +50,19 @@ namespace l7vs{
                        boost::asio::ssl::context& context,
                        const tcp_socket_option_info set_option)
                        :
-                       my_socket(io, context),
+                       my_io(io),
+                       my_context(context),
+                       my_socket(NULL),
                        open_flag(false),
                        non_blocking_flag(false),
-                       opt_info(set_option){
+                       opt_info(set_option),
+                       handshake_error_flag(false){
                 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( 
                     LOG_CAT_L7VSD_SESSION ) ) ){
                     Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 1, 
                         "tcp_ssl_socket::tcp_ssl_socket", __FILE__, __LINE__ );
                 }
+                my_socket = new ssl_socket(io,my_context);
             }
             //! destructor
             ~tcp_ssl_socket(){
@@ -67,6 +71,11 @@ namespace l7vs{
                     Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 2, 
                         "tcp_ssl_socket::~tcp_ssl_socket", __FILE__, __LINE__ );
                 }
+                if(my_socket != NULL){
+                    delete my_socket;
+                    my_socket = NULL;
+                }
+
             }
             
             //! get reference control socket
@@ -75,7 +84,7 @@ namespace l7vs{
                 if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_SESSION ) ) ){
                     Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 3, "tcp_ssl_socket::get_socket", __FILE__, __LINE__ );
                 }
-                return my_socket;
+                return *my_socket;
             }
 
             //! handshake socket
@@ -109,10 +118,27 @@ namespace l7vs{
             bool is_open(){
                 return open_flag;
             }
+            //! socket remake
+            void clear_socket(){
+                if(my_socket != NULL){
+                    delete my_socket;
+                    my_socket = NULL;
+                }
+                my_socket = new ssl_socket(my_io,my_context);
+                handshake_error_flag = false;
+            }
+            //! is handshake error
+            bool is_handshake_error(){
+                return handshake_error_flag;
+            }
 
         protected:
+            //! io service object
+            boost::asio::io_service& my_io;
+            //! SSL context object
+            boost::asio::ssl::context& my_context;
             //! control socket
-            ssl_socket my_socket;
+            ssl_socket* my_socket;
             //! socket close mutex
             wr_mutex close_mutex;
             //! socket open flag
@@ -121,6 +147,9 @@ namespace l7vs{
             bool non_blocking_flag;
             //! socket option 
             tcp_socket_option_info opt_info;
+            //! handshake error flag
+            bool handshake_error_flag;
+
     };// class tcp_ssl_socket
 }// namespace l7vs
 
index b0d45c6..999b714 100644 (file)
@@ -376,51 +376,56 @@ namespace l7vs{
 
         // Reset SSL structure to allow another connection.
         if ( ssl_flag ) {
-            if ( ssl_cache_flag ) {
-                if (unlikely(ssl_clear_keep_cache(client_ssl_socket.get_socket().impl()->ssl) == false)) {
-                    //Error ssl_clear_keep_cache
-                    std::stringstream buf;
-                    buf << "Thread ID[";
-                    buf << boost::this_thread::get_id();
-                    buf << "] ssl_clear_keep_cache failed";
-                    Logger::putLogError( LOG_CAT_L7VSD_SESSION, 110, buf.str(), __FILE__, __LINE__ );
-                    msg.flag = true;
-                    msg.message = "ssl_clear_keep_cache failed";
-                } else {
-                    //----Debug log----------------------------------------------------------------------
-                    if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+            if(client_ssl_socket.is_handshake_error()){
+                // remake socket
+                client_ssl_socket.clear_socket();
+            }else{
+                if ( ssl_cache_flag ) {
+                    if (unlikely(ssl_clear_keep_cache(client_ssl_socket.get_socket().impl()->ssl) == false)) {
+                        //Error ssl_clear_keep_cache
                         std::stringstream buf;
                         buf << "Thread ID[";
                         buf << boost::this_thread::get_id();
-                        buf << "] ssl_clear_keep_cache ok";
-                        Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 81,
-                                    buf.str(),
-                                    __FILE__, __LINE__ );
+                        buf << "] ssl_clear_keep_cache failed";
+                        Logger::putLogError( LOG_CAT_L7VSD_SESSION, 110, buf.str(), __FILE__, __LINE__ );
+                        msg.flag = true;
+                        msg.message = "ssl_clear_keep_cache failed";
+                    } else {
+                        //----Debug log----------------------------------------------------------------------
+                        if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+                            std::stringstream buf;
+                            buf << "Thread ID[";
+                            buf << boost::this_thread::get_id();
+                            buf << "] ssl_clear_keep_cache ok";
+                            Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 81,
+                                        buf.str(),
+                                        __FILE__, __LINE__ );
+                        }
+                        //----Debug log----------------------------------------------------------------------
                     }
-                    //----Debug log----------------------------------------------------------------------
-                }
-            } else {
-                if (unlikely(SSL_clear(client_ssl_socket.get_socket().impl()->ssl) == 0)) {
-                    //Error SSL_clear
-                    std::stringstream buf;
-                    buf << "Thread ID[";
-                    buf << boost::this_thread::get_id();
-                    buf << "] SSL_clear failed";
-                    Logger::putLogError( LOG_CAT_L7VSD_SESSION, 111, buf.str(), __FILE__, __LINE__ );
-                    msg.flag = true;
-                    msg.message = "SSL_clear failed";
-                }else{
-                    //----Debug log----------------------------------------------------------------------
-                    if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+                } else {
+                    if (unlikely(SSL_clear(client_ssl_socket.get_socket().impl()->ssl) == 0)) {
+                        //Error SSL_clear
                         std::stringstream buf;
                         buf << "Thread ID[";
                         buf << boost::this_thread::get_id();
-                        buf << "] SSL_clear ok";
-                        Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 82,
-                                    buf.str(),
-                                    __FILE__, __LINE__ );
+                        buf << "] SSL_clear failed";
+                        Logger::putLogError( LOG_CAT_L7VSD_SESSION, 111, buf.str(), __FILE__, __LINE__ );
+                        msg.flag = true;
+                        msg.message = "SSL_clear failed";
+                    }else{
+                        //----Debug log----------------------------------------------------------------------
+                        if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+                            std::stringstream buf;
+                            buf << "Thread ID[";
+                            buf << boost::this_thread::get_id();
+                            buf << "] SSL_clear ok";
+                            Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 82,
+                                        buf.str(),
+                                        __FILE__, __LINE__ );
+                        }
+                        //----Debug log----------------------------------------------------------------------
                     }
-                    //----Debug log----------------------------------------------------------------------
                 }
             }
         }
index 206f80f..b3b109a 100644 (file)
@@ -43,9 +43,11 @@ namespace l7vs{
         rw_scoped_lock scope_lock(close_mutex);
 
         bool bres = false;
-        my_socket.handshake(boost::asio::ssl::stream_base::server, ec);
+        my_socket->handshake(boost::asio::ssl::stream_base::server, ec);
         if( !ec ){
             bres = true;
+        }else if( ec != boost::asio::error::try_again ){
+            handshake_error_flag = true;
         }
 
         if (unlikely( LOG_LV_DEBUG == Logger::getLogLevel(
@@ -70,7 +72,7 @@ namespace l7vs{
             buf << "Thread ID[";
             buf << boost::this_thread::get_id();
             buf << "] tcp_ssl_socket::accept [";
-            buf << my_socket.lowest_layer().remote_endpoint(ec);
+            buf << my_socket->lowest_layer().remote_endpoint(ec);
             buf << "]";
             Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 54, buf.str(), 
                 __FILE__, __LINE__ );
@@ -81,7 +83,7 @@ namespace l7vs{
         if(opt_info.nodelay_opt){
             boost::system::error_code ec;
             boost::asio::ip::tcp::no_delay set_option(opt_info.nodelay_val);
-            my_socket.lowest_layer().set_option(set_option,ec);
+            my_socket->lowest_layer().set_option(set_option,ec);
             if(unlikely(ec)){
                 //ERROR
                 Logger::putLogError( LOG_CAT_L7VSD_SESSION, 107,
@@ -96,7 +98,7 @@ namespace l7vs{
             int val = opt_info.cork_val;
             size_t len = sizeof(val);
             boost::asio::detail::socket_ops::setsockopt(
-                my_socket.lowest_layer().native(),IPPROTO_TCP,
+                my_socket->lowest_layer().native(),IPPROTO_TCP,
                 TCP_CORK,&val,len,ec);
             if(unlikely(ec)){
                 //ERROR
@@ -117,7 +119,7 @@ namespace l7vs{
             Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 56, 
                 "in_function : tcp_ssl_socket::close", __FILE__, __LINE__ );
         }
-        
+
         rw_scoped_lock scope_lock(close_mutex);
 
         //----Debug log--------------------------------------------------------
@@ -129,7 +131,7 @@ namespace l7vs{
                 buf << "Thread ID[";
                 buf << boost::this_thread::get_id();
                 buf << "] tcp_ssl_socket::close [";
-                buf << my_socket.lowest_layer().remote_endpoint(ec);
+                buf << my_socket->lowest_layer().remote_endpoint(ec);
                 buf << "]";
                 Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 58, buf.str(), 
                     __FILE__, __LINE__ );
@@ -141,8 +143,8 @@ namespace l7vs{
             open_flag = false;
             bres = true;
         }
-        my_socket.lowest_layer().close(ec);
-        
+        my_socket->lowest_layer().close(ec);
+
         if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( 
             LOG_CAT_L7VSD_SESSION ) ) ){
             Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 57, 
@@ -166,7 +168,7 @@ namespace l7vs{
         rd_scoped_lock scope_lock(close_mutex);
         bool bres = false;
         boost::asio::socket_base::non_blocking_io cmd(true);
-        my_socket.lowest_layer().io_control(cmd,ec);
+        my_socket->lowest_layer().io_control(cmd,ec);
         if(likely( !ec )){
             // OK
             bres = true;
@@ -199,7 +201,7 @@ namespace l7vs{
         rw_scoped_lock scope_lock(close_mutex);
         std::size_t res_size = 0;
         if(likely(non_blocking_flag)){
-            res_size = my_socket.write_some(buffers,ec);
+            res_size = my_socket->write_some(buffers,ec);
             if(unlikely(ec)){
                 if (likely(!open_flag)) {
                     res_size = 0;
@@ -232,7 +234,7 @@ namespace l7vs{
                 int val = opt_info.quickack_val;
                 std::size_t len = sizeof(val);
                 boost::asio::detail::socket_ops::setsockopt(
-                    my_socket.lowest_layer().native(),IPPROTO_TCP,
+                    my_socket->lowest_layer().native(),IPPROTO_TCP,
                     TCP_QUICKACK,&val,len,ec);
                 if(unlikely(ec)){
                     //ERROR
@@ -246,7 +248,7 @@ namespace l7vs{
                 }
             }
             boost::this_thread::yield();
-            res_size = my_socket.read_some(buffers,ec);
+            res_size = my_socket->read_some(buffers,ec);
         }
         return res_size;
     }