/*
- * $Id: fork.c,v 1.51.2.2.2.4 2003-10-17 00:01:11 didg Exp $
+ * $Id: fork.c,v 1.51.2.2.2.5 2004-02-10 10:21:35 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
return ret;
}
}
-
if ( access == (OPENACC_WR | OPENACC_RD | OPENACC_DWR | OPENACC_DRD)) {
return ad_excl_lock(adp, eid);
}
-
return 0;
}
int cc, err, eid, xlate = 0;
u_int16_t ofrefnum;
u_char nlmask, nlchar;
+ int non_blocking = 0;
ibuf += 2;
memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
/* due to the nature of afp packets, we have to exit if we get
an error. we can't do this with translation on. */
-#ifdef WITH_SENDFILE
+#if 0 /* idef WITH_SENDFILE */
+ /* FIXME with OS X deadlock partial workaround we can't use sendfile */
if (!(xlate || Debug(obj) )) {
if (ad_readfile(ofork->of_ad, eid, dsi->socket, offset, dsi->datasize) < 0) {
if (errno == EINVAL || errno == ENOSYS)
afp_read_loop:
#endif
+ /* fill up our buffer. */
+ if (*rbuflen) {
+ /* set to non blocking mode */
+ non_blocking = 1;
+ dsi_block(dsi, 1);
+ }
/* fill up our buffer. */
while (*rbuflen > 0) {
cc = read_file(ofork, eid, offset, nlmask, nlchar, rbuf,rbuflen, xlate);
}
afp_read_done:
+ if (non_blocking) {
+ DSI *dsi = obj->handle;
+ /* set back to blocking mode */
+ dsi_block(dsi, 0);
+ }
ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, savereqcount,ofork->of_refnum);
return err;
char srvloc_url[512];
#endif
+ /* buffer for OSX deadlock */
+ int noblocking;
+ char *buffer;
+ char *start;
+ char *eof;
+ char *end;
+ int maxsize;
+
} DSI;
/* DSI flags */
/* server and client quanta */
#define DSI_DEFQUANT 2 /* default attention quantum size */
#define DSI_SERVQUANT_MAX 0xffffffffL /* server quantum */
-#define DSI_SERVQUANT_MIN 0x0004A2E0L /* minimum server quantum */
-#define DSI_SERVQUANT_DEF DSI_SERVQUANT_MIN /* default server quantum */
+#define DSI_SERVQUANT_MIN 32000 /* minimum server quantum */
+#define DSI_SERVQUANT_DEF 0x0004A2E0L /* default server quantum */
/* default port number */
#define DSI_AFPOVERTCP_PORT 548
extern void dsi_close __P((DSI *));
extern void dsi_sleep __P((DSI *, const int ));
+/* set, unset socket blocking mode */
+extern int dsi_block __P((DSI *, const int));
+
/* low-level stream commands -- in dsi_stream.c */
extern size_t dsi_stream_write __P((DSI *, void *, const size_t, const int mode));
extern size_t dsi_stream_read __P((DSI *, void *, const size_t));
/*
- * $Id: dsi_read.c,v 1.3.14.1 2003-10-17 00:01:14 didg Exp $
+ * $Id: dsi_read.c,v 1.3.14.2 2004-02-10 10:21:50 didg Exp $
*
* Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
* All rights reserved. See COPYRIGHT.
#include <sys/time.h>
#include <atalk/dsi.h>
+#include <sys/ioctl.h>
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
dsi->sigblocked = 0;
}
+/* */
+int dsi_block(DSI *dsi, const int mode)
+{
+#if 0
+ dsi->noblocking = mode;
+ return 0;
+#else
+ int adr = mode;
+ int ret;
+
+ ret = ioctl(dsi->socket, FIONBIO, &adr);
+ if (!ret) {
+ dsi->noblocking = mode;
+ }
+ return ret;
+#endif
+}
+
/* send off the data */
ssize_t dsi_read(DSI *dsi, void *buf, const size_t buflen)
{
/*
- * $Id: dsi_stream.c,v 1.11.6.3 2004-02-06 13:34:35 didg Exp $
+ * $Id: dsi_stream.c,v 1.11.6.4 2004-02-10 10:21:50 didg Exp $
*
* Copyright (c) 1998 Adrian Sun (asun@zoology.washington.edu)
* All rights reserved. See COPYRIGHT.
#define MSG_MORE 0x8000
#endif
-/* write raw data. return actual bytes read. checks against EINTR
+#ifndef MSG_DONTWAIT
+#define MSG_DONTWAIT 0x40
+#endif
+
+/* -------------------------
+ * we don't use a circular buffer.
+*/
+const void dsi_buffer(DSI *dsi)
+{
+ fd_set readfds, writefds;
+ int len;
+ int maxfd;
+
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
+ FD_SET( dsi->socket, &readfds);
+ FD_SET( dsi->socket, &writefds);
+ maxfd = dsi->socket +1;
+ if (select( maxfd, &readfds, &writefds, NULL, NULL) <= 0)
+ return;
+
+ if ( !FD_ISSET(dsi->socket, &readfds)) {
+ /* nothing waiting in the queue */
+ return;
+ }
+ if (!dsi->buffer) {
+ /* XXX config options */
+ dsi->maxsize = 6 * dsi->server_quantum;
+ if (!dsi->maxsize)
+ dsi->maxsize = 6 * DSI_SERVQUANT_DEF;
+ dsi->buffer = malloc(dsi->maxsize);
+ if (!dsi->buffer) {
+ /* fall back to blocking IO */
+ dsi_block(dsi, 0);
+ return;
+ }
+ dsi->start = dsi->buffer;
+ dsi->eof = dsi->buffer;
+ dsi->end = dsi->buffer + dsi->maxsize;
+ }
+ len = dsi->end - dsi->eof;
+
+ if (len <= 0) {
+ /* ouch, our buffer is full !
+ * fall back to blocking IO
+ * could block and disconnect but it's better than a cpu hog
+ */
+ dsi_block(dsi, 0);
+ return;
+ }
+
+ len = read(dsi->socket, dsi->eof, len);
+ if (len <= 0)
+ return;
+ dsi->eof += len;
+}
+
+/* ------------------------------
+ * write raw data. return actual bytes read. checks against EINTR
* aren't necessary if all of the signals have SA_RESTART
* specified. */
size_t dsi_stream_write(DSI *dsi, void *data, const size_t length, int mode)
#endif
unsigned int flags = 0;
+#if 0
+ /* XXX there's no MSG_DONTWAIT in recv ?? so we have to play with ioctl
+ */
+ if (dsi->noblocking) {
+ flags |= MSG_DONTWAIT;
+ }
+#endif
+
written = 0;
while (written < length) {
if ((-1 == (len = send(dsi->socket, (u_int8_t *) data + written,
continue;
if (len < 0) {
- LOG(log_error, logtype_default, "dsi_stream_write: %s", strerror(errno));
- break;
+ if (dsi->noblocking && errno == EAGAIN) {
+ /* non blocking mode but will block
+ * read data in input queue.
+ *
+ */
+ dsi_buffer(dsi);
+ }
+ else {
+ LOG(log_error, logtype_default, "dsi_stream_write: %s", strerror(errno));
+ break;
+ }
+ }
+ else {
+ written += len;
}
-
- written += len;
}
dsi->write_count += written;
return written;
}
+/* ---------------------------------
+*/
+static ssize_t buf_read(DSI *dsi, u_int8_t *buf, size_t count)
+{
+ ssize_t nbe = 0;
+ ssize_t ret;
+
+ if (!count)
+ return 0;
+
+ if (dsi->start) {
+ nbe = dsi->eof - dsi->start;
+
+ if (nbe > 0) {
+ nbe = min((size_t)nbe, count);
+ memcpy(buf, dsi->start, nbe);
+ dsi->start += nbe;
+
+ if (dsi->eof == dsi->start)
+ dsi->start = dsi->eof = dsi->buffer;
+
+ if (nbe == count)
+ return nbe;
+ count -= nbe;
+ buf += nbe;
+ }
+ else
+ nbe = 0;
+ }
+
+ ret = read(dsi->socket, buf, count);
+ if (ret <= 0)
+ return ret;
+
+ return ret +nbe;
+}
+
/* ---------------------------------------
* read raw data. return actual bytes read. this will wait until
* it gets length bytes
stored = 0;
while (stored < length) {
- len = read(dsi->socket, (u_int8_t *) data + stored, length - stored);
+ len = buf_read(dsi, (u_int8_t *) data + stored, length - stored);
if (len == -1 && errno == EINTR)
continue;
else if (len > 0)