3 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
4 * All rights reserved. See COPYRIGHT.
6 * 7 Oct 1997 added checks for 0 data.
11 #endif /* HAVE_CONFIG_H */
13 /* this streams writes */
16 #include <sys/types.h>
22 #include <atalk/dsi.h>
23 #include <atalk/util.h>
24 #include <atalk/logger.h>
26 size_t dsi_writeinit(DSI *dsi, void *buf, const size_t buflen _U_)
29 dsi->datasize = ntohl(dsi->header.dsi_len) - dsi->header.dsi_data.dsi_doff;
31 if (dsi->eof > dsi->start) {
32 /* We have data in the buffer */
33 bytes = MIN(dsi->eof - dsi->start, dsi->datasize);
34 memmove(buf, dsi->start, bytes);
36 dsi->datasize -= bytes;
37 if (dsi->start >= dsi->eof)
38 dsi->start = dsi->eof = dsi->buffer;
41 LOG(log_maxdebug, logtype_dsi, "dsi_writeinit: remaining DSI datasize: %jd", (intmax_t)dsi->datasize);
47 /* fill up buf and then return. this should be called repeatedly
48 * until all the data has been read. i block alarm processing
49 * during the transfer to avoid sending unnecessary tickles. */
50 size_t dsi_write(DSI *dsi, void *buf, const size_t buflen)
54 LOG(log_maxdebug, logtype_dsi, "dsi_write: remaining DSI datasize: %jd", (intmax_t)dsi->datasize);
56 if ((length = MIN(buflen, dsi->datasize)) > 0) {
57 if ((length = dsi_stream_read(dsi, buf, length)) > 0) {
58 LOG(log_maxdebug, logtype_dsi, "dsi_write: received: %ju", (intmax_t)length);
59 dsi->datasize -= length;
66 /* flush any unread buffers. */
67 void dsi_writeflush(DSI *dsi)
71 while (dsi->datasize > 0) {
72 length = dsi_stream_read(dsi, dsi->data,
73 MIN(sizeof(dsi->data), dsi->datasize));
75 dsi->datasize -= length;