X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=libatalk%2Fdsi%2Fdsi_tcp.c;h=e06e87d92420187948611b9d044995ab158065c6;hp=6e7ac97431735d3bceb3392a1674ce296892b790;hb=8e5e83dac34cf886996821a51dee5c971e7c51f2;hpb=cf3e505e21e9c7ffba3a048ced9b772be8301e98 diff --git a/libatalk/dsi/dsi_tcp.c b/libatalk/dsi/dsi_tcp.c index 6e7ac974..e06e87d9 100644 --- a/libatalk/dsi/dsi_tcp.c +++ b/libatalk/dsi/dsi_tcp.c @@ -10,8 +10,6 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#define USE_TCP_NODELAY - #include #include #include @@ -85,6 +83,26 @@ static void timeout_handler(int sig _U_) exit(EXITERR_CLNT); } +/*! + * Allocate DSI read buffer and read-ahead buffer + */ +static void dsi_init_buffer(DSI *dsi) +{ + if ((dsi->commands = malloc(dsi->server_quantum)) == NULL) { + LOG(log_error, logtype_dsi, "dsi_init_buffer: OOM"); + AFP_PANIC("OOM in dsi_init_buffer"); + } + + /* dsi_peek() read ahead buffer, default is 12 * 300k = 3,6 MB (Apr 2011) */ + if ((dsi->buffer = malloc(dsi->dsireadbuf * dsi->server_quantum)) == NULL) { + LOG(log_error, logtype_dsi, "dsi_init_buffer: OOM"); + AFP_PANIC("OOM in dsi_init_buffer"); + } + dsi->start = dsi->buffer; + dsi->eof = dsi->buffer; + dsi->end = dsi->buffer + (dsi->dsireadbuf * dsi->server_quantum); +} + static struct itimerval itimer; /* accept the socket and do a little sanity checking */ static int dsi_tcp_open(DSI *dsi) @@ -138,6 +156,8 @@ static int dsi_tcp_open(DSI *dsi) } #endif + dsi_init_buffer(dsi); + /* read in commands. this is similar to dsi_receive except * for the fact that we do some sanity checking to prevent * delinquent connections from causing mischief. */ @@ -176,7 +196,7 @@ static int dsi_tcp_open(DSI *dsi) dsi->clientID = ntohs(dsi->header.dsi_requestID); /* make sure we don't over-write our buffers. */ - dsi->cmdlen = min(ntohl(dsi->header.dsi_len), DSI_CMDSIZ); + dsi->cmdlen = min(ntohl(dsi->header.dsi_len), dsi->server_quantum); stored = 0; while (stored < dsi->cmdlen) { @@ -329,13 +349,11 @@ int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const ch setsockopt(dsi->serversock, IPPROTO_IPV6, IPV6_BINDV6ONLY, (char *)&on, sizeof (on)); #endif -#ifdef USE_TCP_NODELAY #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP #endif flag = 1; setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag)); -#endif /* USE_TCP_NODELAY */ if (bind(dsi->serversock, p->ai_addr, p->ai_addrlen) == -1) { close(dsi->serversock);