15 #include "tlsgnutlsbase.h"
28 :
TLSBase( th, server ), m_session( new gnutls_session_t ), m_buf( 0 ), m_bufsize( 17000 )
30 m_buf = (
char*)calloc( m_bufsize + 1,
sizeof(
char ) );
39 gnutls_global_deinit();
51 std::string::size_type sum = 0;
54 ret = gnutls_record_send( *m_session, data.c_str() + sum, data.length() - sum );
57 while( ( ret == GNUTLS_E_AGAIN ) || ( ret == GNUTLS_E_INTERRUPTED ) || sum < data.length() );
75 ret = gnutls_record_recv( *m_session, m_buf, m_bufsize );
77 if( ret > 0 && m_handler )
92 gnutls_bye( *m_session, GNUTLS_SHUT_RDWR );
93 gnutls_db_remove_session( *m_session );
94 gnutls_credentials_clear( *m_session );
96 gnutls_deinit( *m_session );
102 m_session =
new gnutls_session_t;
111 int ret = gnutls_handshake( *m_session );
112 if( ret < 0 && gnutls_error_is_fatal( ret ) )
114 gnutls_perror( ret );
115 gnutls_db_remove_session( *m_session );
116 gnutls_deinit( *m_session );
122 else if( ret == GNUTLS_E_AGAIN )
135 ssize_t GnuTLSBase::pullFunc(
void *data,
size_t len )
137 ssize_t cpy = ( len > m_recvBuffer.length() ) ? ( m_recvBuffer.length() ) : ( len );
140 memcpy( data, (
const void*)m_recvBuffer.c_str(), cpy );
141 m_recvBuffer.erase( 0, cpy );
147 return GNUTLS_E_AGAIN;
151 ssize_t GnuTLSBase::pullFunc( gnutls_transport_ptr_t ptr,
void *data,
size_t len )
153 return static_cast<GnuTLSBase*
>( ptr )->pullFunc( data, len );
156 ssize_t GnuTLSBase::pushFunc(
const void *data,
size_t len )
164 ssize_t GnuTLSBase::pushFunc( gnutls_transport_ptr_t ptr,
const void *data,
size_t len )
166 return static_cast<GnuTLSBase*
>( ptr )->pushFunc( data, len );
171 #endif // HAVE_GNUTLS