summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-08-22 09:27:43 -0400
committerAndrew Cady <d@jerkface.net>2020-08-22 09:27:43 -0400
commit7b8fea71623849972b9aa61c9264a7d2bc6e76bf (patch)
tree482e6563b251ceab9d5106671fbb98b6ac7efde1
parent38f74d3530ff3d5724493114f430c3b2a851b82d (diff)
use tox_timer for sleep on client
-rw-r--r--client.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/client.c b/client.c
index 54f8c8a..d0353b1 100644
--- a/client.c
+++ b/client.c
@@ -272,19 +272,16 @@ void client_close_all_connections()
272 } 272 }
273} 273}
274 274
275void client_connected_loop_iteration(uint32_t friendnumber) 275void client_connected_loop_iteration(uint32_t friendnumber, struct tox_timer *t)
276{ 276{
277 static unsigned char tox_packet_buf[PROTOCOL_MAX_PACKET_SIZE]; 277 static unsigned char tox_packet_buf[PROTOCOL_MAX_PACKET_SIZE];
278 static fd_set fds; 278 static fd_set fds;
279 static struct timeval tv;
280 279
281 int accept_fd = 0; 280 int accept_fd = 0;
282 int select_rv = 0; 281 int select_rv = 0;
283 tunnel *tmp = NULL; 282 tunnel *tmp = NULL;
284 tunnel *tun = NULL; 283 tunnel *tun = NULL;
285 284
286 tv.tv_sec = 0;
287 tv.tv_usec = 20000;
288 fds = client_master_fdset; 285 fds = client_master_fdset;
289 286
290 /* Handle accepting new connections */ 287 /* Handle accepting new connections */
@@ -303,7 +300,7 @@ void client_connected_loop_iteration(uint32_t friendnumber)
303 } 300 }
304 301
305 /* Handle reading from sockets */ 302 /* Handle reading from sockets */
306 select_rv = select(select_nfds, &fds, NULL, NULL, &tv); 303 select_rv = select(select_nfds, &fds, NULL, NULL, &(t->tv));
307 if(select_rv == -1 || select_rv == 0) 304 if(select_rv == -1 || select_rv == 0)
308 { 305 {
309 if(select_rv == -1) 306 if(select_rv == -1)
@@ -415,6 +412,7 @@ int do_client_loop(uint8_t *tox_id_str)
415 { 412 {
416 /* Let tox do its stuff */ 413 /* Let tox do its stuff */
417 tox_iterate(tox, NULL); 414 tox_iterate(tox, NULL);
415 struct tox_timer t = init_tox_timer(tox);
418 416
419 switch(state) 417 switch(state)
420 { 418 {
@@ -531,11 +529,11 @@ int do_client_loop(uint8_t *tox_id_str)
531 case CLIENT_STATE_AWAIT_PONG: 529 case CLIENT_STATE_AWAIT_PONG:
532 break; 530 break;
533 case CLIENT_STATE_CONNECTED: 531 case CLIENT_STATE_CONNECTED:
534 client_connected_loop_iteration(friendnumber); 532 client_connected_loop_iteration(friendnumber, &t);
535 break; 533 break;
536 } 534 }
537 535
538 usleep(tox_iteration_interval(tox) * 1000); 536 run_tox_timer(tox, t);
539 } 537 }
540} 538}
541 539