diff options
author | sof <unknown> | 1999-09-11 16:49:03 +0000 |
---|---|---|
committer | sof <unknown> | 1999-09-11 16:49:03 +0000 |
commit | 064567b95b91462ca310d1f94ef7df8646632e48 (patch) | |
tree | 9c74120610cf65a06ae0b168b9428a5f15a87fde /ghc/lib/misc/cbits/selectFrom.c | |
parent | c13c43a111e825bb87a465ccbb9533f302beaa09 (diff) | |
download | haskell-064567b95b91462ca310d1f94ef7df8646632e48.tar.gz |
[project @ 1999-09-11 16:49:02 by sof]
Added hSelect
Diffstat (limited to 'ghc/lib/misc/cbits/selectFrom.c')
-rw-r--r-- | ghc/lib/misc/cbits/selectFrom.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ghc/lib/misc/cbits/selectFrom.c b/ghc/lib/misc/cbits/selectFrom.c new file mode 100644 index 0000000000..55e6516ef3 --- /dev/null +++ b/ghc/lib/misc/cbits/selectFrom.c @@ -0,0 +1,72 @@ +/* + * (c) sof, 1999 + * + * Stubs to help implement Select module. + */ + +/* we're outside the realms of POSIX here... */ +#define NON_POSIX_SOURCE + +#include "Rts.h" +#include "selectFrom.h" +#include "stgio.h" + +# if defined(HAVE_SYS_TYPES_H) +# include <sys/types.h> +# endif + +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# endif + + +/* Helpers for the Haskell-side unmarshalling */ + +int +sizeof_fd_set__() +{ + return (sizeof(fd_set)); +} + +void +fd_zero__(StgByteArray a) +{ + FD_ZERO((fd_set*)a); +} + +void +fd_set__(StgByteArray a, StgInt fd) +{ + FD_SET(fd,(fd_set*)a); +} + +int +is_fd_set__(StgByteArray a, StgInt fd) +{ + return FD_ISSET(fd,(fd_set*)a); +} + +StgInt +selectFrom__( StgByteArray rfd + , StgByteArray wfd + , StgByteArray efd + , StgInt mFd + , StgInt tout + ) +{ + int rc, i; + struct timeval tv; + + if (tout != (-1)) { + tv.tv_sec = tout / 1000000; + tv.tv_usec = tout % 1000000; + } + + while ((rc = select(mFd, (fd_set*)rfd, (fd_set*)wfd, (fd_set*)efd, (tout == -1 ? NULL : &tv))) < 0) { + if (errno != EINTR) { + break; + } + } + return 0; +} + |