Fix select() portability issues in src/server.c
Fix select() portability issues in src/server.c by using gettimeofday() immediately prior to and after calling select() to calculate elapsed time since blocking on select()
This commit is contained in:
parent
4899aa4796
commit
98490f79a7
1 changed files with 14 additions and 4 deletions
18
src/server.c
18
src/server.c
|
@ -1968,20 +1968,29 @@ int patty_ax25_server_run(patty_ax25_server *server) {
|
|||
while (1) {
|
||||
int nready;
|
||||
|
||||
struct timeval timer = { 1, 0 },
|
||||
remaining = { 1, 0 };
|
||||
struct timeval timeout = { 1, 0 },
|
||||
before,
|
||||
after;
|
||||
|
||||
memcpy(&server->fds_r, &server->fds_watch, sizeof(server->fds_r));
|
||||
|
||||
if (gettimeofday(&before, NULL) < 0) {
|
||||
goto error_gettimeofday;
|
||||
}
|
||||
|
||||
if ((nready = select( server->fd_max,
|
||||
&server->fds_r,
|
||||
NULL,
|
||||
NULL,
|
||||
&remaining)) < 0) {
|
||||
&timeout)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
timersub(&timer, &remaining, &server->elapsed);
|
||||
if (gettimeofday(&after, NULL) < 0) {
|
||||
goto error_gettimeofday;
|
||||
}
|
||||
|
||||
timersub(&after, &before, &server->elapsed);
|
||||
|
||||
if (handle_clients(server) < 0) {
|
||||
goto error_io;
|
||||
|
@ -2004,6 +2013,7 @@ int patty_ax25_server_run(patty_ax25_server *server) {
|
|||
|
||||
return 0;
|
||||
|
||||
error_gettimeofday:
|
||||
error_io:
|
||||
close(server->fd);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue