X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Fdsi%2Fdsi_read.c;h=31ee3bdff4a9191327b808061c6979c8ae4a0dcf;hb=e450b7b95579a4a4358e499fdbf93620aa09bae2;hp=c723b3b43b878063c2ede7c1287cb8eea93589d9;hpb=ad220cd96d55445846d30b951a188ec5f9b849b2;p=netatalk.git diff --git a/libatalk/dsi/dsi_read.c b/libatalk/dsi/dsi_read.c index c723b3b4..31ee3bdf 100644 --- a/libatalk/dsi/dsi_read.c +++ b/libatalk/dsi/dsi_read.c @@ -15,51 +15,50 @@ #include #include - -#ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) -#endif /* ! min */ +#include +#include /* streaming i/o for afp_read. this is all from the perspective of the * client. it basically does the reverse of dsi_write. on first entry, * it will send off the header plus whatever is in its command * buffer. it returns the amount of stuff still to be read * (constrained by the buffer size). */ -ssize_t dsi_readinit(DSI *dsi, void *buf, const size_t buflen, - const size_t size, const int err) +ssize_t dsi_readinit(DSI *dsi, void *buf, const size_t buflen, const size_t size, const int err) { + LOG(log_maxdebug, logtype_dsi, "dsi_readinit: sending %zd bytes from buffer, total size: %zd", + buflen, size); - dsi->flags |= DSI_NOREPLY; /* we will handle our own replies */ - dsi->header.dsi_flags = DSIFL_REPLY; - /*dsi->header.dsi_command = DSIFUNC_CMD;*/ - dsi->header.dsi_len = htonl(size); - dsi->header.dsi_code = htonl(err); + dsi->flags |= DSI_NOREPLY; /* we will handle our own replies */ + dsi->header.dsi_flags = DSIFL_REPLY; + dsi->header.dsi_len = htonl(size); + dsi->header.dsi_data.dsi_code = htonl(err); - dsi->in_write++; - if (dsi_stream_send(dsi, buf, buflen)) { - dsi->datasize = size - buflen; - return min(dsi->datasize, buflen); - } + dsi->in_write++; + if (dsi_stream_send(dsi, buf, buflen)) { + dsi->datasize = size - buflen; + LOG(log_maxdebug, logtype_dsi, "dsi_readinit: remaining data for sendfile: %zd", dsi->datasize); + return MIN(dsi->datasize, buflen); + } - return -1; /* error */ + return -1; /* error */ } void dsi_readdone(DSI *dsi) { - dsi->in_write--; + dsi->in_write--; } /* send off the data */ ssize_t dsi_read(DSI *dsi, void *buf, const size_t buflen) { - size_t len; - - len = dsi_stream_write(dsi, buf, buflen, 0); + size_t len; + + len = dsi_stream_write(dsi, buf, buflen, 0); - if (len == buflen) { - dsi->datasize -= len; - return min(dsi->datasize, buflen); - } + if (len == buflen) { + dsi->datasize -= len; + return MIN(dsi->datasize, buflen); + } - return -1; + return -1; }