Commit b3e9865e authored by Jonas Termansen's avatar Jonas Termansen

Handle SOCK_NONBLOCK at the file descriptor level.

parent bc8093f4
......@@ -965,13 +965,19 @@ int Descriptor::poll(ioctx_t* ctx, PollNode* node)
Ref<Descriptor> Descriptor::accept4(ioctx_t* ctx, uint8_t* addr,
size_t* addrlen, int flags)
{
if ( flags & ~(SOCK_NONBLOCK) )
return errno = EINVAL, Ref<Descriptor>();
int new_dflags = O_READ | O_WRITE;
if ( flags & SOCK_NONBLOCK )
new_dflags |= O_NONBLOCK;
flags &= ~(SOCK_NONBLOCK);
int old_ctx_dflags = ctx->dflags;
ctx->dflags = ContextFlags(old_ctx_dflags, dflags);
Ref<Vnode> retvnode = vnode->accept4(ctx, addr, addrlen, flags);
if ( !retvnode )
return Ref<Descriptor>();
ctx->dflags = old_ctx_dflags;
return Ref<Descriptor>(new Descriptor(retvnode, O_READ | O_WRITE));
return Ref<Descriptor>(new Descriptor(retvnode, new_dflags));
}
int Descriptor::bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen)
......
......@@ -731,15 +731,11 @@ int sys_accept4(int fd, void* addr, size_t* addrlen, int flags)
int fdflags = 0;
if ( flags & SOCK_CLOEXEC ) fdflags |= FD_CLOEXEC;
if ( flags & SOCK_CLOFORK ) fdflags |= FD_CLOFORK;
int descflags = 0;
if ( flags & SOCK_NONBLOCK ) descflags |= O_NONBLOCK;
flags &= ~(SOCK_CLOEXEC | SOCK_CLOFORK | SOCK_NONBLOCK);
flags &= ~(SOCK_CLOEXEC | SOCK_CLOFORK);
ioctx_t ctx; SetupUserIOCtx(&ctx);
Ref<Descriptor> conn = desc->accept4(&ctx, (uint8_t*) addr, addrlen, flags);
if ( !conn )
return -1;
if ( descflags )
conn->SetFlags(conn->GetFlags() | descflags);
return CurrentProcess()->GetDTable()->Allocate(conn, fdflags);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment