]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_read.c
Fix unnamed union inside struct
[netatalk.git] / libatalk / dsi / dsi_read.c
1 /*
2  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3  * All rights reserved. See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif /* HAVE_CONFIG_H */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/time.h>
16
17 #include <atalk/dsi.h>
18 #include <atalk/util.h>
19 #include <atalk/logger.h>
20
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, const size_t size, const int err)
27 {
28     LOG(log_maxdebug, logtype_dsi, "dsi_readinit: sending %zd bytes from buffer, total size: %zd",
29         buflen, size);
30
31     dsi->flags |= DSI_NOREPLY; /* we will handle our own replies */
32     dsi->header.dsi_flags = DSIFL_REPLY;
33     dsi->header.dsi_len = htonl(size);
34     dsi->header.dsi_data.dsi_code = htonl(err);
35
36     dsi->in_write++;
37     if (dsi_stream_send(dsi, buf, buflen)) {
38         dsi->datasize = size - buflen;
39         LOG(log_maxdebug, logtype_dsi, "dsi_readinit: remaining data for sendfile: %zd", dsi->datasize);
40         return MIN(dsi->datasize, buflen);
41     }
42
43     return -1; /* error */
44 }
45
46 void dsi_readdone(DSI *dsi)
47 {
48     dsi->in_write--;
49 }
50
51 /* send off the data */
52 ssize_t dsi_read(DSI *dsi, void *buf, const size_t buflen)
53 {
54     size_t len;
55
56     len  = dsi_stream_write(dsi, buf, buflen, 0);
57
58     if (len == buflen) {
59         dsi->datasize -= len;
60         return MIN(dsi->datasize, buflen);
61     }
62
63     return -1;
64 }