From: franklahm Date: Mon, 26 Oct 2009 12:35:56 +0000 (+0000) Subject: Use fcntl O_NONBLOCK instead of ioctl FIONBIO X-Git-Tag: before-ipv6~32 X-Git-Url: https://arthur.barton.de/gitweb/?p=netatalk.git;a=commitdiff_plain;h=78820d1660d0243aa120e03ef9771bd0e914da8e Use fcntl O_NONBLOCK instead of ioctl FIONBIO --- diff --git a/include/atalk/util.h b/include/atalk/util.h index 736fab22..4e05b07e 100644 --- a/include/atalk/util.h +++ b/include/atalk/util.h @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.11 2009-10-13 22:55:37 didg Exp $ + * $Id: util.h,v 1.12 2009-10-26 12:35:56 franklahm Exp $ */ #ifndef _ATALK_UTIL_H @@ -81,30 +81,9 @@ extern void *mod_symbol (void *, const char *); #define mod_close(a) dlclose(a) #endif /* ! HAVE_DLFCN_H */ -#if 0 -/* volinfo for shell utilities */ -#define VOLINFOFILE ".volinfo" - -struct volinfo { - char *v_name; - char *v_path; - int v_flags; - int v_casefold; - char *v_cnidscheme; - char *v_dbpath; - char *v_volcodepage; - charset_t v_volcharset; - char *v_maccodepage; - charset_t v_maccharset; - int v_adouble; /* default adouble format */ - char *(*ad_path)(const char *, int); - char *v_dbd_host; - int v_dbd_port; -}; - -extern int loadvolinfo (char *path, struct volinfo *vol); -extern int vol_load_charsets ( struct volinfo *vol); -#endif /* 0 */ +/****************************************************************** + * locking.c + ******************************************************************/ /* * Function: lock_reg @@ -157,3 +136,26 @@ extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t l lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len)) #endif + +/****************************************************************** + * socket.c + ******************************************************************/ + +/* + * Function: setnonblock + * + * Purpose: set or unset non-blocking IO on a fd + * + * Arguments: + * + * fd (r) File descriptor + * cmd (r) 0: disable non-blocking IO, ie block + * <>0: enable non-blocking IO + * + * Returns: 0 on success, -1 on failure + * + * Effects: + * + * fd's file flags. + */ +extern int setnonblock(int fd, int cmd); diff --git a/libatalk/dsi/dsi_stream.c b/libatalk/dsi/dsi_stream.c index 6e62556a..b3581d27 100644 --- a/libatalk/dsi/dsi_stream.c +++ b/libatalk/dsi/dsi_stream.c @@ -1,5 +1,5 @@ /* - * $Id: dsi_stream.c,v 1.19 2009-10-25 12:09:00 didg Exp $ + * $Id: dsi_stream.c,v 1.20 2009-10-26 12:35:56 franklahm Exp $ * * Copyright (c) 1998 Adrian Sun (asun@zoology.washington.edu) * All rights reserved. See COPYRIGHT. @@ -34,11 +34,9 @@ #endif #include - #include #include #include -#include #define min(a,b) ((a) < (b) ? (a) : (b)) @@ -81,11 +79,9 @@ static int dsi_buffer(DSI *dsi) fd_set readfds, writefds; int len; int maxfd; - int adr; /* non blocking mode */ - adr = 1; - if (ioctl(dsi->socket, FIONBIO, &adr) < 0) { + if (setnonblock(dsi->socket, 1) < 0) { /* can't do it! exit without error it will sleep to death below */ LOG(log_error, logtype_default, "dsi_buffer: ioctl non blocking mode %s", strerror(errno)); return 0; @@ -126,8 +122,7 @@ static int dsi_buffer(DSI *dsi) break; } } - adr = 0; - if (ioctl(dsi->socket, FIONBIO, &adr) < 0) { + if (setnonblock(dsi->socket, 0) < 0) { /* can't do it! afpd will fail very quickly */ LOG(log_error, logtype_default, "dsi_buffer: ioctl blocking mode %s", strerror(errno)); return -1; diff --git a/libatalk/util/Makefile.am b/libatalk/util/Makefile.am index 5ba5f2d5..d6351464 100644 --- a/libatalk/util/Makefile.am +++ b/libatalk/util/Makefile.am @@ -9,17 +9,16 @@ AM_CFLAGS = -I$(top_srcdir)/sys libutil_la_SOURCES = \ atalk_addr.c \ bprint.c \ + fault.c \ getiface.c \ + locking.c \ logger.c \ module.c \ server_child.c \ server_ipc.c \ server_lock.c \ + socket.c \ strcasestr.c \ strdicasecmp.c \ strlcpy.c \ - fault.c \ - volinfo.c \ - locking.c - -# util_unicode.c + volinfo.c diff --git a/libatalk/util/socket.c b/libatalk/util/socket.c new file mode 100644 index 00000000..5843d1d6 --- /dev/null +++ b/libatalk/util/socket.c @@ -0,0 +1,41 @@ +/* + $Id: socket.c,v 1.1 2009-10-26 12:35:56 franklahm Exp $ + Copyright (c) 2009 Frank Lahm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +int setnonblock(int fd, int cmd) +{ + int ofdflags; + int fdflags; + + if ((fdflags = ofdflags = fcntl(fd, F_GETFL, 0)) == -1) + return -1; + + if (cmd) + fdflags |= O_NONBLOCK; + else + fdflags &= ~O_NONBLOCK; + + if (fdflags != ofdflags) + if (fcntl(fd, F_SETFL, fdflags) == -1) + return -1; + + return 0; +}