It sometimes stucks on beginning

This commit is contained in:
flowher 2013-09-09 23:24:55 +02:00
parent 614f82a7d7
commit ec012d960b
2 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@ EXECUTABLE = server
EXECUTABLECLI = client
CC=g++ -lboost_system -lboost_thread
CFLAGS=-Wall -O2 -DDEBUG -Wreorder
CFLAGS=-Wall -DDEBUG -Wreorder
COMPILE=$(CC) $(CFLAGS)
all: server client

View File

@ -44,7 +44,7 @@ void Sender()
lock_guard<mutex> lock(WriteReadMutex);
len+=SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len);
// for debugging re-neg
// cout << "SSL STATE: " << SSL_state_string(handler.second) << endl;
cout << "SSL STATE: " << SSL_state_string(SSLHandler) << endl;
} while( len != static_cast<int>(buf.size()) );
}
};
@ -52,6 +52,7 @@ void Sender()
void Client::receive()
{
char buf[MAX_PACKET_SIZE];
cout << "R " << endl;
// TODO: this way it takes 100% CPU, some signal would be usefull
memset(buf,'\0',MAX_PACKET_SIZE);
@ -97,6 +98,13 @@ void Client::connect()
}
SSLHandler = SSL_new(_ctx);
long mode = SSL_CTX_set_mode(_ctx, SSL_MODE_AUTO_RETRY);
if( ( mode & SSL_MODE_AUTO_RETRY) != SSL_MODE_AUTO_RETRY )
{
throw runtime_error("SSL_MODE_AUTO_RETRY couldn't be set");
}
SSL_set_fd(SSLHandler, _handler);
if( SSL_connect(SSLHandler) <= 0)
@ -105,7 +113,9 @@ void Client::connect()
exit(1);
}
// bug reproduces even if call is blocking, so not need to uncommet this line
// fcntl(_handler, F_SETFL, O_NONBLOCK);
int opts = fcntl(_handler,F_GETFL);
opts = opts & ( ~O_NONBLOCK );
fcntl(_handler, F_SETFL, opts);
}
void Client::start()