diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-12-30 05:24:40 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-12-30 05:24:40 +0100 |
commit | 01e3a7a8cd6b7da78bc7bfc883b9b04c328ea2e6 (patch) | |
tree | b4a9beb72cc19ad37d537e11616accd3d1f87ee0 /kms/client | |
parent | 027b29cb6edead1c0128a95fe202a997dbfea388 (diff) |
Use poll instead of select
Diffstat (limited to 'kms/client')
-rw-r--r-- | kms/client/kms_client.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index 9fadf05..0e6d1df 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -11,6 +11,7 @@ #include <sys/socket.h> #include <sys/un.h> #include <sys/wait.h> +#include <sys/poll.h> #include <sys/stat.h> #include <sys/capability.h> @@ -318,17 +319,14 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { } fprintf(stderr, "gsr info: gsr_kms_client_init: waiting for server to connect\n"); + struct pollfd poll_fd = { + .fd = self->initial_socket_fd, + .events = POLLIN, + .revents = 0 + }; for(;;) { - struct timeval tv; - fd_set rfds; - FD_ZERO(&rfds); - FD_SET(self->initial_socket_fd, &rfds); - - tv.tv_sec = 0; - tv.tv_usec = 100 * 1000; // 100 ms - - int select_res = select(1 + self->initial_socket_fd, &rfds, NULL, NULL, &tv); - if(select_res > 0) { + int poll_res = poll(&poll_fd, 1, 100); + if(poll_res > 0 && (poll_fd.revents & POLLIN)) { socklen_t sock_len = 0; self->initial_client_fd = accept(self->initial_socket_fd, (struct sockaddr*)&remote_addr, &sock_len); if(self->initial_client_fd == -1) { |