mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-30 16:14:13 +00:00
socket fs: simplify AF_UNSPEC
Remove separate context state for AF_UNSPEC. issue #5031
This commit is contained in:
parent
c7956aa41b
commit
3264a22c1e
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user