2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3 * All rights reserved. See COPYRIGHT.
8 #endif /* HAVE_CONFIG_H */
14 #include <sys/types.h>
17 #include <atalk/dsi.h>
18 #include <atalk/util.h>
19 #include <atalk/logger.h>
21 /* streaming i/o for afp_read. this is all from the perspective of the
22 * client. it basically does the reverse of dsi_write. on first entry,
23 * it will send off the header plus whatever is in its command
24 * buffer. it returns the amount of stuff still to be read
25 * (constrained by the buffer size). */
26 ssize_t dsi_readinit(DSI *dsi, void *buf, const size_t buflen,
27 const size_t size, const int err)
29 LOG(log_maxdebug, logtype_dsi, "dsi_readinit: sending %zd bytes from buffer, total size: %zd",
32 dsi->flags |= DSI_NOREPLY; /* we will handle our own replies */
33 dsi->header.dsi_flags = DSIFL_REPLY;
34 dsi->header.dsi_len = htonl(size);
35 dsi->header.dsi_code = htonl(err);
38 if (dsi_stream_send(dsi, buf, buflen)) {
39 dsi->datasize = size - buflen;
40 LOG(log_maxdebug, logtype_dsi, "dsi_readinit: remaining data for sendfile: %zd", dsi->datasize);
41 return MIN(dsi->datasize, buflen);
44 return -1; /* error */
47 void dsi_readdone(DSI *dsi)
52 /* send off the data */
53 ssize_t dsi_read(DSI *dsi, void *buf, const size_t buflen)
57 len = dsi_stream_write(dsi, buf, buflen, 0);
61 return MIN(dsi->datasize, buflen);