From e3071b372acaf7fb32c52fc664a8cdbdd92be56e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 4 Mar 2024 21:51:27 -0500 Subject: [PATCH] Poking at TCP binds from Haiku. --- src/http.c | 15 ++++++++++++++- src/ssb.c | 7 ++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/http.c b/src/http.c index ca4ea3f0..c8252a6a 100644 --- a/src/http.c +++ b/src/http.c @@ -619,15 +619,28 @@ int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls, tf_http_cle if (r == 0) { +#if defined(__HAIKU__) + /* + ** Binding to IPv6 here fails with an odd error, and the socket + ** becomes unusable. Since we probably want localhost only + ** on this single-user OS, let's just assume IPv4. + */ + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_addr = { .s_addr = INADDR_ANY }, + .sin_port = ntohs(port), + }; +#else struct sockaddr_in6 addr = { .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_ANY_INIT, .sin6_port = ntohs(port), }; +#endif r = uv_tcp_bind(&listener->tcp, (struct sockaddr*)&addr, 0); if (r) { - tf_printf("uv_tcp_bind: %s\n", uv_strerror(r)); + tf_printf("%s:%d: uv_tcp_bind: %s\n", __FILE__, __LINE__, uv_strerror(r)); } } diff --git a/src/ssb.c b/src/ssb.c index cc2ac0de..9a25885d 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -2843,13 +2843,14 @@ void tf_ssb_server_open(tf_ssb_t* ssb, int port) addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = INADDR_ANY; - if (uv_tcp_bind(&ssb->server, (struct sockaddr*)&addr, 0) != 0) + int status = uv_tcp_bind(&ssb->server, (struct sockaddr*)&addr, 0); + if (status != 0) { - tf_printf("uv_tcp_bind failed\n"); + tf_printf("%s:%d: uv_tcp_bind failed: %s\n", __FILE__, __LINE__, uv_strerror(status)); return; } - int status = uv_listen((uv_stream_t*)&ssb->server, SOMAXCONN, _tf_ssb_on_connection); + status = uv_listen((uv_stream_t*)&ssb->server, SOMAXCONN, _tf_ssb_on_connection); if (status != 0) { tf_printf("uv_listen failed: %s\n", uv_strerror(status));