Add timeout callculate and return string in obey methods

dev v0.4_beta
marcelb 1 year ago
parent 24e2a4e4a9
commit 93d72e16aa
  1. 12
      src/tcp_socket.cpp
  2. 2
      test/client.cpp
  3. BIN
      test/client.o
  4. 3
      test/server.cpp
  5. BIN
      test/server.o

@ -126,8 +126,8 @@ client::client(const string address, const ushort port, const uint timeout, SSL_
}
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = timeout*1000;
tv.tv_sec = timeout/1000;
tv.tv_usec = (timeout%1000)*1000;
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval))) {
throw string("[ERROR] Unable to set timeout ");
@ -206,7 +206,7 @@ string client::obey (size_t byte_limit) {
read(sock , res, byte_limit);
}
return (string) res;
return string(res);
}
/**
@ -226,8 +226,8 @@ comming::comming(const server *_srv, const uint timeout, SSL_CTX* securefds) {
}
struct timeval tv;
tv.tv_sec = 0; // za sad 2 sekunde timeout, harkodirano
tv.tv_usec = timeout*1000;
tv.tv_sec = timeout/1000;
tv.tv_usec = (timeout%1000)*1000;
if (setsockopt(conn, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval))) {
throw string("[ERROR] Unable to set timeout ");
@ -313,5 +313,5 @@ string comming::obey (size_t byte_limit) {
read(conn , res, byte_limit);
}
return (string) res;
return string(res);
}

@ -11,7 +11,7 @@ int main() {
secure crypto;
cout << "init cert " << endl;
client myserver("127.0.0.1", 5000, 500, crypto.fds);
client myserver("127.0.0.1", 5000, 5000, crypto.fds);
// client myserver("localhost", 5000);
cout << "init client " << endl;

Binary file not shown.

@ -18,7 +18,8 @@ int main() {
string fromclient = myclient.obey();
cout << "tell client " << fromclient << endl;
// sleep(5);
// usleep(600*1000);
sleep(5);
myclient.tell(fromclient);
// myclient.~comming();

Binary file not shown.
Loading…
Cancel
Save