Use the most portable POSIX-style non-blocking I/O (O_NONBLOCK) instead of

BSD-style through FIONBIO. It turns out Tru64 and probably IRIX don't support
the latter when fd is a pipe (slirp case).
This commit is contained in:
gbeauche 2006-01-24 23:46:19 +00:00
parent 064973dbc7
commit a615a4ac24
5 changed files with 43 additions and 3 deletions

View File

@ -422,6 +422,31 @@ AC_CHECK_FILE([/dev/ptc],
dnl (end of code from openssh-3.2.2p1 configure.ac)
dnl Check for systems where POSIX-style non-blocking I/O (O_NONBLOCK)
dnl doesn't work or is unimplemented. On these systems (mostly older
dnl ones), use the old BSD-style FIONBIO approach instead. [tcl.m4]
AC_CACHE_CHECK([FIONBIO vs. O_NONBLOCK for non-blocking I/O],
ac_cv_nonblocking_io, [
case "$host" in
*-*-osf*)
ac_cv_nonblocking_io=FIONBIO
;;
*-*-sunos4*)
ac_cv_nonblocking_io=FIONBIO
;;
*-*-ultrix*)
ac_cv_nonblocking_io=FIONBIO
;;
*)
ac_cv_nonblocking_io=O_NONBLOCK
;;
esac
])
if [[ "$ac_cv_nonblocking_io" = "FIONBIO" ]]; then
AC_DEFINE(USE_FIONBIO, 1, [Define if BSD-style non-blocking I/O is to be used])
fi
dnl AC_CHECK_FRAMEWORK($1=NAME, $2=INCLUDES)
AC_DEFUN([AC_CHECK_FRAMEWORK], [
AS_VAR_PUSHDEF([ac_Framework], [ac_cv_framework_$1])dnl

View File

@ -333,7 +333,20 @@ bool ether_init(void)
#endif
// Set nonblocking I/O
ioctl(fd, FIONBIO, &nonblock);
#ifdef USE_FIONBIO
if (ioctl(fd, FIONBIO, &nonblock) < 0) {
sprintf(str, GetString(STR_BLOCKING_NET_SOCKET_WARN), strerror(errno));
WarningAlert(str);
goto open_error;
}
#else
int val = fcntl(fd, F_GETFL, 0);
if (val < 0 || fcntl(fd, F_SETFL, val | O_NONBLOCK) < 0) {
sprintf(str, GetString(STR_BLOCKING_NET_SOCKET_WARN), strerror(errno));
WarningAlert(str);
goto open_error;
}
#endif
// Get Ethernet address
if (net_if_type == NET_IF_ETHERTAP) {

View File

@ -46,6 +46,7 @@ user_string_def platform_strings[] = {
{STR_TIMER_SETTIME_ERR, "Cannot start timer (%s)."},
{STR_TICK_THREAD_ERR, "Cannot create 60Hz thread (%s)."},
{STR_BLOCKING_NET_SOCKET_WARN, "Cannot set non-blocking I/O to net socket (%s). Ethernet will not be available."},
{STR_NO_SHEEP_NET_DRIVER_WARN, "Cannot open %s (%s). Ethernet will not be available."},
{STR_SHEEP_NET_ATTACH_WARN, "Cannot attach to Ethernet card (%s). Ethernet will not be available."},
{STR_TUN_TAP_CONFIG_WARN, "Cannot configure TUN/TAP device (%s). Ethernet will not be available."},

View File

@ -37,6 +37,7 @@ enum {
STR_TIMER_SETTIME_ERR,
STR_TICK_THREAD_ERR,
STR_BLOCKING_NET_SOCKET_WARN,
STR_NO_SHEEP_NET_DRIVER_WARN,
STR_SHEEP_NET_ATTACH_WARN,
STR_TUN_TAP_CONFIG_WARN,

View File

@ -821,7 +821,7 @@ void
fd_nonblock(fd)
int fd;
{
#ifdef FIONBIO
#if defined USE_FIONBIO && defined FIONBIO
int opt = 1;
ioctlsocket(fd, FIONBIO, &opt);
@ -838,7 +838,7 @@ void
fd_block(fd)
int fd;
{
#ifdef FIONBIO
#if defined USE_FIONBIO && defined FIONBIO
int opt = 0;
ioctlsocket(fd, FIONBIO, &opt);