2 * $Id: dsi_read.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5 * All rights reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
16 #endif /* HAVE_UNISTD_H */
18 #include <sys/types.h>
21 #include <atalk/dsi.h>
24 #define min(a,b) ((a) < (b) ? (a) : (b))
27 /* streaming i/o for afp_read. this is all from the perspective of the
28 * client. it basically does the reverse of dsi_write. on first entry,
29 * it will send off the header plus whatever is in its command
30 * buffer. it returns the amount of stuff still to be read
31 * (constrained by the buffer size). */
32 ssize_t dsi_readinit(DSI *dsi, void *buf, const size_t buflen,
33 const size_t size, const int err)
35 const struct itimerval none = {{0, 0}, {0, 0}};
37 dsi->noreply = 1; /* we will handle our own replies */
38 dsi->header.dsi_flags = DSIFL_REPLY;
39 /*dsi->header.dsi_command = DSIFUNC_CMD;*/
40 dsi->header.dsi_len = htonl(size);
41 dsi->header.dsi_code = htonl(err);
43 sigprocmask(SIG_BLOCK, &dsi->sigblockset, NULL);
44 setitimer(ITIMER_REAL, &none, &dsi->savetimer);
45 if (dsi_stream_send(dsi, buf, buflen)) {
46 dsi->datasize = size - buflen;
47 return min(dsi->datasize, buflen);
50 return -1; /* error */
53 void dsi_readdone(DSI *dsi)
55 setitimer(ITIMER_REAL, &dsi->savetimer, NULL);
56 sigprocmask(SIG_UNBLOCK, &dsi->sigblockset, NULL);
59 /* send off the data */
60 ssize_t dsi_read(DSI *dsi, void *buf, const size_t buflen)
62 size_t len = dsi_stream_write(dsi, buf, buflen);
66 return min(dsi->datasize, buflen);