socket fs: simplify AF_UNSPEC

Remove separate context state for AF_UNSPEC.

issue #5031
This commit is contained in:
Sebastian Sumpf 2023-11-06 18:45:04 +01:00 committed by Christian Helmuth
parent c7956aa41b
commit 3264a22c1e

View File

@ -122,7 +122,7 @@ struct Libc::Socket_fs::Context : Plugin_context
enum Proto { TCP, UDP }; enum Proto { TCP, UDP };
enum State { UNCONNECTED, ACCEPT_ONLY, CONNECTING, CONNECTED, CONNECT_ABORTED, UNSPEC }; enum State { UNCONNECTED, ACCEPT_ONLY, CONNECTING, CONNECTED, CONNECT_ABORTED };
/* TODO remove */ /* TODO remove */
struct Inaccessible { }; /* exception */ struct Inaccessible { }; /* exception */
@ -680,10 +680,21 @@ extern "C" int socket_fs_connect(int libc_fd, sockaddr const *addr, socklen_t ad
switch (addr->sa_family) { switch (addr->sa_family) {
case AF_UNSPEC: case AF_UNSPEC:
if (context->state() != Context::CONNECTED) {
if (context->state() != Context::CONNECTED)
return 0;
Sockaddr_string addr_string { };
int const len = ::strlen(addr_string.base());
int const n = write(context->connect_fd(), addr_string.base(), len);
if (n != len)
return (context->proto() == Context::UDP) ? Errno(EIO) : Errno(EAFNOSUPPORT);
context->state(Context::UNCONNECTED);
return 0; return 0;
context->state(Context::UNSPEC); /* reset */ }
break;
case AF_INET: case AF_INET:
break; break;
default: default:
@ -691,18 +702,6 @@ extern "C" int socket_fs_connect(int libc_fd, sockaddr const *addr, socklen_t ad
} }
switch (context->state()) { switch (context->state()) {
case Context::UNSPEC:
{
Sockaddr_string addr_string { };
int const len = ::strlen(addr_string.base());
int const n = write(context->connect_fd(), addr_string.base(), len);
if (n != len) return Errno(ECONNREFUSED);
context->state(Context::UNCONNECTED);
return 0;
}
case Context::UNCONNECTED: case Context::UNCONNECTED:
{ {
Sockaddr_string addr_string; Sockaddr_string addr_string;