Poking at TCP binds from Haiku.

This commit is contained in:
Cory McWilliams 2024-03-04 21:51:27 -05:00
parent 18bd279b0c
commit e3071b372a
2 changed files with 18 additions and 4 deletions

View File

@ -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));
}
}

View File

@ -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));