#include "squid.h"
#include "cache_cf.h"
#include "comm.h"
+#include "comm/Connection.h"
#include "fd.h"
#include "fde.h"
+#include "globals.h"
#include "ip/Address.h"
#include "rfc1738.h"
#include "SquidConfig.h"
#include "tools.h"
#include <cerrno>
-#ifndef _MSWSOCK_
+#if HAVE_MSWSOCK_H
#include <mswsock.h>
#endif
#include <process.h>
Ip::Address PS = params->PS;
Ip::Address local_addr = params->local_addr;
- buf1 = (char *)xcalloc(1, 8192);
+ const size_t bufSz = 8192;
+ buf1 = (char *)xcalloc(1, bufSz);
strcpy(buf1, params->prog);
prog = strtok(buf1, w_space);
debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd);
comm_close(crfd);
- snprintf(buf1, 8191, "%s CHILD socket", prog);
+ snprintf(buf1, bufSz-1, "%s CHILD socket", prog);
fd_open(fd, FD_SOCKET, buf1);
fd_table[fd].flags.ipc = 1;
cwfd = crfd = fd;
}
PutEnvironment();
- memset(buf1, '\0', sizeof(buf1));
- x = recv(crfd, (void *)buf1, 8191, 0);
+ memset(buf1, '\0', bufSz);
+ x = recv(crfd, (void *)buf1, bufSz-1, 0);
if (x < 0) {
debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: OK read test failed");
}
if (type == IPC_UDP_SOCKET) {
- snprintf(buf1, 8192, "%s(%ld) <-> ipc CHILD socket", prog, -1L);
+ snprintf(buf1, bufSz, "%s(%ld) <-> ipc CHILD socket", prog, -1L);
crfd_ipc = cwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
if (crfd_ipc < 0) {
goto cleanup;
}
- snprintf(buf1, 8192, "%s(%ld) <-> ipc PARENT socket", prog, -1L);
+ snprintf(buf1, bufSz, "%s(%ld) <-> ipc PARENT socket", prog, -1L);
prfd_ipc = pwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
if (pwfd_ipc < 0) {
goto cleanup;
}
- x = read(p2c[0], buf1, 8192);
+ x = read(p2c[0], buf1, bufSz-1);
if (x < 0) {
debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: read FD " << p2c[0] << ": " << xstrerror());
goto cleanup;
}
- x = read(p2c[0], buf1, 8192);
+ x = read(p2c[0], buf1, bufSz-1);
if (x < 0) {
debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: read FD " << p2c[0] << ": " << xstrerror());
}
x = send(pwfd_ipc, (const void *)ok_string, strlen(ok_string), 0);
- x = recv(prfd_ipc, (void *)(buf1 + 200), 8191 - 200, 0);
+ x = recv(prfd_ipc, (void *)(buf1 + 200), bufSz -1 - 200, 0);
assert((size_t) x == strlen(ok_string)
&& !strncmp(ok_string, buf1 + 200, strlen(ok_string)));
} /* IPC_UDP_SOCKET */
- snprintf(buf1, 8191, "%s(%ld) CHILD socket", prog, (long int) pid);
+ snprintf(buf1, bufSz-1, "%s(%ld) CHILD socket", prog, (long int) pid);
fd_note(fd, buf1);
if (prfd_ipc != -1) {
- snprintf(buf1, 8191, "%s(%ld) <-> ipc CHILD socket", prog, (long int) pid);
+ snprintf(buf1, bufSz-1, "%s(%ld) <-> ipc CHILD socket", prog, (long int) pid);
fd_note(crfd_ipc, buf1);
- snprintf(buf1, 8191, "%s(%ld) <-> ipc PARENT socket", prog, (long int) pid);
+ snprintf(buf1, bufSz-1, "%s(%ld) <-> ipc PARENT socket", prog, (long int) pid);
fd_note(prfd_ipc, buf1);
}
goto cleanup;
}
- snprintf(buf1, 8191, "%ld\n", (long int) pid);
+ snprintf(buf1, bufSz-1, "%ld\n", (long int) pid);
if (-1 == ipcSend(cwfd, buf1, strlen(buf1)))
goto cleanup;
/* cycle */
for (;;) {
- x = recv(crfd, (void *)buf1, 8192, 0);
+ x = recv(crfd, (void *)buf1, bufSz-1, 0);
if (x <= 0) {
debugs(54, 3, "ipc(" << prog << "," << pid << "): " << x << " bytes received from parent. Exiting...");
if (!retval)
debugs(54, 2, "ipc(" << prog << "," << pid << "): normal exit");
- if (buf1)
- xfree(buf1);
-
- if (prog)
- xfree(prog);
+ xfree(buf1);
+ xfree(prog);
if (thread)
CloseHandle(thread);
int send_fd = params->send_fd;
char *prog = xstrdup(params->prog);
pid_t pid = params->pid;
- char *buf2 = (char *)xcalloc(1, 8192);
+ const size_t bufSz = 8192;
+ char *buf2 = (char *)xcalloc(1, bufSz);
for (;;) {
if (type == IPC_TCP_SOCKET)
- x = read(rfd, buf2, 8192);
+ x = read(rfd, buf2, bufSz-1);
else
- x = recv(rfd, (void *)buf2, 8192, 0);
+ x = recv(rfd, (void *)buf2, bufSz-1, 0);
if ((x <= 0 && type == IPC_TCP_SOCKET) ||
(x < 0 && type == IPC_UDP_SOCKET)) {
if (type == IPC_UDP_SOCKET && !strcmp(buf2, shutdown_string)) {
debugs(54, 3, "ipc(" << prog << "," << pid << "): request for shutdown received. Exiting...");
-
break;
}