Added manual sleep to socket accept and recv
This commit is contained in:
@@ -123,9 +123,10 @@ read_stream(void)
|
|||||||
|
|
||||||
// error
|
// error
|
||||||
if (read_size == -1) {
|
if (read_size == -1) {
|
||||||
// read timeout, try again
|
// got nothing, sleep and try again
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
usleep(1000 * 5);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// real error
|
// real error
|
||||||
@@ -246,7 +247,7 @@ server_wait_for(char *id)
|
|||||||
log_println("WAIT complete for id: %s", id);
|
log_println("WAIT complete for id: %s", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
usleep(1000 * 50);
|
usleep(1000 * 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,16 +263,7 @@ _start_server_cb(void* userdata)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// listen socket read timeout
|
log_println("Waiting for incoming connection...");
|
||||||
struct timeval timeout;
|
|
||||||
timeout.tv_sec = 0;
|
|
||||||
timeout.tv_usec = 1000 * 10;
|
|
||||||
errno = 0;
|
|
||||||
res = setsockopt(listen_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
|
|
||||||
if (res < 0) {
|
|
||||||
log_println("Error setting listen socket options: %s", strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for connection
|
// wait for connection
|
||||||
int c = sizeof(struct sockaddr_in);
|
int c = sizeof(struct sockaddr_in);
|
||||||
@@ -283,6 +275,7 @@ _start_server_cb(void* userdata)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
usleep(1000 * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// client socket non blocking
|
// client socket non blocking
|
||||||
@@ -292,14 +285,6 @@ _start_server_cb(void* userdata)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// client socket read timeout
|
|
||||||
errno = 0;
|
|
||||||
res = setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
|
|
||||||
if (res < 0) {
|
|
||||||
log_println("Error setting client socket options: %s", strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
client = xmppclient_new(client_addr, client_socket);
|
client = xmppclient_new(client_addr, client_socket);
|
||||||
parser_init(stream_start_callback, auth_callback, id_callback, query_callback);
|
parser_init(stream_start_callback, auth_callback, id_callback, query_callback);
|
||||||
|
|
||||||
@@ -337,7 +322,7 @@ server_run(int port, int httpport)
|
|||||||
server_addr.sin_port = htons(port);
|
server_addr.sin_port = htons(port);
|
||||||
|
|
||||||
int reuse = 1;
|
int reuse = 1;
|
||||||
int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
|
int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &reuse, sizeof(reuse));
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
log_println("Set socket options failed: %s", strerror(errno));
|
log_println("Set socket options failed: %s", strerror(errno));
|
||||||
_shutdown();
|
_shutdown();
|
||||||
@@ -362,8 +347,6 @@ server_run(int port, int httpport)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_println("Waiting for incoming connection...");
|
|
||||||
|
|
||||||
prime_init();
|
prime_init();
|
||||||
|
|
||||||
// start client processor thread
|
// start client processor thread
|
||||||
|
|||||||
Reference in New Issue
Block a user