diff options
author | jenglish <jenglish@flightlab.com> | 2008-02-28 20:12:09 (GMT) |
---|---|---|
committer | jenglish <jenglish@flightlab.com> | 2008-02-28 20:12:09 (GMT) |
commit | 6e9187684c687eab654ee37f1d4a9aa9caff97a2 (patch) | |
tree | aa41a586696a80054db4e5e47d019b5e80c80923 /unix/tclUnixCompat.c | |
parent | 2b7f76a785b725b2cf77ee239b28c5529e92093f (diff) | |
download | tcl-6e9187684c687eab654ee37f1d4a9aa9caff97a2.zip tcl-6e9187684c687eab654ee37f1d4a9aa9caff97a2.tar.gz tcl-6e9187684c687eab654ee37f1d4a9aa9caff97a2.tar.bz2 |
Consolidate all code conditionalized on -DUSE_FIONBIO into one place.
New routine TclUnixSetBlockingMode().
Diffstat (limited to 'unix/tclUnixCompat.c')
-rw-r--r-- | unix/tclUnixCompat.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c index 40caae2..c26bef5 100644 --- a/unix/tclUnixCompat.c +++ b/unix/tclUnixCompat.c @@ -6,7 +6,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixCompat.c,v 1.13 2007/12/13 15:28:42 dgp Exp $ + * RCS: @(#) $Id: tclUnixCompat.c,v 1.14 2008/02/28 20:12:09 jenglish Exp $ * */ @@ -17,6 +17,39 @@ #include <string.h> /* + *--------------------------------------------------------------------------- + * + * TclUnixSetBlockingMode -- + * + * Set the blocking mode of a file descriptor. + * + * Results: + * + * 0 on success, -1 (with errno set) on error. + * + *--------------------------------------------------------------------------- + */ +int +TclUnixSetBlockingMode( + int fd, /* File descriptor */ + int mode) /* TCL_MODE_BLOCKING or TCL_MODE_NONBLOCKING */ +{ +#ifndef USE_FIONBIO + int flags = fcntl(fd, F_GETFL); + + if (mode == TCL_MODE_BLOCKING) { + flags &= ~O_NONBLOCK; + } else { + flags |= O_NONBLOCK; + } + return fcntl(fd, F_SETFL, flags); +#else /* USE_FIONBIO */ + int state = (mode == TCL_MODE_NONBLOCKING); + return ioctl(fd, FIONBIO, &state); +#endif /* !USE_FIONBIO */ +} + +/* * Used to pad structures at size'd boundaries * * This macro assumes that the pointer 'buffer' was created from an aligned |