diff --git a/racket/src/rktio/README.txt b/racket/src/rktio/README.txt new file mode 100644 index 0000000000..9432621fa7 --- /dev/null +++ b/racket/src/rktio/README.txt @@ -0,0 +1,18 @@ +The "rktio" library (for "Racket I/O") is a layer just above the OS +layer to provide a portable interface to filesystem, networking, etc. +facilities. + +The library is meant to be + + * easily embeddable; + + * always non-blocking; + + * independent of global state (except on Windows, where internal + global state is managed appropriately with locks), so that it works + with or without threads; and + + * easily callable though a FFI. + +Many such libraries exist already. This one happens to have exactly +the things that a Racket implementation needs. diff --git a/racket/src/rktio/rktio_poll_set.c b/racket/src/rktio/rktio_poll_set.c index 3c897c8490..70cae53fda 100644 --- a/racket/src/rktio/rktio_poll_set.c +++ b/racket/src/rktio/rktio_poll_set.c @@ -824,12 +824,20 @@ int rktio_get_fd_limit(rktio_poll_set_t *fds) int actual_limit; # ifdef STORED_ACTUAL_FDSET_LIMIT - actual_limit = FDSET_LIMIT(rd); - if (FDSET_LIMIT(wr) > actual_limit) - actual_limit = FDSET_LIMIT(wr); - if (FDSET_LIMIT(ex) > actual_limit) - actual_limit = FDSET_LIMIT(ex); - actual_limit++; + { + fd_set *rd, *wr, *ex; + + rd = RKTIO_FDS(fds); + wr = RKTIO_FDS(RKTIO_GET_FDSET(fds, 1)); + ex = RKTIO_FDS(RKTIO_GET_FDSET(fds, 2)); + + actual_limit = FDSET_LIMIT(rd); + if (FDSET_LIMIT(wr) > actual_limit) + actual_limit = FDSET_LIMIT(wr); + if (FDSET_LIMIT(ex) > actual_limit) + actual_limit = FDSET_LIMIT(ex); + actual_limit++; + } # elif defined (USE_ULIMIT) actual_limit = ulimit(4, 0); #elif defined(FIXED_FD_LIMIT) diff --git a/racket/src/rktio/rktio_private.h b/racket/src/rktio/rktio_private.h index 07c83d0d5d..98b5521bf1 100644 --- a/racket/src/rktio/rktio_private.h +++ b/racket/src/rktio/rktio_private.h @@ -16,6 +16,13 @@ # include #endif +#if defined(__linux__) || defined(OS_X) || defined(__NetBSD__) \ + || defined(__NetBSD__) || defined(__OpenBSD__) \ + || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ + || defined(__DragonFly__) || defined(__QNX__) +# define USE_DYNAMIC_FDSET_SIZE +#endif + #if RKTIO_SYSTEM_WINDOWS # define USE_FAR_RKTIO_FDCALLS #endif @@ -85,7 +92,7 @@ void rktio_fdset(rktio_poll_set_t *fd, int n); void rktio_fdclr(rktio_poll_set_t *fd, int n); int rktio_fdisset(rktio_poll_set_t *fd, int n); -# define DECL_FDSET(n, c) fd_set *n +# define DECL_FDSET(n, c) rktio_poll_set_t *n # define INIT_DECL_FDSET(r, w, e) { \ r = RKTIO_GET_FDSET(rktio->rktio_global_poll_set, 0 ); \ w = RKTIO_GET_FDSET(rktio->rktio_global_poll_set, 1 ); \ @@ -102,7 +109,7 @@ int rktio_fdisset(rktio_poll_set_t *fd, int n); # define RKTIO_FD_ISSET(n, p) rktio_fdisset(p, n) # if !defined(HAVE_POLL_SYSCALL) && !defined(RKTIO_SYSTEM_WINDOWS) -# define RKTIO_FDS(p) ((fd_set *)fds) +# define RKTIO_FDS(p) ((fd_set *)p) # endif #else