Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/sys/select.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif

#include_next <sys/select.h>
6 changes: 5 additions & 1 deletion include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
#define SO_NOSLOWSTART 0x4000 // disable slowstart
#define SO_RUSRBUF 0x10000 // enable somemopt provided memory for receive buffer

typedef uint32_t socklen_t;
#ifndef __socklen_t_defined
typedef __socklen_t socklen_t;
#define __socklen_t_defined
#endif

typedef uint16_t sa_family_t;

struct sockaddr
Expand Down
4 changes: 4 additions & 0 deletions libraries/wutsocket/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ poll(struct pollfd *fds,

if ((cnv_fd + 1) > cnv_nfds) {
cnv_nfds = cnv_fd + 1;
if (cnv_nfds > NSYSNET_FD_SETSIZE) {
errno = EINVAL;
return -1;
}
}

if (fds[i].events & POLLIN) {
Expand Down
16 changes: 9 additions & 7 deletions libraries/wutsocket/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ select(int nfds,
nsysnet_fd_set cnv_rd, cnv_wr, cnv_ex;
struct nsysnet_timeval cnv_timeout;

if (nfds > FD_SETSIZE) {
errno = EINVAL;
return -1;
}

NSYSNET_FD_ZERO(&cnv_rd);
NSYSNET_FD_ZERO(&cnv_wr);
NSYSNET_FD_ZERO(&cnv_ex);
Expand All @@ -38,6 +33,10 @@ select(int nfds,

if ((cnv_fd + 1) > cnv_nfds) {
cnv_nfds = cnv_fd + 1;
if (cnv_nfds > NSYSNET_FD_SETSIZE) {
errno = EINVAL;
return -1;
}
}

if (rd_fd) {
Expand Down Expand Up @@ -67,8 +66,6 @@ select(int nfds,
return rc;
}

rc = 0;

if (readfds) {
FD_ZERO(readfds);
}
Expand All @@ -79,6 +76,11 @@ select(int nfds,
FD_ZERO(exceptfds);
}

if (rc == 0)
return 0;

rc = 0;

for (i = 0; i < nfds; i++) {
int cnv_fd = __wut_get_nsysnet_fd(i);
if (cnv_fd == -1) {
Expand Down