/*
- * $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
#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
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);
/*
- * $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))
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;
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;
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
--- /dev/null
+/*
+ $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;
+}