Browse Source

It sometimes stucks on beginning

master
flowher 11 years ago
parent
commit
ec012d960b
2 changed files with 13 additions and 3 deletions
  1. +1
    -1
      Makefile
  2. +12
    -2
      client.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 -O2 -DDEBUG -Wreorder
CFLAGS=-Wall -DDEBUG -Wreorder
COMPILE=$(CC) $(CFLAGS) COMPILE=$(CC) $(CFLAGS)
all: server client all: server client


+ 12
- 2
client.cpp View File

@@ -44,7 +44,7 @@ void Sender()
lock_guard<mutex> lock(WriteReadMutex); lock_guard<mutex> lock(WriteReadMutex);
len+=SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len); len+=SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len);
// for debugging re-neg // 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()) ); } while( len != static_cast<int>(buf.size()) );
} }
}; };
@@ -52,6 +52,7 @@ void Sender()
void Client::receive() void Client::receive()
{ {
char buf[MAX_PACKET_SIZE]; char buf[MAX_PACKET_SIZE];
cout << "R " << endl;


// TODO: this way it takes 100% CPU, some signal would be usefull // TODO: this way it takes 100% CPU, some signal would be usefull
memset(buf,'\0',MAX_PACKET_SIZE); memset(buf,'\0',MAX_PACKET_SIZE);
@@ -97,6 +98,13 @@ void Client::connect()
} }


SSLHandler = SSL_new(_ctx); 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); SSL_set_fd(SSLHandler, _handler);


if( SSL_connect(SSLHandler) <= 0) if( SSL_connect(SSLHandler) <= 0)
@@ -105,7 +113,9 @@ void Client::connect()
exit(1); exit(1);
} }
// bug reproduces even if call is blocking, so not need to uncommet this line // 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() void Client::start()


Loading…
Cancel
Save