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(){
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
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
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
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
// 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----------------------------------------------------------------------
}
}
}
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(
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__ );
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,
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
Logger::putLogDebug( LOG_CAT_L7VSD_SESSION, 56,
"in_function : tcp_ssl_socket::close", __FILE__, __LINE__ );
}
-
+
rw_scoped_lock scope_lock(close_mutex);
//----Debug log--------------------------------------------------------
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__ );
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,
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;
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;
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
}
}
boost::this_thread::yield();
- res_size = my_socket.read_some(buffers,ec);
+ res_size = my_socket->read_some(buffers,ec);
}
return res_size;
}