X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=libatalk%2Fdsi%2Fdsi_write.c;h=1cf25e64c6516ea65e4144f63eafcd625fdb72d2;hp=8ce85c2ca547f4cff7977681b4e5e6d549f06a96;hb=8e5e83dac34cf886996821a51dee5c971e7c51f2;hpb=a4772fa50378fb23354fc515ca237d9957f77ed7 diff --git a/libatalk/dsi/dsi_write.c b/libatalk/dsi/dsi_write.c index 8ce85c2c..1cf25e64 100644 --- a/libatalk/dsi/dsi_write.c +++ b/libatalk/dsi/dsi_write.c @@ -1,5 +1,5 @@ /* - * $Id: dsi_write.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $ + * $Id: dsi_write.c,v 1.5 2009-10-20 04:31:41 didg Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * All rights reserved. See COPYRIGHT. @@ -13,52 +13,43 @@ /* this streams writes */ #include -#ifdef HAVE_UNISTD_H #include -#endif /* HAVE_UNISTD_H */ #include #include #include -#ifdef HAVE_FCNTL_H #include -#endif /* HAVE_FCNTL_H */ #include #include -#include - -#ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif /* ! MIN */ +#include +#include /* initialize relevant things for dsi_write. this returns the amount * of data in the data buffer. the interface has been reworked to allow * for arbitrary buffers. */ -size_t dsi_writeinit(DSI *dsi, void *buf, const size_t buflen) +size_t dsi_writeinit(DSI *dsi, void *buf, const size_t buflen _U_) { - const struct itimerval none = {{0, 0}, {0, 0}}; size_t len, header; /* figure out how much data we have. do a couple checks for 0 * data */ - header = ntohl(dsi->header.dsi_code); + header = ntohl(dsi->header.dsi_doff); dsi->datasize = header ? ntohl(dsi->header.dsi_len) - header : 0; + if (dsi->datasize > 0) { - len = MIN(sizeof(dsi->commands) - header, dsi->datasize); - - /* write last part of command buffer into buf */ - memcpy(buf, dsi->commands + header, len); - - /* recalculate remaining data */ - dsi->datasize -= len; + len = MIN(dsi->server_quantum - header, dsi->datasize); + + /* write last part of command buffer into buf */ + memmove(buf, dsi->commands + header, len); + + /* recalculate remaining data */ + dsi->datasize -= len; } else len = 0; - /* deal with signals. i'm doing it this way to ensure that we don't - * get confused if a writeflush on zero remaining data is, for some - * reason, needed. */ - sigprocmask(SIG_BLOCK, &dsi->sigblockset, NULL); - setitimer(ITIMER_REAL, &none, &dsi->savetimer); + LOG(log_maxdebug, logtype_dsi, "dsi_writeinit: len: %ju, remaining DSI datasize: %jd", + (intmax_t)len, (intmax_t)dsi->datasize); + return len; } @@ -69,14 +60,15 @@ size_t dsi_write(DSI *dsi, void *buf, const size_t buflen) { size_t length; - if (((length = MIN(buflen, dsi->datasize)) > 0) && - ((length = dsi_stream_read(dsi, buf, length)) > 0)) { - dsi->datasize -= length; - return length; - } + LOG(log_maxdebug, logtype_dsi, "dsi_write: remaining DSI datasize: %jd", (intmax_t)dsi->datasize); - setitimer(ITIMER_REAL, &dsi->savetimer, NULL); - sigprocmask(SIG_UNBLOCK, &dsi->sigblockset, NULL); + if ((length = MIN(buflen, dsi->datasize)) > 0) { + if ((length = dsi_stream_read(dsi, buf, length)) > 0) { + LOG(log_maxdebug, logtype_dsi, "dsi_write: received: %ju", (intmax_t)length); + dsi->datasize -= length; + return length; + } + } return 0; } @@ -93,7 +85,4 @@ void dsi_writeflush(DSI *dsi) else break; } - - setitimer(ITIMER_REAL, &dsi->savetimer, NULL); - sigprocmask(SIG_UNBLOCK, &dsi->sigblockset, NULL); }