Selaa lähdekoodia

It sometimes stucks on beginning

master
flowher 11 vuotta sitten
vanhempi
commit
ec012d960b
2 muutettua tiedostoa jossa 13 lisäystä ja 3 poistoa
  1. +1
    -1
      Makefile
  2. +12
    -2
      client.cpp

+ 1
- 1
Makefile Näytä tiedosto

@@ -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


+ 12
- 2
client.cpp Näytä tiedosto

@@ -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()


Ladataan…
Peruuta
Tallenna