/*
* Copyright (c) 1998 Adrian Sun (asun@zoology.washington.edu)
+ * Copyright (c) 2010,2011,2012 Frank Lahm <franklahm@googlemail.com>
* All rights reserved. See COPYRIGHT.
*
* this file provides the following functions:
#include <atalk/dsi.h>
#include <atalk/util.h>
-#define min(a,b) ((a) < (b) ? (a) : (b))
-
#ifndef MSG_MORE
#define MSG_MORE 0x8000
#endif
#define MSG_DONTWAIT 0x40
#endif
+/* Pack a DSI header in wire format */
+static void dsi_header_pack_reply(const DSI *dsi, char *buf)
+{
+ buf[0] = dsi->header.dsi_flags;
+ buf[1] = dsi->header.dsi_command;
+ memcpy(buf + 2, &dsi->header.dsi_requestID, sizeof(dsi->header.dsi_requestID));
+ memcpy(buf + 4, &dsi->header.dsi_code, sizeof(dsi->header.dsi_code));
+ memcpy(buf + 8, &dsi->header.dsi_len, sizeof(dsi->header.dsi_len));
+ memcpy(buf + 12, &dsi->header.dsi_reserved, sizeof(dsi->header.dsi_reserved));
+}
+
/*
* afpd is sleeping too much while trying to send something.
* May be there's no reader or the reader is also sleeping in write,
nbe = dsi->eof - dsi->start;
if (nbe > 0) {
- nbe = min((size_t)nbe, count);
+ nbe = MIN((size_t)nbe, count);
memcpy(buf, dsi->start, nbe);
dsi->start += nbe;
}
/* fill the buffer with 8192 bytes or until buffer is full */
- buflen = min(8192, dsi->end - dsi->eof);
+ buflen = MIN(8192, dsi->end - dsi->eof);
if (buflen > 0) {
ssize_t ret;
ret = read(dsi->socket, dsi->eof, buflen);
return written;
}
-/* Pack a DSI header in wire format */
-static void dsi_header_pack_reply(const DSI *dsi, char *buf)
-{
- buf[0] = dsi->header.dsi_flags;
- buf[1] = dsi->header.dsi_command;
- memcpy(buf + 2, &dsi->header.dsi_requestID, sizeof(dsi->header.dsi_requestID));
- memcpy(buf + 4, &dsi->header.dsi_code, sizeof(dsi->header.dsi_code));
- memcpy(buf + 8, &dsi->header.dsi_len, sizeof(dsi->header.dsi_len));
- memcpy(buf + 12, &dsi->header.dsi_reserved, sizeof(dsi->header.dsi_reserved));
-}
-
-
/* ---------------------------------
*/
#ifdef WITH_SENDFILE
if (dsi->flags & DSI_DISCONNECTED)
return 0;
- block[0] = dsi->header.dsi_flags;
- block[1] = dsi->header.dsi_command;
- memcpy(block + 2, &dsi->header.dsi_requestID,
- sizeof(dsi->header.dsi_requestID));
- memcpy(block + 4, &dsi->header.dsi_code, sizeof(dsi->header.dsi_code));
- memcpy(block + 8, &dsi->header.dsi_len, sizeof(dsi->header.dsi_len));
- memcpy(block + 12, &dsi->header.dsi_reserved,
- sizeof(dsi->header.dsi_reserved));
+ dsi_header_pack_reply(dsi, block);
if (!length) { /* just write the header */
LOG(log_maxdebug, logtype_dsi, "dsi_stream_send(%u bytes): DSI header, no data", sizeof(block));
dsi->clientID = ntohs(dsi->header.dsi_requestID);
/* make sure we don't over-write our buffers. */
- dsi->cmdlen = min(ntohl(dsi->header.dsi_len), DSI_CMDSIZ);
+ dsi->cmdlen = MIN(ntohl(dsi->header.dsi_len), DSI_CMDSIZ);
if (dsi_stream_read(dsi, dsi->commands, dsi->cmdlen) != dsi->cmdlen)
return 0;