X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Fdsi%2Fdsi_tcp.c;h=2dc5e15ddbafd72888f73d13f29db347d0ad88e1;hb=59ba70c884ca7356e28873fccab7d3611369e6cc;hp=5432525355dda0dcb9bf279570f53e44376a7988;hpb=1a16fe7e7662b6c0830dbb7a87856b0566a7ae43;p=netatalk.git diff --git a/libatalk/dsi/dsi_tcp.c b/libatalk/dsi/dsi_tcp.c index 54325253..2dc5e15d 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,44 @@ 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); +} + +/*! + * Free any allocated ressources of the master afpd DSI objects and close server socket + */ +void dsi_free(DSI *dsi) +{ + close(dsi->serversock); + dsi->serversock = -1; + + free(dsi->commands); + dsi->commands = NULL; + + free(dsi->buffer); + dsi->buffer = NULL; + + free(dsi->bonjourname); + dsi->bonjourname = NULL; +} + static struct itimerval itimer; /* accept the socket and do a little sanity checking */ static int dsi_tcp_open(DSI *dsi) @@ -119,9 +155,6 @@ static int dsi_tcp_open(DSI *dsi) uint8_t block[DSI_BLOCKSIZ]; size_t stored; - /* Immediateyl mark globally that we're a child now */ - parent_or_child = 1; - /* reset signals */ server_reset_signal(); @@ -141,6 +174,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. */ @@ -179,7 +214,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) { @@ -252,9 +287,10 @@ static void guess_interface(DSI *dsi, const char *hostname, const char *port) getip_string((struct sockaddr *)&dsi->server), port, ifr.ifr_name); goto iflist_done; } - LOG(log_info, logtype_dsi, "dsi_tcp (Chooser will not select afp/tcp) " - "Check to make sure %s is in /etc/hosts and the correct domain is in " - "/etc/resolv.conf: %s", hostname, strerror(errno)); + + LOG(log_note, logtype_dsi, "dsi_tcp: couldn't find network interface with IP address to advertice, " + "check to make sure \"%s\" is in /etc/hosts or can be resolved with DNS, or " + "add a netinterface that is not a loopback or point-2-point type", hostname); iflist_done: close(fd); @@ -270,7 +306,7 @@ iflist_done: int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const char *inport) { EC_INIT; - int flag; + int flag, err; char *a = NULL, *b; const char *address; const char *port; @@ -331,13 +367,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); @@ -380,8 +414,8 @@ int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const ch hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - if ((ret = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) { - LOG(log_info, logtype_dsi, "dsi_tcp_init: getaddrinfo '%s': %s\n", hostname, gai_strerror(ret)); + if ((err = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) { + LOG(log_info, logtype_dsi, "dsi_tcp_init: getaddrinfo '%s': %s\n", hostname, gai_strerror(err)); goto interfaces; }