diff --git a/lib/u_async.c b/lib/u_async.c index 4957f5cf..037a2306 100644 --- a/lib/u_async.c +++ b/lib/u_async.c @@ -800,3 +800,13 @@ int uasync_get_wakeup_fd(struct UASYNC* ua) { if (!ua || !ua->wakeup_initialized) return -1; return ua->wakeup_pipe[1]; } + +/* Lookup socket by file descriptor - returns current pointer even after realloc */ +int uasync_lookup_socket(struct UASYNC* ua, int fd, void** socket_id) { + if (!ua || !ua->sockets || !socket_id || fd < 0 || fd >= FD_SETSIZE) { + return -1; + } + + *socket_id = socket_array_get(ua->sockets, fd); + return (*socket_id != NULL) ? 0 : -1; +} diff --git a/lib/u_async.h b/lib/u_async.h index c0c45dfa..a933eba5 100644 --- a/lib/u_async.h +++ b/lib/u_async.h @@ -56,11 +56,14 @@ void uasync_poll(struct UASYNC* ua, int timeout_tb); // Mainloop (бесконечный цикл, __noreturn) void uasync_mainloop(struct UASYNC* ua); -// Debug statistics -void uasync_get_stats(struct UASYNC* ua, size_t* timer_alloc, size_t* timer_free, size_t* socket_alloc, size_t* socket_free); - -// Print all resources (timers, sockets) for debugging -void uasync_print_resources(struct UASYNC* ua, const char* prefix); +// Debug statistics +void uasync_get_stats(struct UASYNC* ua, size_t* timer_alloc, size_t* timer_free, size_t* socket_alloc, size_t* socket_free); + +// Lookup socket by file descriptor - returns current pointer even after realloc +int uasync_lookup_socket(struct UASYNC* ua, int fd, void** socket_id); + +// Print all resources (timers, sockets) for debugging +void uasync_print_resources(struct UASYNC* ua, const char* prefix); // Wakeup mechanism for interrupting poll int uasync_wakeup(struct UASYNC* ua);