/*
- * $Id: client_side.cc,v 1.626 2003/02/23 00:08:03 robertc Exp $
+ * $Id: client_side.cc,v 1.627 2003/03/02 23:13:48 hno Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
static void connMakeSpaceAvailable(ConnStateData * conn);
static void connAddContextToQueue(ConnStateData * conn, ClientSocketContext * context);
static int connGetConcurrentRequestCount(ConnStateData * conn);
-static int connReadWasError(ConnStateData * conn, comm_err_t, int size);
+static int connReadWasError(ConnStateData * conn, comm_err_t, int size, int xerrno);
static int connFinishedWithConn(ConnStateData * conn, int size);
static void connNoteUseOfBuffer(ConnStateData * conn, size_t byteCount);
static int connKeepReadingIncompleteRequest(ConnStateData * conn);
}
int
-connReadWasError(ConnStateData * conn, comm_err_t flag, int size)
+connReadWasError(ConnStateData * conn, comm_err_t flag, int size, int xerrno)
{
if (flag != COMM_OK) {
debug(50, 2) ("connReadWasError: FD %d: got flag %d\n", conn->fd, flag);
}
if (size < 0) {
- if (!ignoreErrno(errno)) {
- debug(50, 2) ("connReadWasError: FD %d: %s\n", conn->fd, xstrerror());
+ if (!ignoreErrno(xerrno)) {
+ debug(50, 2) ("connReadWasError: FD %d: %s\n", conn->fd, xstrerr(xerrno));
return 1;
} else if (conn->in.notYetUsed == 0) {
debug(50, 2) ("connReadWasError: FD %d: no data to process (%s)\n",
- conn->fd, xstrerror());
+ conn->fd, xstrerr(xerrno));
}
}
* whole, not individual read() calls. Plus, it breaks our
* lame half-close detection
*/
- if (connReadWasError(conn, flag, size)) {
+ if (connReadWasError(conn, flag, size, xerrno)) {
comm_close(fd);
return;
}
/* XXX we're not considering httpAcceptDefer yet! */
if (flag != COMM_OK) {
- errno = xerrno;
debug(50, 1) ("httpAccept: FD %d: accept failure: %s\n",
- sock, xstrerror());
+ sock, xstrerr(xerrno));
return;
}
if (flag != COMM_OK) {
errno = xerrno;
debug(50, 1) ("httpsAccept: FD %d: accept failure: %s\n",
- sock, xstrerror());
+ sock, xstrerr(xerrno));
return;
}
/*
- * $Id: comm.cc,v 1.366 2003/02/21 22:50:07 robertc Exp $
+ * $Id: comm.cc,v 1.367 2003/03/02 23:13:49 hno Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
static PF commConnectHandle;
static PF commHandleWrite;
static IPH commConnectDnsHandle;
-static void commConnectCallback(ConnectStateData * cs, comm_err_t status);
+static void commConnectCallback(ConnectStateData * cs, comm_err_t status, int xerrno);
static int commResetFD(ConnectStateData * cs);
static int commRetryConnect(ConnectStateData * cs);
CBDATA_TYPE(ConnectStateData);
* Queue a callback
*/
static void
-comm_read_callback(int fd, int retval, comm_err_t errcode, int xerrno)
+comm_read_callback(int fd, size_t retval, comm_err_t errcode, int xerrno)
{
fdc_t *Fc = &fdc_table[fd];
if (retval < 0 && !ignoreErrno(errno)) {
debug(5, 3) ("comm_read_try: scheduling COMM_ERROR\n");
- comm_read_callback(fd, -1, COMM_ERROR, errno);
+ comm_read_callback(fd, 0, COMM_ERROR, errno);
return;
};
}
assert(dns_error_message != NULL);
- commConnectCallback(cs, COMM_ERR_DNS);
+ commConnectCallback(cs, COMM_ERR_DNS, 0);
return;
}
}
static void
-commConnectCallback(ConnectStateData * cs, comm_err_t status)
+commConnectCallback(ConnectStateData * cs, comm_err_t status, int xerrno)
{
CNCB *callback = cs->callback;
void *cbdata = cs->data;
commConnectFree(fd, cs);
if (cbdataReferenceValid(cbdata))
- callback(fd, status, cbdata);
+ callback(fd, status, xerrno, cbdata);
cbdataReferenceDone(cbdata);
}
case COMM_OK:
ipcacheMarkGoodAddr(cs->host, cs->S.sin_addr);
- commConnectCallback(cs, COMM_OK);
+ commConnectCallback(cs, COMM_OK, 0);
break;
default:
cs->locks++;
ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs);
} else {
- commConnectCallback(cs, COMM_ERR_CONNECT);
+ commConnectCallback(cs, COMM_ERR_CONNECT, errno);
}
break;
/*
- * $Id: ftp.cc,v 1.343 2003/02/23 00:08:04 robertc Exp $
+ * $Id: ftp.cc,v 1.344 2003/03/02 23:13:49 hno Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
static PF ftpStateFree;
static PF ftpTimeout;
static IOCB ftpReadControlReply;
-static CWCB ftpWriteCommandCallback;
+static IOWCB ftpWriteCommandCallback;
static void ftpLoginParser(const char *, FtpStateData *, int escaped);
static wordlist *ftpParseControlReply(char *, size_t, int *, int *);
static int ftpRestartable(FtpStateData * ftpState);
static void ftpScheduleReadControlReply(FtpStateData *, int);
static void ftpHandleControlReply(FtpStateData *);
static char *ftpHtmlifyListEntry(const char *line, FtpStateData * ftpState);
-static void ftpFailed(FtpStateData *, err_type);
-static void ftpFailedErrorMessage(FtpStateData *, err_type);
+static void ftpFailed(FtpStateData *, err_type, int xerrno);
+static void ftpFailedErrorMessage(FtpStateData *, err_type, int xerrno);
/*
* State machine functions
debug(9, 1) ("ftpTimeout: timeout in SENT_PASV state\n");
}
- ftpFailed(ftpState, ERR_READ_TIMEOUT);
+ ftpFailed(ftpState, ERR_READ_TIMEOUT, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
}
}
if (flag != COMM_OK || len < 0) {
- debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpDataRead: read error: %s\n", xstrerror());
+ debug(50, ignoreErrno(xerrno) ? 3 : 1) ("ftpDataRead: read error: %s\n", xstrerr(xerrno));
- if (ignoreErrno(errno)) {
+ if (ignoreErrno(xerrno)) {
/* XXX what about Config.Timeout.read? */
read_sz = ftpState->data.size - ftpState->data.offset;
#if DELAY_POOLS
comm_read(fd, ftpState->data.buf + ftpState->data.offset, read_sz, ftpDataRead, data);
} else {
- ftpFailed(ftpState, ERR_READ_ERROR);
+ ftpFailed(ftpState, ERR_READ_ERROR, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
safe_free(ftpState->ctrl.last_command);
safe_free(ftpState->ctrl.last_reply);
ftpState->ctrl.last_command = xstrdup(buf);
- comm_old_write(ftpState->ctrl.fd,
- xstrdup(buf),
- strlen(buf),
- ftpWriteCommandCallback,
- ftpState,
- xfree);
+ comm_write(ftpState->ctrl.fd,
+ xstrdup(buf),
+ strlen(buf),
+ ftpWriteCommandCallback,
+ ftpState);
ftpScheduleReadControlReply(ftpState, 0);
}
static void
-ftpWriteCommandCallback(int fd, char *bufnotused, size_t size, comm_err_t errflag, void *data)
+ftpWriteCommandCallback(int fd, char *buf, size_t size, comm_err_t errflag, int xerrno, void *data)
{
FtpStateData *ftpState = (FtpStateData *)data;
+ xfree(buf);
debug(9, 7) ("ftpWriteCommandCallback: wrote %d bytes\n", (int) size);
if (size > 0) {
return;
if (errflag) {
- debug(9, 1) ("ftpWriteCommandCallback: FD %d: %s\n", fd, xstrerror());
- ftpFailed(ftpState, ERR_WRITE_ERROR);
+ debug(9, 1) ("ftpWriteCommandCallback: FD %d: %s\n", fd, xstrerr(xerrno));
+ ftpFailed(ftpState, ERR_WRITE_ERROR, xerrno);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
debug(9, 5) ("ftpReadControlReply: FD %d, Read %d bytes\n", fd, (int)len);
if (flag != COMM_OK || len < 0) {
- debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpReadControlReply: read error: %s\n", xstrerror());
+ debug(50, ignoreErrno(xerrno) ? 3 : 1) ("ftpReadControlReply: read error: %s\n", xstrerr(xerrno));
- if (ignoreErrno(errno)) {
+ if (ignoreErrno(xerrno)) {
ftpScheduleReadControlReply(ftpState, 0);
} else {
- ftpFailed(ftpState, ERR_READ_ERROR);
+ ftpFailed(ftpState, ERR_READ_ERROR, xerrno);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
if (len == 0) {
if (entry->store_status == STORE_PENDING) {
- ftpFailed(ftpState, ERR_FTP_FAILURE);
+ ftpFailed(ftpState, ERR_FTP_FAILURE, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
}
static void
-ftpPasvCallback(int fd, comm_err_t status, void *data)
+ftpPasvCallback(int fd, comm_err_t status, int xerrno, void *data)
{
FtpStateData *ftpState = (FtpStateData *)data;
debug(9, 3) ("ftpPasvCallback\n");
debug(9, 2) ("ftpPasvCallback: failed to connect. Retrying without PASV.\n");
ftpState->fwd->flags.dont_retry = 0; /* this is a retryable error */
ftpState->fwd->flags.ftp_pasv_failed = 1;
- ftpFailed(ftpState, ERR_NONE);
+ ftpFailed(ftpState, ERR_NONE, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
}
if (flag != COMM_OK) {
- errno = xerrno;
- debug(9, 1) ("ftpHandleDataAccept: comm_accept(%d): %s", newfd, xstrerror());
+ debug(9, 1) ("ftpHandleDataAccept: comm_accept(%d): %s", newfd, xstrerr(xerrno));
/* XXX Need to set error message */
ftpFail(ftpState);
return;
} else { /* != 226 */
debug(9, 1) ("ftpReadTransferDone: Got code %d after reading data\n",
code);
- ftpFailed(ftpState, ERR_FTP_FAILURE);
+ ftpFailed(ftpState, ERR_FTP_FAILURE, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
return;
}
} else if (size < 0) {
/* Error */
debug(9, 1) ("ftpRequestBody: request aborted");
- ftpFailed(ftpState, ERR_READ_ERROR);
+ ftpFailed(ftpState, ERR_READ_ERROR, 0);
} else if (size == 0) {
/* End of transfer */
ftpDataComplete(ftpState);
/* Shedule the rest of the request */
clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState);
} else {
- debug(9, 1) ("ftpDataWriteCallback: write error: %s\n", xstrerror());
- ftpFailed(ftpState, ERR_WRITE_ERROR);
+ debug(9, 1) ("ftpDataWriteCallback: write error: %s\n", xstrerr(xerrno));
+ ftpFailed(ftpState, ERR_WRITE_ERROR, xerrno);
}
}
if (code != 226) {
debug(9, 1) ("ftpReadTransferDone: Got code %d after sending data\n",
code);
- ftpFailed(ftpState, ERR_FTP_PUT_ERROR);
+ ftpFailed(ftpState, ERR_FTP_PUT_ERROR, 0);
return;
}
}
}
- ftpFailed(ftpState, ERR_NONE);
+ ftpFailed(ftpState, ERR_NONE, 0);
/* ftpFailed closes ctrl.fd and frees ftpState */
}
static void
-ftpFailed(FtpStateData * ftpState, err_type error)
+ftpFailed(FtpStateData * ftpState, err_type error, int xerrno)
{
StoreEntry *entry = ftpState->entry;
if (entry->isEmpty())
- ftpFailedErrorMessage(ftpState, error);
+ ftpFailedErrorMessage(ftpState, error, xerrno);
if (ftpState->data.fd > -1) {
comm_close(ftpState->data.fd);
}
static void
-ftpFailedErrorMessage(FtpStateData * ftpState, err_type error)
+ftpFailedErrorMessage(FtpStateData * ftpState, err_type error, int xerrno)
{
ErrorState *err;
const char *command, *reply;
if (err == NULL)
err = errorCon(ERR_FTP_FAILURE, HTTP_BAD_GATEWAY);
- err->xerrno = errno;
+ err->xerrno = xerrno;
err->request = requestLink(ftpState->request);