Libuv - how to stop a tcp server that is running in a different thread

For example, I have 2 threads . I want to stop the server from the main thread (Thread 1).

Theme 1: main program

Topic 2: TcpServer

From the libuv library:

/*
 * This function will stop the event loop by forcing uv_run to end
 * as soon as possible, but not sooner than the next loop iteration.
 * If this function was called before blocking for i/o, the loop won't
 * block for i/o on this iteration.
 */
UV_EXTERN void uv_stop(uv_loop_t*);

This means that if I called uv_stop(tcp_server_loop)in the main thread, and the server loop would be blocked due to the absence of events on tcpserver, then the server would remain in the loop until any event occurred. (he probably checks to see if there was a call uv_stopbefore the loop goes into blocking mode to wait for new events).

+4
source share
1 answer

uv_run UV_RUN_DEFAULT, . , uv_stop, uv_run . , uv, , uv_async_send, , uv_stop TcpServer, .

+4

Source: https://habr.com/ru/post/1531195/


All Articles