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
@@ -312,7 +312,9 @@ static void ca_cleanup(void* arg) {
|
||||
|
||||
int call_headless_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_CALL, "%s: invalid init arguments port=%d", CH_ID, port); return -1;
|
||||
}
|
||||
struct call_audio* ca = ca_of(inst);
|
||||
if (ca && ca->running) return 0;
|
||||
|
||||
@@ -336,6 +338,8 @@ int call_headless_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
socket_close_wrapper(ca->listen_fd); ca->listen_fd = SOCKET_INVALID; return -1;
|
||||
}
|
||||
if (listen(ca->listen_fd, 5) < 0) { socket_close_wrapper(ca->listen_fd); ca->listen_fd = SOCKET_INVALID; return -1; }
|
||||
uint16_t bound_port = socket_get_bound_port(ca->listen_fd);
|
||||
if (!bound_port) { socket_close_wrapper(ca->listen_fd); ca->listen_fd = SOCKET_INVALID; return -1; }
|
||||
|
||||
ca->listen_sock_id = uasync_add_socket_t(ua, ca->listen_fd, ca_accept_callback, NULL, NULL, "call_listen", ca);
|
||||
if (!ca->listen_sock_id) { socket_close_wrapper(ca->listen_fd); ca->listen_fd = SOCKET_INVALID; return -1; }
|
||||
@@ -345,10 +349,16 @@ int call_headless_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
if (!ca->cleanup_timer) DEBUG_ERROR(DEBUG_CATEGORY_CALL, "%s: cleanup timer scheduling failed", CH_ID);
|
||||
|
||||
ca->running = 1;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CALL, "%s: audio socket listening on %s:%d", CH_ID, bind_ip, port);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CALL, "%s: audio socket listening on %s:%u", CH_ID, bind_ip, bound_port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t call_headless_get_port(struct UTUN_INSTANCE* inst) {
|
||||
if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "%s: get port without instance", CH_ID); return 0; }
|
||||
struct call_audio* ca = ca_of(inst);
|
||||
return ca && ca->running ? socket_get_bound_port(ca->listen_fd) : 0;
|
||||
}
|
||||
|
||||
void call_headless_destroy(struct UTUN_INSTANCE* inst) {
|
||||
struct call_audio* ca = ca_of(inst);
|
||||
if (!ca || !ca->running) return;
|
||||
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
int call_headless_init(struct UASYNC* ua, struct UTUN_INSTANCE* inst,
|
||||
const char* bind_ip, int port);
|
||||
void call_headless_destroy(struct UTUN_INSTANCE* inst);
|
||||
// port=0 при init выбирает ОС; 0 для остановленной службы или при ошибке.
|
||||
uint16_t call_headless_get_port(struct UTUN_INSTANCE* inst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user