1 #include "opensslBIO.h"
2 #include <log/logger.hpp>
4 OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> _b ) : b( _b ), buffer( 2 * 0xFFFF + 20, 0 ), pos( 0 ) {
7 OpensslBIOWrapper::~OpensslBIOWrapper() {
10 int OpensslBIOWrapper::write( const char* buf, int num ) {
11 return BIO_write( b.get(), buf, num );
14 int OpensslBIOWrapper::read( char* buf, int size ) {
15 return BIO_read( b.get(), buf, size );
18 long OpensslBIOWrapper::ctrl( int cmod, long arg1, void* arg2 ) {
19 return BIO_ctrl( b.get(), cmod, arg1, arg2 );
22 int OpensslBIOWrapper::puts( const char* str ) {
23 return BIO_puts( b.get(), str );
26 int OpensslBIOWrapper::gets( char* str, int size ) {
27 return BIO_gets( b.get(), str, size );
30 const char* OpensslBIOWrapper::getName() {
31 return "OpenSSLWrapper";
33 std::string OpensslBIOWrapper::readLine() {
37 logger::debug( "doing data" );
39 while( target < pos ) {
40 if( buffer[target] == '\n' ) {
42 std::string res( buffer.data(), 0, target );
43 std::copy( buffer.data() + target, buffer.data() + pos, buffer.data() );
45 logger::debug( "emit" );
53 ss << "target: " << target << ", pos:" << pos;
54 logger::debug( ss.str() );
55 int dlen = read( buffer.data() + pos, buffer.size() - pos );
58 throw eof_exception();
61 std::stringstream ss2;
62 ss2 << "done: " << dlen;
63 logger::debug( ss2.str() );