/*
- * $Id: comm.cc,v 1.148 1997/04/30 20:06:25 wessels Exp $
+ * $Id: comm.cc,v 1.149 1997/05/02 21:34:04 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
#define min(x,y) ((x)<(y)? (x) : (y))
#define max(a,b) ((a)>(b)? (a) : (b))
-typedef struct _RWStateData {
+struct _cwstate {
char *buf;
long size;
long offset;
- RWCB *handler;
+ CWCB *handler;
void *handler_data;
void (*free) (void *);
-} RWStateData;
+};
/* GLOBAL */
FD_ENTRY *fd_table = NULL; /* also used in disk.c */
/* STATIC */
static int commBind _PARAMS((int s, struct in_addr, u_short port));
-static int comm_cleanup_fd_entry _PARAMS((int));
#ifndef USE_POLL
static int examine_select _PARAMS((fd_set *, fd_set *));
#endif
static void checkTimeouts _PARAMS((void));
-static void Reserve_More_FDs _PARAMS((void));
static void commSetReuseAddr _PARAMS((int));
static void commSetNoLinger _PARAMS((int));
static void comm_select_incoming _PARAMS((void));
-static void RWStateCallbackAndFree _PARAMS((int fd, int code));
+static void CommWriteStateCallbackAndFree _PARAMS((int fd, int code));
#ifdef TCP_NODELAY
static void commSetTcpNoDelay _PARAMS((int));
#endif
static struct timeval zero_tv;
void
-commCancelRWHandler(int fd)
+commCancelWriteHandler(int fd)
{
- RWStateData *RWState = fd_table[fd].rwstate;
- if (RWState) {
- RWState->handler = NULL;
- RWState->handler_data = NULL;
+ CommWriteStateData *CommWriteState = fd_table[fd].rwstate;
+ if (CommWriteState) {
+ CommWriteState->handler = NULL;
+ CommWriteState->handler_data = NULL;
}
}
static void
-RWStateCallbackAndFree(int fd, int code)
+CommWriteStateCallbackAndFree(int fd, int code)
{
- RWStateData *RWState = fd_table[fd].rwstate;
- RWCB *callback = NULL;
+ CommWriteStateData *CommWriteState = fd_table[fd].rwstate;
+ CWCB *callback = NULL;
fd_table[fd].rwstate = NULL;
- if (RWState == NULL)
+ if (CommWriteState == NULL)
return;
- if (RWState->free) {
- RWState->free(RWState->buf);
- RWState->buf = NULL;
+ if (CommWriteState->free) {
+ CommWriteState->free(CommWriteState->buf);
+ CommWriteState->buf = NULL;
}
- callback = RWState->handler;
- RWState->handler = NULL;
+ callback = CommWriteState->handler;
+ CommWriteState->handler = NULL;
if (callback) {
callback(fd,
- RWState->buf,
- RWState->offset,
+ CommWriteState->buf,
+ CommWriteState->offset,
code,
- RWState->handler_data);
+ CommWriteState->handler_data);
}
- safe_free(RWState);
+ safe_free(CommWriteState);
}
/* Return the local port associated with fd. */
case ENFILE:
case EMFILE:
debug(50, 1, "comm_open: socket failure: %s\n", xstrerror());
- Reserve_More_FDs();
break;
default:
debug(50, 0, "comm_open: socket failure: %s\n", xstrerror());
return COMM_NOMESSAGE;
case ENFILE:
case EMFILE:
- Reserve_More_FDs();
return COMM_ERROR;
default:
debug(50, 1, "comm_accept: FD %d: accept failure: %s\n",
if (fd_table[fd].type == FD_FILE)
fatal_dump("comm_close: not a SOCKET");
fde->open = 0;
- RWStateCallbackAndFree(fd, COMM_ERROR);
+ CommWriteStateCallbackAndFree(fd, COMM_ERROR);
commCallCloseHandlers(fd);
fd_close(fd); /* update fdstat */
#if USE_ASYNC_IO
#endif
}
-/* use to clean up fdtable when socket is closed without
- * using comm_close */
-static int
-comm_cleanup_fd_entry(int fd)
-{
- RWStateCallbackAndFree(fd, COMM_ERROR);
- fd_close(fd);
- return 0;
-}
-
/* Send a udp datagram to specified PORT at HOST. */
int
callback = fde->timeout_handler;
fde->timeout_handler = NULL;
callback(fd, fde->timeout_data);
- } else if (fde->read_handler) {
- debug(5, 5, "checkTimeouts: FD %d: Call read handler\n", fd);
- callback = fde->read_handler;
- fde->read_handler = NULL;
- callback(fd, fde->read_data);
- } else if (fde->write_handler) {
- debug(5, 5, "checkTimeouts: FD %d: Call write handler\n", fd);
- callback = fde->write_handler;
- fde->write_handler = NULL;
- callback(fd, fde->write_data);
} else {
debug(5, 5, "checkTimeouts: FD %d: Forcing comm_close()\n", fd);
comm_close(fd);
- comm_cleanup_fd_entry(fd);
}
}
}
-/*
- * Reserve_More_FDs() called when acceopt(), open(), or socket is failing
- */
-static void
-Reserve_More_FDs(void)
-{
- if (RESERVED_FD < Squid_MaxFD - 64) {
- RESERVED_FD = RESERVED_FD + 1;
- } else if (RESERVED_FD == Squid_MaxFD - 64) {
- RESERVED_FD = RESERVED_FD + 1;
- debug(5, 0, "Don't you have a tiny open-file table size of %d\n",
- Squid_MaxFD - RESERVED_FD);
- }
-}
-
/* Write to FD. */
static void
commHandleWrite(int fd, void *data)
{
- RWStateData *state = data;
+ CommWriteStateData *state = data;
int len = 0;
int nleft;
/* We're done */
if (nleft != 0)
debug(5, 2, "commHandleWrite: FD %d: write failure: connection closed with %d bytes remaining.\n", fd, nleft);
- RWStateCallbackAndFree(fd, nleft ? COMM_ERROR : COMM_OK);
+ CommWriteStateCallbackAndFree(fd, nleft ? COMM_ERROR : COMM_OK);
} else if (len < 0) {
/* An error */
if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR) {
} else {
debug(50, 2, "commHandleWrite: FD %d: write failure: %s.\n",
fd, xstrerror());
- RWStateCallbackAndFree(fd, COMM_ERROR);
+ CommWriteStateCallbackAndFree(fd, COMM_ERROR);
}
} else {
/* A successful write, continue */
state,
0);
} else {
- RWStateCallbackAndFree(fd, COMM_OK);
+ CommWriteStateCallbackAndFree(fd, COMM_OK);
}
}
}
/* Select for Writing on FD, until SIZE bytes are sent. Call
* * HANDLER when complete. */
void
-comm_write(int fd, char *buf, int size, RWCB * handler, void *handler_data, void (*free_func) (void *))
+comm_write(int fd, char *buf, int size, CWCB * handler, void *handler_data, FREE *free_func)
{
- RWStateData *state = NULL;
-
+ CommWriteStateData *state = NULL;
debug(5, 5, "comm_write: FD %d: sz %d: hndl %p: data %p.\n",
fd, size, handler, handler_data);
-
if (fd_table[fd].rwstate) {
debug(5, 1, "WARNING: FD %d: A comm_write is already active.\n", fd);
- RWStateCallbackAndFree(fd, COMM_ERROR);
+ CommWriteStateCallbackAndFree(fd, COMM_ERROR);
}
- state = xcalloc(1, sizeof(RWStateData));
+ state = xcalloc(1, sizeof(CommWriteStateData));
state->buf = buf;
state->size = size;
state->offset = 0;
fd_table[fd].rwstate,
0);
}
-
-void
-commFreeMemory(void)
-{
- safe_free(fd_table);
-}
/*
- * $Id: disk.cc,v 1.66 1997/04/30 22:46:25 wessels Exp $
+ * $Id: disk.cc,v 1.67 1997/05/02 21:34:06 wessels Exp $
*
* DEBUG: section 6 Disk I/O Routines
* AUTHOR: Harvest Derived
typedef struct open_ctrl_t {
- void (*callback) ();
+ FOCB *callback;
void *callback_data;
char *path;
} open_ctrl_t;
/* Open a disk file. Return a file descriptor */
int
-file_open(const char *path, int (*handler) _PARAMS((void)), int mode, void (*callback) (), void *callback_data)
+file_open(const char *path, int mode, FOCB *callback, void *callback_data)
{
int fd;
open_ctrl_t *ctrlp;
/* Open file */
#if USE_ASYNC_IO
- if (callback == NULL) {
- fd = open(path, mode, 0644);
- file_open_complete(ctrlp, fd, errno);
- if (fd < 0)
- return DISK_ERROR;
- return fd;
+ if (callback != NULL) {
+ aioOpen(path, mode, 0644, file_open_complete, ctrlp);
+ return DISK_OK;
}
- aioOpen(path, mode, 0644, file_open_complete, ctrlp);
- return DISK_OK;
-#else
+#endif
fd = open(path, mode, 0644);
file_open_complete(ctrlp, fd, errno);
if (fd < 0)
return DISK_ERROR;
return fd;
-#endif
}
else
fatal_dump("fd_bytes: bad type");
}
+
+void
+fdFreeMemory(void)
+{
+ safe_free(fd_table);
+}
/*
- * $Id: send-announce.cc,v 1.33 1997/04/30 20:06:35 wessels Exp $
+ * $Id: send-announce.cc,v 1.34 1997/05/02 21:34:12 wessels Exp $
*
* DEBUG: section 27 Cache Announcer
* AUTHOR: Duane Wessels
strcat(sndbuf, tbuf);
l = strlen(sndbuf);
if ((file = Config.Announce.file)) {
- fd = file_open(file, NULL, O_RDONLY, NULL, NULL);
+ fd = file_open(file, O_RDONLY, NULL, NULL);
if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) {
fd_bytes(fd, n, FD_READ);
l += n;
/*
- * $Id: squid.h,v 1.107 1997/04/30 18:31:00 wessels Exp $
+ * $Id: squid.h,v 1.108 1997/05/02 21:34:13 wessels Exp $
*
* AUTHOR: Duane Wessels
*
typedef struct _MemObject MemObject;
typedef struct _cachemgr_passwd cachemgr_passwd;
typedef struct _fileMap fileMap;
+typedef struct _cwstate CommWriteStateData;
/* 32 bit integer compatability hack */
#if SIZEOF_INT == 4
/*
- * $Id: stat.cc,v 1.138 1997/04/30 18:31:02 wessels Exp $
+ * $Id: stat.cc,v 1.139 1997/05/02 21:34:13 wessels Exp $
*
* DEBUG: section 18 Cache Manager Statistics
* AUTHOR: Harvest Derived
storeComplete(sentry);
return;
}
- fd = file_open(obj->logfilename, NULL, O_RDONLY, NULL, NULL);
+ fd = file_open(obj->logfilename, O_RDONLY, NULL, NULL);
if (fd < 0) {
debug(50, 0, "Cannot open logfile: %s: %s\n",
obj->logfilename, xstrerror());
data = xcalloc(1, sizeof(squid_read_data_t));
data->sentry = sentry;
- data->fd = file_open(ConfigFile, NULL, O_RDONLY, NULL, NULL);
+ data->fd = file_open(ConfigFile, O_RDONLY, NULL, NULL);
storeAppendPrintf(sentry, open_bracket);
file_walk(data->fd, squidReadEndHandler, data, squidReadHandler, data);
}
obj->logfile_status = LOG_ENABLE;
/* open the logfile */
- obj->logfile_fd = file_open(obj->logfilename, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ obj->logfile_fd = file_open(obj->logfilename, O_WRONLY | O_CREAT, NULL, NULL);
if (obj->logfile_fd == DISK_ERROR) {
debug(18, 0, "Cannot open logfile: %s\n", obj->logfilename);
obj->logfile_status = LOG_DISABLE;
unlink(obj->logfilename);
/* reopen it anyway */
- obj->logfile_fd = file_open(obj->logfilename, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ obj->logfile_fd = file_open(obj->logfilename, O_WRONLY | O_CREAT, NULL, NULL);
if (obj->logfile_fd == DISK_ERROR) {
debug(18, 0, "Cannot open logfile: %s\n", obj->logfilename);
obj->logfile_status = LOG_DISABLE;
if (logfilename) {
memset(obj->logfilename, '\0', SQUID_MAXPATHLEN);
xstrncpy(obj->logfilename, logfilename, SQUID_MAXPATHLEN);
- obj->logfile_fd = file_open(obj->logfilename, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ obj->logfile_fd = file_open(obj->logfilename, O_WRONLY | O_CREAT, NULL, NULL);
if (obj->logfile_fd == DISK_ERROR) {
debug(50, 0, "%s: %s\n", obj->logfilename, xstrerror());
fatal("Cannot open logfile.");
/* Close and reopen the log. It may have been renamed "manually"
* before HUP'ing us. */
file_close(HTTPCacheInfo->logfile_fd);
- HTTPCacheInfo->logfile_fd = file_open(fname, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ HTTPCacheInfo->logfile_fd = file_open(fname, O_WRONLY | O_CREAT, NULL, NULL);
if (HTTPCacheInfo->logfile_fd == DISK_ERROR) {
debug(18, 0, "stat_rotate_log: Cannot open logfile: %s\n", fname);
HTTPCacheInfo->logfile_status = LOG_DISABLE;
/*
- * $Id: store.cc,v 1.227 1997/04/30 22:46:27 wessels Exp $
+ * $Id: store.cc,v 1.228 1997/05/02 21:34:15 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
const char *pingStatusStr[] =
{
+ "PING_NONE",
"PING_WAITING",
"PING_TIMEOUT",
- "PING_DONE",
- "PING_NONE"
+ "PING_DONE"
};
const char *storeStatusStr[] =
if (e->mem_status == NOT_IN_MEMORY && e->swap_status == SWAP_OK) {
/* object is in disk and no swapping daemon running. Bring it in. */
if (callback == NULL)
- debug(20, 0, "storeLockObject: NULL callback\n");
+ debug_trap("storeLockObject: NULL callback\n");
ctrlp = xmalloc(sizeof(lock_ctrl_t));
ctrlp->callback = callback;
ctrlp->callback_data = callback_data;
if (e->lock_count)
return (int) e->lock_count;
if (e->store_status == STORE_PENDING) {
-#ifdef COMPLAIN
debug_trap("storeUnlockObject: Someone unlocked STORE_PENDING object");
debug(20, 1, " --> Key '%s'\n", e->key);
-#endif
e->store_status = STORE_ABORTED;
}
if (storePendingNClients(e) > 0)
}
path = storeSwapFullPath(e->swap_file_number, NULL);
ctrlp->path = xstrdup(path);
- file_open(path, NULL, O_RDONLY, storeSwapInStartComplete, ctrlp);
+ file_open(path, O_RDONLY, storeSwapInStartComplete, ctrlp);
}
static void
ctrlp->swapfileno = swapfileno;
e->swap_status = SWAPPING_OUT;
file_open(swapfilename,
- NULL,
O_WRONLY | O_CREAT | O_TRUNC,
storeSwapOutStartComplete,
ctrlp);
char *abort_msg;
MemObject *mem = e->mem_obj;
- if (e->store_status != STORE_PENDING) { /* XXX remove later */
+ if (e->store_status != STORE_PENDING) {
debug_trap("storeAbort: bad store_status");
return;
- } else if (mem == NULL) { /* XXX remove later */
- debug_trap("storeAbort: null mem");
+ } else if (mem == NULL) {
+ debug_trap("storeAbort: null mem_obj");
+ return;
+ } else if (e->ping_status == PING_WAITING) {
+ debug_trap("storeAbort: ping_status == PING_WAITING");
return;
}
debug(20, 6, "storeAbort: '%s'\n", e->key);
if (strcmp((fname = Config.Log.store), "none") == 0)
storelog_fd = -1;
else
- storelog_fd = file_open(fname, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ storelog_fd = file_open(fname, O_WRONLY | O_CREAT, NULL, NULL);
if (storelog_fd < 0)
debug(20, 1, "Store logging disabled\n");
if (ncache_dirs < 1)
cln[dirn] = xstrdup(storeDirSwapLogFile(dirn, ".last-clean"));
safeunlink(new[dirn], 1);
safeunlink(cln[dirn], 1);
- fd[dirn] = open(new[dirn], O_WRONLY | O_APPEND | O_CREAT | O_TRUNC, 0644);
+ fd[dirn] = file_open(new[dirn],
+ O_WRONLY | O_CREAT | O_TRUNC,
+ NULL,
+ NULL);
if (fd[dirn] < 0) {
debug(50, 0, "storeWriteCleanLogs: %s: %s\n", new[dirn], xstrerror());
continue;
/* touch a timestamp file if we're not still validating */
for (dirn = 0; dirn < ncache_dirs; dirn++) {
if (!store_validating)
- file_close(file_open(cln[dirn], NULL,
+ file_close(file_open(cln[dirn],
O_WRONLY | O_CREAT | O_TRUNC, NULL, NULL));
safe_free(cur[dirn]);
safe_free(new[dirn]);
sprintf(to, "%s.%d", fname, 0);
rename(fname, to);
}
- storelog_fd = file_open(fname, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ storelog_fd = file_open(fname, O_WRONLY | O_CREAT, NULL, NULL);
if (storelog_fd < 0) {
debug(50, 0, "storeRotateLog: %s: %s\n", fname, xstrerror());
debug(20, 1, "Store logging disabled\n");
storeDescribeStatus(const StoreEntry * e)
{
static char buf[MAX_URL << 1];
- sprintf(buf, "mem:%13s ping:%12s store:%13s swap:%12s locks:%d %s\n",
+ sprintf(buf, "mem:%s ping:%s store:%s swap:%s locks:%d %s\n",
memStatusStr[e->mem_status],
pingStatusStr[e->ping_status],
storeStatusStr[e->store_status],
for (i = 0; i < ncache_dirs; i++) {
SD = &SwapDirs[i];
path = storeDirSwapLogFile(i, NULL);
- fd = file_open(path, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ fd = file_open(path, O_WRONLY | O_CREAT, NULL, NULL);
if (fd < 0) {
debug(50, 1, "%s: %s\n", path, xstrerror());
fatal("storeDirOpenSwapLogs: Failed to open swap log.");
if (SD->swaplog_fd >= 0)
file_close(SD->swaplog_fd);
/* open a write-only FD for the new log */
- fd = file_open(new_path, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ fd = file_open(new_path, O_WRONLY | O_CREAT, NULL, NULL);
if (fd < 0) {
debug(50, 1, "%s: %s\n", new_path, xstrerror());
fatal("storeDirOpenTmpSwapLog: Failed to open swap log.");
fatal("storeDirCloseTmpSwapLog: rename failed");
}
file_close(SD->swaplog_fd);
- fd = file_open(swaplog_path, NULL, O_WRONLY | O_CREAT, NULL, NULL);
+ fd = file_open(swaplog_path, O_WRONLY | O_CREAT, NULL, NULL);
if (fd < 0) {
debug(50, 1, "%s: %s\n", swaplog_path, xstrerror());
fatal("storeDirCloseTmpSwapLog: Failed to open swap log.");
/*
- * $Id: tools.cc,v 1.102 1997/04/30 18:31:03 wessels Exp $
+ * $Id: tools.cc,v 1.103 1997/05/02 21:34:17 wessels Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
#if PURIFY
configFreeMemory();
storeFreeMemory();
- commFreeMemory();
+ fdFreeMemory();
dnsFreeMemory();
redirectFreeMemory();
errorpageFreeMemory();
/*
- * $Id: useragent.cc,v 1.5 1997/02/26 19:46:27 wessels Exp $
+ * $Id: useragent.cc,v 1.6 1997/05/02 21:34:18 wessels Exp $
*
* DEBUG: section 40 User-Agent logging
* AUTHOR: Joe Ramey <ramey@csc.ti.com>
cache_useragent_log = NULL;
}
if (fname && strcmp(fname, "none") != 0) {
- log_fd = file_open(fname, NULL, O_WRONLY | O_CREAT | O_APPEND, NULL, NULL);
+ log_fd = file_open(fname, O_WRONLY | O_CREAT | O_APPEND, NULL, NULL);
if (log_fd < 0) {
debug(50, 0, "useragentOpenLog: %s: %s\n", fname, xstrerror());
} else if ((cache_useragent_log = fdopen(log_fd, "a")) == NULL) {
/*
- * $Id: wais.cc,v 1.68 1997/04/30 20:06:37 wessels Exp $
+ * $Id: wais.cc,v 1.69 1997/05/02 21:34:19 wessels Exp $
*
* DEBUG: section 24 WAIS Relay
* AUTHOR: Harvest Derived
} WaisStateData;
static PF waisStateFree;
-static void waisStartComplete _PARAMS((void *, int));
static PF waisTimeout;
static PF waisReadReply;
-static void waisSendComplete _PARAMS((int, char *, int, int, void *));
+static CWCB waisSendComplete;
static PF waisSendRequest;
static IPH waisConnect;
static CNCB waisConnectDone;
waisStateFree,
waisState);
commSetTimeout(fd, Config.Timeout.read, waisTimeout, waisState);
- storeLockObject(entry, waisStartComplete, waisState);
- return COMM_OK;
-}
-
-
-static void
-waisStartComplete(void *data, int status)
-{
- WaisStateData *waisState = data;
+ storeLockObject(entry, NULL, NULL);
waisState->ip_lookup_pending = 1;
ipcache_nbgethostbyname(waisState->relayhost,
waisState->fd,
waisConnect,
waisState);
+ return COMM_OK;
}
-
static void
waisConnect(int fd, const ipcache_addrs * ia, void *data)
{