/* CommCommonCbParams */
CommCommonCbParams::CommCommonCbParams(void *aData):
- data(cbdataReference(aData)), fd(-1), xerrno(0), flag(COMM_OK)
+ data(cbdataReference(aData)), conn(), flag(COMM_OK), xerrno(0), fd(-1)
{
}
CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
- data(cbdataReference(p.data)), fd(p.fd), xerrno(p.xerrno), flag(p.flag)
+ data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
{
}
public:
void *data; // cbdata-protected
+
+ /** The connection which this call pertains to.
+ * \itemize On accept() calls this is the new client connection.
+ * \itemize On connect() finished calls this is the newely opened connection.
+ * \itemize On write calls this is the connection just written to.
+ * \itemize On read calls this is the connection just read from.
+ * \itemize On close calls this describes the connection which is now closed.
+ * \itemize On timeouts this is the connection whose operation timed out.
+ * NP: timeouts should now return to the connect/read/write handler with COMM_ERR_TIMEOUT.
+ */
Comm::ConnectionPointer conn;
- int fd; // raw FD from legacy calls. use conn instead.
- int xerrno;
- comm_err_t flag;
+ comm_err_t flag; ///< comm layer result status.
+ int xerrno; ///< The last errno to occur. non-zero if flag is COMM_ERR.
+
+ int fd; // raw FD which the call was about. use conn instead for new code.
private:
// should not be needed and not yet implemented
CommCommonCbParams &operator =(const CommCommonCbParams ¶ms);
#include "squid.h"
#include "comm.h"
#include "CommCalls.h"
+#include "comm/forward.h"
#include "CbDataList.h"
class CommRead
{
public:
- CommRead ();
- CommRead (int fd, char *buf, int len, AsyncCall::Pointer &callback);
- int fd;
+ CommRead();
+ CommRead(const Comm::ConnectionPointer &c, char *buf, int len, AsyncCall::Pointer &callback);
+ Comm::ConnectionPointer conn;
char *buf;
int len;
AsyncCall::Pointer callback;
*/
#include "squid.h"
+#include "comm/Connection.h"
#include "MemObject.h"
#include "HttpRequest.h"
#include "HttpReply.h"
#include "Range.h"
#include "RefCount.h"
#include "CommRead.h"
+#include "comm/forward.h"
#include "Packer.h"
#include "RemovalPolicy.h"
void destroyMemObject();
int checkTooSmall();
- void delayAwareRead(int fd, char *buf, int len, AsyncCall::Pointer callback);
+ void delayAwareRead(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer callback);
void setNoDelay (bool const);
bool modifiedSince(HttpRequest * request) const;
}
-CommRead::CommRead() : fd(-1), buf(NULL), len(0), callback(NULL) {}
+CommRead::CommRead() : conn(NULL), buf(NULL), len(0), callback(NULL) {}
-CommRead::CommRead(int fd_, char *buf_, int len_, AsyncCall::Pointer &callback_)
- : fd(fd_), buf(buf_), len(len_), callback(callback_) {}
+CommRead::CommRead(const Comm::ConnectionPointer &c, char *buf_, int len_, AsyncCall::Pointer &callback_)
+ : conn(c), buf(buf_), len(len_), callback(callback_) {}
DeferredRead::DeferredRead () : theReader(NULL), theContext(NULL), theRead(), cancelled(false) {}
void
DeferredReadManager::delayRead(DeferredRead const &aRead)
{
- debugs(5, 3, "Adding deferred read on FD " << aRead.theRead.fd);
+ debugs(5, 3, "Adding deferred read on " << aRead.theRead.conn);
CbDataList<DeferredRead> *temp = deferredReads.push_back(aRead);
// We have to use a global function as a closer and point to temp
AsyncCall::Pointer closer = commCbCall(5,4,
"DeferredReadManager::CloseHandler",
CommCloseCbPtrFun(&CloseHandler, temp));
- comm_add_close_handler(aRead.theRead.fd, closer);
+ comm_add_close_handler(aRead.theRead.conn->fd, closer);
temp->element.closer = closer; // remeber so that we can cancel
}
DeferredRead &read = deferredReads.head->element;
if (!read.cancelled) {
- comm_remove_close_handler(read.theRead.fd, read.closer);
+ comm_remove_close_handler(read.theRead.conn->fd, read.closer);
read.closer = NULL;
}
if (aRead.cancelled)
return;
- if (aRead.theRead.fd>=0 && fd_table[aRead.theRead.fd].closing())
+ if (Comm::IsConnOpen(aRead.theRead.conn) && fd_table[aRead.theRead.conn->fd].closing())
return;
- debugs(5, 3, "Kicking deferred read on FD " << aRead.theRead.fd);
+ debugs(5, 3, "Kicking deferred read on " << aRead.theRead.conn);
aRead.theReader(aRead.theContext, aRead.theRead);
}
static int64_t lost_conn = 0;
Comm::Connection::~Connection()
{
+ assert(fd < 0); // These should never occur now.
+
if (fd >= 0) {
debugs(5, 0, "NOTE: Orphan Comm::Connection: " << *this);
debugs(5, 0, "NOTE: Orphaned Comm::Connections: " << ++lost_conn);
debugs(9,5,HERE << "queueing read on FD " << data.conn->fd);
typedef CommCbMemFunT<FtpStateData, CommIoCbParams> Dialer;
- entry->delayAwareRead(data.conn->fd, data.readBuf->space(), read_sz,
+ entry->delayAwareRead(data.conn, data.readBuf->space(), read_sz,
JobCallback(9, 5, Dialer, this, FtpStateData::dataRead));
}
/* Schedule read reply. */
AsyncCall::Pointer call = commCbCall(10,5, "gopherReadReply",
CommIoCbPtrFun(gopherReadReply, gopherState));
- entry->delayAwareRead(conn->fd, gopherState->replybuf, BUFSIZ, call);
+ entry->delayAwareRead(conn, gopherState->replybuf, BUFSIZ, call);
if (buf)
memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */
flags.do_next_read = 0;
- debugs(11, 5, "httpReadReply: FD " << io.fd << ": len " << len << ".");
+ debugs(11, 5, HERE << io.conn << ": len " << len << ".");
// Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us
if (io.flag == COMM_ERR_CLOSING) {
// handle I/O errors
if (io.flag != COMM_OK || len < 0) {
- debugs(11, 2, "httpReadReply: FD " << io.fd << ": read failure: " << xstrerror() << ".");
+ debugs(11, 2, HERE << io.conn << ": read failure: " << xstrerror() << ".");
if (ignoreErrno(io.xerrno)) {
flags.do_next_read = 1;
} else
switch (persistentConnStatus()) {
case INCOMPLETE_MSG:
- debugs(11, 5, "processReplyBody: INCOMPLETE_MSG");
+ debugs(11, 5, "processReplyBody: INCOMPLETE_MSG from " << serverConnection);
/* Wait for more data or EOF condition */
if (flags.keepalive_broken) {
call = NULL;
break;
case COMPLETE_PERSISTENT_MSG:
- debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG");
+ debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG from " << serverConnection);
/* yes we have to clear all these! */
call = NULL;
commSetTimeout(serverConnection->fd, -1, call);
}
serverConnection = NULL;
-
serverComplete();
return;
case COMPLETE_NONPERSISTENT_MSG:
- debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG");
+ debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG from " << serverConnection);
serverComplete();
return;
}
if (flags.do_next_read) {
flags.do_next_read = 0;
typedef CommCbMemFunT<HttpStateData, CommIoCbParams> Dialer;
- entry->delayAwareRead(serverConnection->fd, readBuf->space(read_size), read_size,
+ entry->delayAwareRead(serverConnection, readBuf->space(read_size), read_size,
JobCallback(11, 5, Dialer, this, HttpStateData::readReply));
}
}
StoreEntry::DeferReader(void *theContext, CommRead const &aRead)
{
StoreEntry *anEntry = (StoreEntry *)theContext;
- anEntry->delayAwareRead(aRead.fd,
+ anEntry->delayAwareRead(aRead.conn,
aRead.buf,
aRead.len,
aRead.callback);
}
void
-StoreEntry::delayAwareRead(int fd, char *buf, int len, AsyncCall::Pointer callback)
+StoreEntry::delayAwareRead(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer callback)
{
size_t amountToRead = bytesWanted(Range<size_t>(0, len));
/* sketch: readdeferer* = getdeferer.
#if USE_DELAY_POOLS
if (!mem_obj->readAheadPolicyCanRead()) {
#endif
- mem_obj->delayRead(DeferredRead(DeferReader, this, CommRead(fd, buf, len, callback)));
+ mem_obj->delayRead(DeferredRead(DeferReader, this, CommRead(conn, buf, len, callback)));
return;
#if USE_DELAY_POOLS
}
/* delay id limit */
- mem_obj->mostBytesAllowed().delayRead(DeferredRead(DeferReader, this, CommRead(fd, buf, len, callback)));
-
+ mem_obj->mostBytesAllowed().delayRead(DeferredRead(DeferReader, this, CommRead(conn, buf, len, callback)));
return;
-
#endif
-
}
- Comm::ConnectionPointer temp = new Comm::Connection; // XXX: transition. until conn passed in.
- temp->fd = fd;
- comm_read(temp, buf, amountToRead, callback);
+ comm_read(conn, buf, amountToRead, callback);
}
size_t