/*
- * $Id: dsi_write.c,v 1.5 2009-10-20 04:31:41 didg Exp $
*
* Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
* All rights reserved. See COPYRIGHT.
#include <string.h>
#include <atalk/dsi.h>
-
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif /* ! MIN */
+#include <atalk/util.h>
+#include <atalk/logger.h>
/* initialize relevant things for dsi_write. this returns the amount
* of data in the data buffer. the interface has been reworked to allow
/* figure out how much data we have. do a couple checks for 0
* data */
- header = ntohl(dsi->header.dsi_code);
+ header = ntohl(dsi->header.dsi_doff);
dsi->datasize = header ? ntohl(dsi->header.dsi_len) - header : 0;
+
if (dsi->datasize > 0) {
- len = MIN(sizeof(dsi->commands) - header, dsi->datasize);
-
- /* write last part of command buffer into buf */
- memcpy(buf, dsi->commands + header, len);
-
- /* recalculate remaining data */
- dsi->datasize -= len;
+ len = MIN(dsi->server_quantum - header, dsi->datasize);
+
+ /* write last part of command buffer into buf */
+ memmove(buf, dsi->commands + header, len);
+
+ /* recalculate remaining data */
+ dsi->datasize -= len;
} else
len = 0;
+ LOG(log_maxdebug, logtype_dsi, "dsi_writeinit: len: %ju, remaining DSI datasize: %jd",
+ (intmax_t)len, (intmax_t)dsi->datasize);
+
return len;
}
{
size_t length;
- if (((length = MIN(buflen, dsi->datasize)) > 0) &&
- ((length = dsi_stream_read(dsi, buf, length)) > 0)) {
- dsi->datasize -= length;
- return length;
+ LOG(log_maxdebug, logtype_dsi, "dsi_write: remaining DSI datasize: %jd", (intmax_t)dsi->datasize);
+
+ if ((length = MIN(buflen, dsi->datasize)) > 0) {
+ if ((length = dsi_stream_read(dsi, buf, length)) > 0) {
+ LOG(log_maxdebug, logtype_dsi, "dsi_write: received: %ju", (intmax_t)length);
+ dsi->datasize -= length;
+ return length;
+ }
}
return 0;
}