mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2026-10-09 23:58:19 +03:00
prinet-proxy/client: Bugfix, avoid claiming mutex constantly
Without a brief pause between retries on the socket to receive data, other threads, e.g. keepalive, have a hard time acquiring the mutex. This leads to the keepalive thread gettin stuck frequently.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
#include "util/sock-tcp.h"
|
||||
#include "util/time.h"
|
||||
|
||||
struct pumpnet_prinet_proxy_client_connection {
|
||||
int handle;
|
||||
@@ -28,6 +29,9 @@ static bool _pumpnet_prinet_proxy_client_recv_packet_length(struct pumpnet_prine
|
||||
|
||||
if (read == 0) {
|
||||
// no data, repeat
|
||||
// Avoid banging immediately on socket/mutex. Other threads, e.g. keepalive, might want to send something as well
|
||||
util_time_sleep_ms(10);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,18 +19,18 @@ static atomic_bool _pumpnet_prinet_proxy_keepalive_thread_run;
|
||||
static void* _pumpnet_prinet_proxy_keepalive_proc(void* ctx)
|
||||
{
|
||||
struct pumpnet_prinet_proxy_packet* keepalive_packet;
|
||||
uint64_t time_prev_ns;
|
||||
uint64_t time_prev_us;
|
||||
|
||||
time_prev_ns = util_time_now_ns();
|
||||
time_prev_us = util_time_now_us();
|
||||
|
||||
log_debug("Keepalive thread started");
|
||||
|
||||
while (_pumpnet_prinet_proxy_keepalive_thread_run) {
|
||||
uint64_t time_now_ns = util_time_now_ns();
|
||||
double time_delta_ms = util_time_delta_ms(time_prev_ns, time_now_ns);
|
||||
uint64_t time_now_us = util_time_now_us();
|
||||
double time_delta_ms = util_time_delta_ms(time_prev_us, time_now_us);
|
||||
|
||||
if (time_delta_ms >= _pumpnet_prinet_proxy_keepalive_poll_ms) {
|
||||
time_prev_ns = time_now_ns;
|
||||
time_prev_us = time_now_us;
|
||||
|
||||
if (pumpnet_prinet_proxy_client_connection_is_active(_pumpnet_prinet_proxy_client_connection)) {
|
||||
log_debug("Sending keepalive");
|
||||
|
||||
Reference in New Issue
Block a user