1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[select] Introduced get_handler_data

This commit is contained in:
Witold Filipczyk 2022-02-21 19:03:54 +01:00
parent 7fa9c6f7d9
commit 2e2737e6de
3 changed files with 13 additions and 3 deletions

View File

@ -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_READ: return threads[fd].read_func;
case SELECT_HANDLER_WRITE: return threads[fd].write_func; case SELECT_HANDLER_WRITE: return threads[fd].write_func;
case SELECT_HANDLER_ERROR: return threads[fd].error_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); INTERNAL("get_handler: bad type %d", tp);
return NULL; return NULL;
} }
void *
get_handler_data(int fd)
{
if (fd >= w_max) {
return NULL;
}
return threads[fd].data;
}
void void
set_handlers(int fd, select_handler_T read_func, select_handler_T write_func, set_handlers(int fd, select_handler_T read_func, select_handler_T write_func,
select_handler_T error_func, void *data) select_handler_T error_func, void *data)

View File

@ -28,12 +28,13 @@ enum select_handler_type {
SELECT_HANDLER_READ, SELECT_HANDLER_READ,
SELECT_HANDLER_WRITE, SELECT_HANDLER_WRITE,
SELECT_HANDLER_ERROR, SELECT_HANDLER_ERROR,
SELECT_HANDLER_DATA,
}; };
/* Get a registered select handler. */ /* Get a registered select handler. */
select_handler_T get_handler(int fd, enum select_handler_type type); 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. */ /* Set handlers and callback @data for the @fd descriptor. */
void set_handlers(int fd, void set_handlers(int fd,
select_handler_T read_handler, select_handler_T read_handler,

View File

@ -99,7 +99,7 @@ itrm_queue_write(struct itrm *itrm)
get_handler(itrm->out.sock, SELECT_HANDLER_READ), get_handler(itrm->out.sock, SELECT_HANDLER_READ),
NULL, NULL,
get_handler(itrm->out.sock, SELECT_HANDLER_ERROR), get_handler(itrm->out.sock, SELECT_HANDLER_ERROR),
get_handler(itrm->out.sock, SELECT_HANDLER_DATA)); get_handler_data(itrm->out.sock));
} else { } else {
assert(itrm->out.queue.len > 0); assert(itrm->out.queue.len > 0);
memmove(itrm->out.queue.data, itrm->out.queue.data + written, itrm->out.queue.len); memmove(itrm->out.queue.data, itrm->out.queue.data + written, itrm->out.queue.len);