summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2020-11-03 22:37:48 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2020-11-03 22:37:48 +0100
commit5d8182c246538e84b4b1bda5ba1c4e388fa9cccd (patch)
treeffe17592da961026ddf6ee9973c8c27d6cb79ad3
parent842a347a4b8ce3a41e457e79d04cf901ec26a644 (diff)
Use select(2) when accessing several file descriptors at once
-rw-r--r--gdbstub/gdbstub_sys.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/gdbstub/gdbstub_sys.c b/gdbstub/gdbstub_sys.c
index 688cf1e3..86f18f63 100644
--- a/gdbstub/gdbstub_sys.c
+++ b/gdbstub/gdbstub_sys.c
@@ -10,6 +10,7 @@
#include <pthread.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/select.h>
#include <mqueue.h>
#include <errno.h>
@@ -142,10 +143,27 @@ static int wait_hit_or_break(struct msg *msg)
if (exit_loop)
return 1;
- SetsNonblock(client_socket);
-
if (ret < 0 && errno == EAGAIN) {
/* Breakpoint has not been hit yet, look for incoming messages from gdb. */
+ SetsNonblock(client_socket);
+
+ {
+ const int fd = in_queue > client_socket ? in_queue : client_socket;
+ fd_set set;
+
+ FD_ZERO(&set);
+ FD_SET(in_queue, &set);
+ FD_SET(client_socket, &set);
+
+ /* Warning: mqd_t are file descriptors in Linux and hence
+ * can be used with select(), but this is not portable. */
+ if (select(fd + 1, &set, NULL, NULL, NULL) < 0)
+ {
+ perror("wait_hit_or_break: select");
+ return EOF;
+ }
+ }
+
char packet;
size_t len = sizeof packet;
const enum read_socket_err err = ReadSocket(client_socket, &packet, &len);