-/* $Id: errorpage.cc,v 1.8 1996/04/01 18:21:29 wessels Exp $ */
+/* $Id: errorpage.cc,v 1.9 1996/04/02 00:51:52 wessels Exp $ */
/* DEBUG: Section 4 cached_error: Error printing routines */
{"ERR_URL_BLOCKED",
"Access Denied",
"You are not allowed to access this URL."},
+ {"ERR_ZERO_SIZE_OBJECT",
+ "No Object Data",
+ "The remote server closed the connection before sending any data."},
{"ERR_MAX"
"",
""}
-/* $Id: ftp.cc,v 1.16 1996/04/01 23:34:43 wessels Exp $ */
+/* $Id: ftp.cc,v 1.17 1996/04/02 00:51:53 wessels Exp $ */
/*
* DEBUG: Section 9 ftp: FTP
int got_marker; /* denotes end of successful request */
} FtpData;
+static void ftpCloseAndFree(fd, data)
+ int fd;
+ FtpData *data;
+{
+ if (fd > -1)
+ comm_close(fd);
+ xfree(data);
+}
+
/* XXX: this does not support FTP on a different port! */
int ftp_url_parser(url, data)
char *url;
}
safe_free(data->icp_rwd_ptr);
cached_error_entry(entry, ERR_LIFETIME_EXP, NULL);
- comm_close(fd);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
}
clen = entry->mem_obj->e_current_len;
off = entry->mem_obj->e_lowest_offset;
if ((clen - off) > FTP_DELETE_GAP) {
- debug(9, 3, "ftpReadReply: Read deferred for Object: %s\n", entry->key);
+ debug(9, 3, "ftpReadReply: Read deferred for Object: %s\n",
+ entry->url);
debug(9, 3, "--> Current Gap: %d bytes\n", clen - off);
/* reschedule, so it will automatically be reactivated when
* Gap is big enough. */
} else {
/* we can terminate connection right now */
cached_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- comm_close(fd);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
return 0;
}
}
len = read(fd, buf, READBUFSIZ);
debug(9, 5, "ftpReadReply: FD %d, Read %d bytes\n", fd, len);
- if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
- if (len < 0)
- debug(9, 1, "ftpReadReply: read error: %s\n", xstrerror());
- if (errno == ECONNRESET) {
- /* Connection reset by peer */
- /* consider it as a EOF */
- if (!(entry->flag & DELETE_BEHIND))
- entry->expires = cached_curtime + ttlSet(entry);
- sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
- storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
- storeComplete(entry);
- comm_close(fd);
- safe_free(data);
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (len < 0) {
+ debug(9, 1, "ftpReadReply: read error: %s\n", xstrerror());
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* reinstall handlers */
/* XXX This may loop forever */
comm_set_select_handler(fd, COMM_SELECT_READ,
/* note there is no ftpReadReplyTimeout. Timeouts are handled
* by `ftpget'. */
} else {
+ BIT_RESET(entry->flag, CACHABLE);
+ BIT_SET(entry->flag, RELEASE_REQUEST);
cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
- comm_close(fd);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
}
+ } else if (len == 0 && entry->mem_obj->e_current_len == 0) {
+ cached_error_entry(entry,
+ ERR_ZERO_SIZE_OBJECT,
+ errno ? xstrerror() : NULL);
+ ftpCloseAndFree(fd, data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
if (!data->got_marker) {
- /* If we didn't see the magic marker, assume the transfer failed and arrange
- * so the object gets ejected and never gets to disk. */
+ /* If we didn't see the magic marker, assume the transfer
+ * failed and arrange so the object gets ejected and
+ * never gets to disk. */
debug(9, 1, "ftpReadReply: Didn't see magic marker, purging <URL:%s>.\n", entry->url);
entry->expires = cached_curtime + getNegativeTTL();
BIT_RESET(entry->flag, CACHABLE);
entry->expires = cached_curtime + ttlSet(entry);
}
/* update fdstat and fdtable */
- comm_close(fd);
storeComplete(entry);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
} else if (((entry->mem_obj->e_current_len + len) > getFtpMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
/* append the last bit of info we get */
storeAppend(entry, buf, len);
cached_error_entry(entry, ERR_CLIENT_ABORT, NULL);
- comm_close(fd);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
} else {
/* check for a magic marker at the end of the read */
+ data->got_marker = 0;
if (len >= MAGIC_MARKER_SZ) {
if (!memcmp(MAGIC_MARKER, buf + len - MAGIC_MARKER_SZ, MAGIC_MARKER_SZ)) {
data->got_marker = 1;
if (errflag) {
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- comm_close(fd);
- safe_free(data);
+ ftpCloseAndFree(fd, data);
return;
} else {
comm_set_select_handler(data->ftp_fd,
debug(9, 5, "ftpConnInProgress: FD %d is now connected.", fd);
break; /* cool, we're connected */
default:
- comm_close(fd);
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- safe_free(data);
+ ftpCloseAndFree(fd, data);
return;
}
/* Call the real write handler, now that we're fully connected */
/* Now connect ... */
if ((status = comm_connect(data->ftp_fd, "localhost", 3131))) {
if (status != EINPROGRESS) {
- comm_close(data->ftp_fd);
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- safe_free(data);
+ ftpCloseAndFree(data->ftp_fd, data);
return COMM_ERROR;
} else {
debug(9, 5, "ftpStart: FD %d: EINPROGRESS.\n", data->ftp_fd);
-/* $Id: gopher.cc,v 1.12 1996/04/01 23:34:43 wessels Exp $ */
+/* $Id: gopher.cc,v 1.13 1996/04/02 00:51:54 wessels Exp $ */
/*
* DEBUG: Section 10 gopher: GOPHER
} conversion;
int HTML_header_added;
int port;
- char *mime_hdr;
char type_id;
char request[MAX_URL];
int data_in;
GopherData *CreateGopherData();
-static void freeGopherData _PARAMS((GopherData *));
char def_gopher_bin[] = "www/unknown";
char def_gopher_text[] = "text/plain";
+static void gopherCloseAndFree(fd, data)
+ int fd;
+ GopherData *data;
+{
+ if (fd > 0)
+ comm_close(fd);
+ put_free_4k_page(data->buf);
+ xfree(data);
+}
+
+
/* figure out content type from file extension */
static void gopher_mime_content(buf, name, def)
char *buf;
default:
cachable = 1;
}
- freeGopherData(data);
+ gopherCloseAndFree(-1, data);
return cachable;
}
put_free_4k_page(data->icp_page_ptr);
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
return 0;
}
COMM_SELECT_READ | COMM_SELECT_WRITE,
0,
0);
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
}
off = entry->mem_obj->e_lowest_offset;
if ((clen - off) > GOPHER_DELETE_GAP) {
debug(10, 3, "gopherReadReply: Read deferred for Object: %s\n",
- entry->key);
+ entry->url);
debug(10, 3, " Current Gap: %d bytes\n",
clen - off);
} else {
/* we can terminate connection right now */
cached_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
return 0;
}
}
len = read(fd, buf, TEMP_BUF_SIZE - 1); /* leave one space for \0 in gopherToHTML */
debug(10, 5, "gopherReadReply: FD %d read len=%d\n", fd, len);
- if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
- debug(10, 1, "gopherReadReply: error reading: %s\n",
- xstrerror());
- if (errno == ECONNRESET) {
- /* Connection reset by peer */
- /* consider it as a EOF */
- if (!(entry->flag & DELETE_BEHIND))
- entry->expires = cached_curtime + ttlSet(entry);
- sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
- storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
- storeComplete(entry);
- comm_close(fd);
- freeGopherData(data);
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (len < 0) {
+ debug(10, 1, "gopherReadReply: error reading: %s\n", xstrerror());
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* reinstall handlers */
/* XXX This may loop forever */
comm_set_select_handler(fd, COMM_SELECT_READ,
comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
(PF) gopherReadReplyTimeout, (caddr_t) data, getReadTimeout());
} else {
+ BIT_RESET(entry->flag, CACHABLE);
+ BIT_SET(entry->flag, RELEASE_REQUEST);
cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
}
+ } else if (len == 0 && entry->mem_obj->e_current_len == 0) {
+ cached_error_entry(entry,
+ ERR_ZERO_SIZE_OBJECT,
+ errno ? xstrerror() : NULL);
+ gopherCloseAndFree(fd, data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
/* flush the rest of data in temp buf if there is one. */
entry->expires = cached_curtime + ttlSet(entry);
BIT_RESET(entry->flag, DELAY_SENDING);
storeComplete(entry);
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
} else if (((entry->mem_obj->e_current_len + len) > getGopherMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
} else {
storeAppend(entry, buf, len);
}
- comm_set_select_handler(fd, COMM_SELECT_READ, (PF) gopherReadReply, (caddr_t) data);
- comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT, (PF) gopherReadReplyTimeout,
- (caddr_t) data, getReadTimeout());
-
+ comm_set_select_handler(fd,
+ COMM_SELECT_READ,
+ (PF) gopherReadReply,
+ (caddr_t) data);
+ comm_set_select_handler_plus_timeout(fd,
+ COMM_SELECT_TIMEOUT,
+ (PF) gopherReadReplyTimeout,
+ (caddr_t) data,
+ getReadTimeout());
} else if (entry->flag & CLIENT_ABORT_REQUEST) {
/* append the last bit of info we got */
if (data->conversion != NORMAL) {
if (data->conversion != NORMAL)
gopherEndHTML(data);
BIT_RESET(entry->flag, DELAY_SENDING);
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
} else {
if (data->conversion != NORMAL) {
gopherToHTML(data, buf, len);
} else {
storeAppend(entry, buf, len);
}
- comm_set_select_handler(fd, COMM_SELECT_READ, (PF) gopherReadReply, (caddr_t) data);
- comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT, (PF) gopherReadReplyTimeout,
- (caddr_t) data, getReadTimeout());
+ comm_set_select_handler(fd,
+ COMM_SELECT_READ,
+ (PF) gopherReadReply,
+ (caddr_t) data);
+ comm_set_select_handler_plus_timeout(fd,
+ COMM_SELECT_TIMEOUT,
+ (PF) gopherReadReplyTimeout,
+ (caddr_t) data,
+ getReadTimeout());
}
put_free_4k_page(buf);
return 0;
fd, size, errflag);
if (errflag) {
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- comm_close(fd);
- freeGopherData(data);
+ gopherCloseAndFree(fd, data);
if (buf)
put_free_4k_page(buf); /* Allocated by gopherSendRequest. */
return;
if (gopher_url_parser(url, data->host, &data->port,
&data->type_id, data->request)) {
cached_error_entry(entry, ERR_INVALID_URL, NULL);
- freeGopherData(data);
+ gopherCloseAndFree(-1, data);
return COMM_ERROR;
}
/* Create socket. */
if (sock == COMM_ERROR) {
debug(10, 4, "gopherStart: Failed because we're out of sockets.\n");
cached_error_entry(entry, ERR_NO_FDS, xstrerror());
- freeGopherData(data);
+ gopherCloseAndFree(-1, data);
return COMM_ERROR;
}
/* check if IP is already in cache. It must be.
* Otherwise, we cannot check return code for connect. */
if (!ipcache_gethostbyname(data->host)) {
debug(10, 4, "gopherStart: Called without IP entry in ipcache. OR lookup failed.\n");
- comm_close(sock);
cached_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
- freeGopherData(data);
+ gopherCloseAndFree(sock, data);
return COMM_ERROR;
}
if (((data->type_id == GOPHER_INDEX) || (data->type_id == GOPHER_CSO))
}
gopherToHTML(data, (char *) NULL, 0);
storeComplete(entry);
- freeGopherData(data);
- comm_close(sock);
+ gopherCloseAndFree(sock, data);
return COMM_OK;
}
/* Open connection. */
if ((status = comm_connect(sock, data->host, data->port)) != 0) {
if (status != EINPROGRESS) {
- comm_close(sock);
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- freeGopherData(data);
+ gopherCloseAndFree(sock, data);
return COMM_ERROR;
} else {
debug(10, 5, "startGopher: conn %d EINPROGRESS\n", sock);
gd->buf = get_free_4k_page();
return (gd);
}
-
-static void freeGopherData(gd)
- GopherData *gd;
-{
- put_free_4k_page(gd->buf);
- safe_free(gd);
-}
-/* $Id: http.cc,v 1.22 1996/04/01 23:34:44 wessels Exp $ */
+/* $Id: http.cc,v 1.23 1996/04/02 00:51:54 wessels Exp $ */
/*
* DEBUG: Section 11 http: HTTP
clen = entry->mem_obj->e_current_len;
off = entry->mem_obj->e_lowest_offset;
if ((clen - off) > HTTP_DELETE_GAP) {
- debug(11, 3, "httpReadReply: Read deferred for Object: %s\n", entry->key);
+ debug(11, 3, "httpReadReply: Read deferred for Object: %s\n",
+ entry->url);
debug(11, 3, " Current Gap: %d bytes\n", clen - off);
/* reschedule, so it will be automatically reactivated
* when Gap is big enough. */
len = read(fd, buf, READBUFSIZ);
debug(11, 5, "httpReadReply: FD %d: len %d.\n", fd, len);
- if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
- /* XXX we we should log when len==0 and current_len==0 */
+ if (len < 0) {
debug(11, 2, "httpReadReply: FD %d: read failure: %s.\n",
fd, xstrerror());
- if (errno == ECONNRESET) {
- /* Connection reset by peer, junk the object */
- /* XXX this line we add assumes HTML. Should we lose it? -DPW */
- sprintf(tmp_error_buf, "\n<p>Warning: The Remote Server sent RESET at the end of transmission.\n");
- storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
- BIT_RESET(entry->flag, CACHABLE);
- BIT_SET(entry->flag, RELEASE_REQUEST);
- storeComplete(entry);
- httpCloseAndFree(fd, data);
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* reinstall handlers */
/* XXX This may loop forever */
comm_set_select_handler(fd, COMM_SELECT_READ,
comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
(PF) httpReadReplyTimeout, (caddr_t) data, getReadTimeout());
} else {
+ BIT_RESET(entry->flag, CACHABLE);
+ BIT_SET(entry->flag, RELEASE_REQUEST);
cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
httpCloseAndFree(fd, data);
}
+ } else if (len == 0 && entry->mem_obj->e_current_len == 0) {
+ cached_error_entry(entry,
+ ERR_ZERO_SIZE_OBJECT,
+ errno ? xstrerror() : NULL);
+ httpCloseAndFree(fd, data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
storeComplete(entry);
httpCloseAndFree(fd, data);
- } else if (((entry->mem_obj->e_current_len + len) > getHttpMax()) &&
+ } else if ((entry->mem_obj->e_current_len + len) > getHttpMax() &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
storeStartDeleteBehind(entry);
-
storeAppend(entry, buf, len);
- comm_set_select_handler(fd, COMM_SELECT_READ,
- (PF) httpReadReply, (caddr_t) data);
- comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
- (PF) httpReadReplyTimeout, (caddr_t) data, getReadTimeout());
-
+ comm_set_select_handler(fd,
+ COMM_SELECT_READ,
+ (PF) httpReadReply,
+ (caddr_t) data);
+ comm_set_select_handler_plus_timeout(fd,
+ COMM_SELECT_TIMEOUT,
+ (PF) httpReadReplyTimeout,
+ (caddr_t) data,
+ getReadTimeout());
} else if (entry->flag & CLIENT_ABORT_REQUEST) {
/* append the last bit of info we get */
storeAppend(entry, buf, len);
storeAppend(entry, buf, len);
if (data->reply_hdr_state < 2)
httpProcessReplyHeader(data, buf);
- comm_set_select_handler(fd, COMM_SELECT_READ,
- (PF) httpReadReply, (caddr_t) data);
- comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
- (PF) httpReadReplyTimeout, (caddr_t) data, getReadTimeout());
+ comm_set_select_handler(fd,
+ COMM_SELECT_READ,
+ (PF) httpReadReply,
+ (caddr_t) data);
+ comm_set_select_handler_plus_timeout(fd,
+ COMM_SELECT_TIMEOUT,
+ (PF) httpReadReplyTimeout,
+ (caddr_t) data,
+ getReadTimeout());
}
}
-/* $Id: store.cc,v 1.20 1996/04/01 23:34:45 wessels Exp $ */
+/* $Id: store.cc,v 1.21 1996/04/02 00:51:55 wessels Exp $ */
/*
* DEBUG: Section 20 store
debug(25, 0, "storeChangeKey: NULL key for %s\n", e->url);
return;
}
-
if ((table_entry = hash_lookup(table, e->key)))
result = (StoreEntry *) table_entry;
if (result != e) {
debug(25, 0, "storeUnChangeKey: NULL key for %s\n", e->url);
return;
}
-
if ((table_entry = hash_lookup(table, e->key)))
E1 = (StoreEntry *) table_entry;
if (E1 != e) {
-/* $Id: wais.cc,v 1.15 1996/04/01 23:34:47 wessels Exp $ */
+/* $Id: wais.cc,v 1.16 1996/04/02 00:51:56 wessels Exp $ */
/*
* DEBUG: Section 24 wais
extern char *dns_error_message;
-int wais_url_parser(url, host, port, request)
+static void waisCloseAndFree(fd, data)
+ int fd;
+ WAISData *data;
+{
+ if (fd > 0)
+ comm_close(fd);
+ xfree(data);
+}
+
+
+static int wais_url_parser(url, host, port, request)
char *url;
char *host;
int *port;
}
/* This will be called when timeout on read. */
-void waisReadReplyTimeout(fd, data)
+static void waisReadReplyTimeout(fd, data)
int fd;
WAISData *data;
{
debug(24, 4, "waisReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url);
cached_error_entry(entry, ERR_READ_TIMEOUT, NULL);
comm_set_select_handler(fd, COMM_SELECT_READ, 0, 0);
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
}
/* This will be called when socket lifetime is expired. */
debug(24, 4, "waisLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
cached_error_entry(entry, ERR_LIFETIME_EXP, NULL);
comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0);
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
}
/* check if we want to defer reading */
if ((entry->mem_obj->e_current_len -
entry->mem_obj->e_lowest_offset) > WAIS_DELETE_GAP) {
- debug(24, 3, "waisReadReply: Read deferred for Object: %s\n", entry->key);
+ debug(24, 3, "waisReadReply: Read deferred for Object: %s\n",
+ entry->url);
debug(24, 3, " Current Gap: %d bytes\n",
entry->mem_obj->e_current_len -
entry->mem_obj->e_lowest_offset);
-
- /* reschedule, so it will automatically reactivated when Gap is big enough. */
+ /* reschedule, so it will automatically reactivated
+ * when Gap is big enough. */
comm_set_select_handler(fd,
COMM_SELECT_READ,
(PF) waisReadReply,
(caddr_t) NULL,
(time_t) 0);
#endif
- comm_set_stall(fd, getStallDelay()); /* dont try reading again for a while */
+ /* dont try reading again for a while */
+ comm_set_stall(fd, getStallDelay());
return;
}
} else {
/* we can terminate connection right now */
cached_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
return;
}
}
len = read(fd, buf, 4096);
debug(24, 5, "waisReadReply - fd: %d read len:%d\n", fd, len);
- if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
- debug(24, 1, "waisReadReply - error reading errno %d: %s\n",
- errno, xstrerror());
- if (errno == ECONNRESET) {
- /* Connection reset by peer */
- /* consider it as a EOF */
- if (!(entry->flag & DELETE_BEHIND))
- entry->expires = cached_curtime + ttlSet(entry);
- sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
- storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
- storeComplete(entry);
- comm_close(fd);
- safe_free(data);
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (len < 0) {
+ debug(24, 1, "waisReadReply: FD %d: read failure: %s.\n", xstrerror());
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* reinstall handlers */
/* XXX This may loop forever */
comm_set_select_handler(fd, COMM_SELECT_READ,
comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
(PF) waisReadReplyTimeout, (caddr_t) data, getReadTimeout());
} else {
+ BIT_RESET(entry->flag, CACHABLE);
+ BIT_SET(entry->flag, RELEASE_REQUEST);
cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
}
+ } else if (len == 0 && entry->mem_obj->e_current_len == 0) {
+ cached_error_entry(entry,
+ ERR_ZERO_SIZE_OBJECT,
+ errno ? xstrerror() : NULL);
+ waisCloseAndFree(fd, data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
entry->expires = cached_curtime;
storeComplete(entry);
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
} else if (((entry->mem_obj->e_current_len + len) > getWAISMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
storeStartDeleteBehind(entry);
-
storeAppend(entry, buf, len);
comm_set_select_handler(fd,
COMM_SELECT_READ,
fd, size, errflag);
if (errflag) {
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- comm_close(fd);
- safe_free(data);
+ waisCloseAndFree(fd, data);
} else {
/* Schedule read reply. */
comm_set_select_handler(fd,
* Otherwise, we cannot check return code for connect. */
if (!ipcache_gethostbyname(data->host)) {
debug(24, 4, "waisstart: Called without IP entry in ipcache. OR lookup failed.\n");
- comm_close(sock);
cached_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
- safe_free(data);
+ waisCloseAndFree(sock, data);
return COMM_ERROR;
}
/* Open connection. */
if ((status = comm_connect(sock, data->host, data->port))) {
if (status != EINPROGRESS) {
- comm_close(sock);
cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- safe_free(data);
+ waisCloseAndFree(sock, data);
return COMM_ERROR;
} else {
debug(24, 5, "waisStart - conn %d EINPROGRESS\n", sock);