mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Handle SOCK_NONBLOCK at the file descriptor level.
This commit is contained in:
parent
bc8093f4ff
commit
b3e9865e53
2 changed files with 8 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue