headless: expose OS-assigned control and audio listener ports
This commit is contained in:
1 parent
91909fbb1e
commit
dc0dbbf720
12 files changed
+91
-53
No files matched your search
@@ -903,7 +903,9 @@ static void hc_cleanup(void* arg) {
|
||||
|
||||
int chat_headless_control_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
const char* bind_ip, int port) {
|
||||
if (!ua || !inst || !bind_ip || port <= 0 || port > 65535) return -1;
|
||||
if (!ua || !inst || !bind_ip || port < 0 || port > 65535) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_HEADLESS, "headless: invalid init arguments port=%d", port); return -1;
|
||||
}
|
||||
struct headless_control* hc = hc_of(inst);
|
||||
if (hc && hc->running) return 0;
|
||||
|
||||
@@ -929,6 +931,8 @@ int chat_headless_control_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
socket_close_wrapper(hc->listen_fd); hc->listen_fd = SOCKET_INVALID; return -1;
|
||||
}
|
||||
if (listen(hc->listen_fd, 5) < 0) { socket_close_wrapper(hc->listen_fd); hc->listen_fd = SOCKET_INVALID; return -1; }
|
||||
uint16_t bound_port = socket_get_bound_port(hc->listen_fd);
|
||||
if (!bound_port) { socket_close_wrapper(hc->listen_fd); hc->listen_fd = SOCKET_INVALID; return -1; }
|
||||
|
||||
hc->listen_sock_id = uasync_add_socket_t(ua, hc->listen_fd, accept_callback, NULL, NULL, "chatctl_listen", hc);
|
||||
if (!hc->listen_sock_id) { socket_close_wrapper(hc->listen_fd); hc->listen_fd = SOCKET_INVALID; return -1; }
|
||||
@@ -941,10 +945,16 @@ int chat_headless_control_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
}
|
||||
|
||||
hc->running = 1;
|
||||
DEBUG_INFO((int)DEBUG_CATEGORY_HEADLESS, "headless: listening on %s:%d", bind_ip, port);
|
||||
DEBUG_INFO((int)DEBUG_CATEGORY_HEADLESS, "headless: listening on %s:%u", bind_ip, bound_port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t chat_headless_control_get_port(struct UTUN_INSTANCE* inst) {
|
||||
if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_HEADLESS, "headless: get port without instance"); return 0; }
|
||||
struct headless_control* hc = hc_of(inst);
|
||||
return hc && hc->running ? socket_get_bound_port(hc->listen_fd) : 0;
|
||||
}
|
||||
|
||||
void chat_headless_control_destroy(struct UTUN_INSTANCE* inst) {
|
||||
struct headless_control* hc = hc_of(inst);
|
||||
if (!hc) return;
|
||||
|
||||
@@ -23,5 +23,7 @@ struct UTUN_INSTANCE;
|
||||
int chat_headless_control_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
const char* bind_ip, int port);
|
||||
void chat_headless_control_destroy(struct UTUN_INSTANCE* inst);
|
||||
// port=0 при init выбирает ОС; getter возвращает 0 для остановленной службы или при ошибке.
|
||||
uint16_t chat_headless_control_get_port(struct UTUN_INSTANCE* inst);
|
||||
|
||||
#endif /* CHAT_HEADLESS_CONTROL_H */
|
||||
Reference in new issue
Block a user