]> arthur.barton.de Git - netatalk.git/commitdiff
Use fcntl O_NONBLOCK instead of ioctl FIONBIO
authorfranklahm <franklahm>
Mon, 26 Oct 2009 12:35:56 +0000 (12:35 +0000)
committerfranklahm <franklahm>
Mon, 26 Oct 2009 12:35:56 +0000 (12:35 +0000)
include/atalk/util.h
libatalk/dsi/dsi_stream.c
libatalk/util/Makefile.am
libatalk/util/socket.c [new file with mode: 0644]

index 736fab22cd5fb1823e6e8b903001eca9c687ed3c..4e05b07e5bd25282ca97db85b8409ab7a341100a 100644 (file)
@@ -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);
index 6e62556a6ac9909874dd08dbc9ce9e9e0adba498..b3581d2709ec51a007cee5185e813f98e0ef1e30 100644 (file)
@@ -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.
 #endif
 
 #include <atalk/logger.h>
-
 #include <atalk/dsi.h>
 #include <netatalk/endian.h>
 #include <atalk/util.h>
-#include <sys/ioctl.h> 
 
 #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;
index 5ba5f2d547a60c42dc6520237c6418b682009913..d6351464f19c74c3ad3e61912e930ae62b6aafef 100644 (file)
@@ -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 (file)
index 0000000..5843d1d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+   $Id: socket.c,v 1.1 2009-10-26 12:35:56 franklahm Exp $
+   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
+
+   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 <unistd.h>
+#include <fcntl.h>
+
+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;
+}