From 2e2737e6de7a02de3c886ff93af00030daaefa90 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 21 Feb 2022 19:03:54 +0100 Subject: [PATCH] [select] Introduced get_handler_data --- src/main/select.c | 11 ++++++++++- src/main/select.h | 3 ++- src/terminal/kbd.c | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/select.c b/src/main/select.c index 1b63e68b..04982720 100644 --- a/src/main/select.c +++ b/src/main/select.c @@ -377,13 +377,22 @@ get_handler(int fd, enum select_handler_type tp) case SELECT_HANDLER_READ: return threads[fd].read_func; case SELECT_HANDLER_WRITE: return threads[fd].write_func; case SELECT_HANDLER_ERROR: return threads[fd].error_func; - case SELECT_HANDLER_DATA: return (select_handler_T)threads[fd].data; } INTERNAL("get_handler: bad type %d", tp); return NULL; } +void * +get_handler_data(int fd) +{ + if (fd >= w_max) { + return NULL; + } + + return threads[fd].data; +} + void set_handlers(int fd, select_handler_T read_func, select_handler_T write_func, select_handler_T error_func, void *data) diff --git a/src/main/select.h b/src/main/select.h index 24a2644a..dd2f9a2c 100644 --- a/src/main/select.h +++ b/src/main/select.h @@ -28,12 +28,13 @@ enum select_handler_type { SELECT_HANDLER_READ, SELECT_HANDLER_WRITE, SELECT_HANDLER_ERROR, - SELECT_HANDLER_DATA, }; /* Get a registered select handler. */ select_handler_T get_handler(int fd, enum select_handler_type type); +void *get_handler_data(int fd); + /* Set handlers and callback @data for the @fd descriptor. */ void set_handlers(int fd, select_handler_T read_handler, diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index d7d7a05b..95395208 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -99,7 +99,7 @@ itrm_queue_write(struct itrm *itrm) get_handler(itrm->out.sock, SELECT_HANDLER_READ), NULL, get_handler(itrm->out.sock, SELECT_HANDLER_ERROR), - get_handler(itrm->out.sock, SELECT_HANDLER_DATA)); + get_handler_data(itrm->out.sock)); } else { assert(itrm->out.queue.len > 0); memmove(itrm->out.queue.data, itrm->out.queue.data + written, itrm->out.queue.len);