Browse Source

Fixed mutexed version

master
flowher 11 years ago
parent
commit
614f82a7d7
3 changed files with 12 additions and 12 deletions
  1. +1
    -1
      Makefile
  2. +7
    -11
      client.cpp
  3. +4
    -0
      server.cpp

+ 1
- 1
Makefile View File

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


+ 7
- 11
client.cpp View File

@@ -27,7 +27,6 @@
using namespace std; using namespace std;
using namespace boost; using namespace boost;


int Handler = 0;
SSL* SSLHandler = 0; SSL* SSLHandler = 0;
int CharsRead = 0; int CharsRead = 0;


@@ -40,8 +39,6 @@ void Sender()
{ {
string buf(EXCHANGE_STRING); string buf(EXCHANGE_STRING);
int len = 0; int len = 0;
SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len);
/*
do do
{ {
lock_guard<mutex> lock(WriteReadMutex); lock_guard<mutex> lock(WriteReadMutex);
@@ -49,7 +46,6 @@ void Sender()
// for debugging re-neg // for debugging re-neg
// cout << "SSL STATE: " << SSL_state_string(handler.second) << endl; // cout << "SSL STATE: " << SSL_state_string(handler.second) << endl;
} while( len != static_cast<int>(buf.size()) ); } while( len != static_cast<int>(buf.size()) );
*/
} }
}; };


@@ -62,7 +58,6 @@ void Client::receive()
int len_rcv = 0; int len_rcv = 0;
{ {
lock_guard<mutex> lock(WriteReadMutex); lock_guard<mutex> lock(WriteReadMutex);
cout << "A" << endl;
len_rcv = SSL_read(SSLHandler, buf, MAX_PACKET_SIZE); len_rcv = SSL_read(SSLHandler, buf, MAX_PACKET_SIZE);
} }


@@ -89,26 +84,28 @@ void Client::connect()
lock_guard<mutex> lock(WriteReadMutex); lock_guard<mutex> lock(WriteReadMutex);


struct sockaddr_in echoserver; struct sockaddr_in echoserver;
int sock = socket(AF_INET, SOCK_STREAM, 0);
_handler = socket(AF_INET, SOCK_STREAM, 0);
memset(&echoserver, 0, sizeof(echoserver)); memset(&echoserver, 0, sizeof(echoserver));
echoserver.sin_family = AF_INET; echoserver.sin_family = AF_INET;
echoserver.sin_addr.s_addr = inet_addr(IP); echoserver.sin_addr.s_addr = inet_addr(IP);
echoserver.sin_port = htons(PORT); echoserver.sin_port = htons(PORT);


/* Establish connection */ /* Establish connection */
if ( 0 > ::connect(sock, (struct sockaddr *) &echoserver, sizeof(echoserver)) )
if ( 0 > ::connect(_handler, (struct sockaddr *) &echoserver, sizeof(echoserver)) )
{ {
throw runtime_error("Can't connect to the server"); throw runtime_error("Can't connect to the server");
} }
Handler = sock;
SSLHandler = SSL_new(_ctx); SSLHandler = SSL_new(_ctx);
SSL_set_fd(SSLHandler, Handler);
SSL_set_fd(SSLHandler, _handler);

if( SSL_connect(SSLHandler) <= 0) if( SSL_connect(SSLHandler) <= 0)
{ {
cerr << "Can't setup SSL session" << endl; cerr << "Can't setup SSL session" << endl;
exit(1); exit(1);
} }
fcntl(sock, F_SETFL, O_NONBLOCK);
// bug reproduces even if call is blocking, so not need to uncommet this line
// fcntl(_handler, F_SETFL, O_NONBLOCK);
} }


void Client::start() void Client::start()
@@ -147,7 +144,6 @@ void Client::start()
void Client::renegotiate() void Client::renegotiate()
{ {
lock_guard<mutex> lock_reads(WriteReadMutex); lock_guard<mutex> lock_reads(WriteReadMutex);
cout << "B" << endl;


cout << "Starting SSL renegotiation on SSL" cout << "Starting SSL renegotiation on SSL"
<< "client (initiating by SSL client)" << endl; << "client (initiating by SSL client)" << endl;


+ 4
- 0
server.cpp View File

@@ -32,11 +32,15 @@ mutex SocketSetMutex;
// WaitForWrite is a condition variable that is signaled when Sender must start sending the data // WaitForWrite is a condition variable that is signaled when Sender must start sending the data
condition_variable WaitForWrite; condition_variable WaitForWrite;
mutex WaitForWriteMutex; mutex WaitForWriteMutex;
// mutex that synchronizes access to SSL_read/SSL_write
mutex WriteReadMutex; mutex WriteReadMutex;
// thread functions to send and receive
void Receive(); void Receive();
void Send(); void Send();
Server::Server() Server::Server()
: SSLProcess(true) : SSLProcess(true)
, _master(0) , _master(0)


Loading…
Cancel
Save