Skip to content

Commit

Permalink
Comm restructure part 2 - outbound connections
Browse files Browse the repository at this point in the history
  • Loading branch information
yadij committed May 19, 2010
1 parent 45bffb5 commit cfd6652
Show file tree
Hide file tree
Showing 39 changed files with 1,075 additions and 1,041 deletions.
5 changes: 2 additions & 3 deletions src/CommCalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void
CommConnectCbParams::print(std::ostream &os) const
{
CommCommonCbParams::print(os);
os << ", " << dns;
}

/* CommIoCbParams */
Expand Down Expand Up @@ -133,7 +132,7 @@ CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
void
CommAcceptCbPtrFun::dial()
{
handler(params.fd, params.nfd, &params.details, params.flag, params.xerrno, params.data);
handler(params.fd, params.nfd, params.details, params.flag, params.xerrno, params.data);
}

void
Expand All @@ -157,7 +156,7 @@ CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
void
CommConnectCbPtrFun::dial()
{
handler(params.fd, params.dns, params.flag, params.xerrno, params.data);
handler(params.conn, params.paths, params.flag, params.xerrno, params.data);
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/CommCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#define SQUID_COMMCALLS_H

#include "comm.h"
#include "ConnectionDetail.h"
#include "DnsLookupDetails.h"
#include "comm/Connection.h"
#include "base/AsyncCall.h"
#include "base/AsyncJobCalls.h"

Expand Down Expand Up @@ -69,7 +68,7 @@ class CommAcceptCbParams: public CommCommonCbParams
void print(std::ostream &os) const;

public:
ConnectionDetail details;
Comm::Connection *details;
int nfd; // TODO: rename to fdNew or somesuch
};

Expand All @@ -84,7 +83,8 @@ class CommConnectCbParams: public CommCommonCbParams
void print(std::ostream &os) const;

public:
DnsLookupDetails dns;
Comm::Connection *conn;
Vector<Comm::Connection *> *paths;
};

// read/write (I/O) parameters
Expand Down
11 changes: 6 additions & 5 deletions src/HttpRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
*/

#include "squid.h"
#include "HttpRequest.h"
#include "acl/FilledChecklist.h"
#if ICAP_CLIENT
#include "adaptation/icap/icap_log.h"
#endif
#include "auth/UserRequest.h"
#include "DnsLookupDetails.h"
#include "HttpRequest.h"
#include "HttpHeaderRange.h"
#include "MemBuf.h"
#include "Store.h"
#if ICAP_CLIENT
#include "adaptation/icap/icap_log.h"
#endif
#include "acl/FilledChecklist.h"

HttpRequest::HttpRequest() : HttpMsg(hoRequest)
{
Expand Down
17 changes: 8 additions & 9 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ squid_SOURCES = \
ConfigOption.cc \
ConfigParser.cc \
ConfigParser.h \
ConnectionDetail.h \
debug.cc \
Debug.h \
defines.h \
Expand Down Expand Up @@ -532,7 +531,7 @@ nodist_squid_SOURCES = \

squid_LDADD = \
$(COMMON_LIBS) \
comm/libcomm-listener.la \
comm/libcomm.la \
eui/libeui.la \
icmp/libicmp.la icmp/libicmp-core.la \
log/liblog.la \
Expand Down Expand Up @@ -1234,10 +1233,10 @@ tests_testCacheManager_SOURCES = \
wordlist.cc
nodist_tests_testCacheManager_SOURCES = \
$(BUILT_SOURCES)
# comm.cc only requires comm/libcomm-listener.la until fdc_table is dead.
# comm.cc only requires comm/libcomm.la until fdc_table is dead.
tests_testCacheManager_LDADD = \
$(COMMON_LIBS) \
comm/libcomm-listener.la \
comm/libcomm.la \
icmp/libicmp.la icmp/libicmp-core.la \
log/liblog.la \
$(REPL_OBJS) \
Expand Down Expand Up @@ -1419,7 +1418,7 @@ nodist_tests_testEvent_SOURCES = \
tests_testEvent_LDADD = \
$(COMMON_LIBS) \
icmp/libicmp.la icmp/libicmp-core.la \
comm/libcomm-listener.la \
comm/libcomm.la \
log/liblog.la \
$(REPL_OBJS) \
${ADAPTATION_LIBS} \
Expand Down Expand Up @@ -1573,7 +1572,7 @@ nodist_tests_testEventLoop_SOURCES = \
tests_testEventLoop_LDADD = \
$(COMMON_LIBS) \
icmp/libicmp.la icmp/libicmp-core.la \
comm/libcomm-listener.la \
comm/libcomm.la \
log/liblog.la \
$(REPL_OBJS) \
${ADAPTATION_LIBS} \
Expand Down Expand Up @@ -1722,7 +1721,7 @@ nodist_tests_test_http_range_SOURCES = \
tests_test_http_range_LDADD = \
$(COMMON_LIBS) \
icmp/libicmp.la icmp/libicmp-core.la \
comm/libcomm-listener.la \
comm/libcomm.la \
log/liblog.la \
$(REPL_OBJS) \
${ADAPTATION_LIBS} \
Expand Down Expand Up @@ -1876,7 +1875,7 @@ nodist_tests_testHttpRequest_SOURCES = \
tests_testHttpRequest_LDADD = \
$(COMMON_LIBS) \
icmp/libicmp.la icmp/libicmp-core.la \
comm/libcomm-listener.la \
comm/libcomm.la \
log/liblog.la \
$(REPL_OBJS) \
${ADAPTATION_LIBS} \
Expand Down Expand Up @@ -2247,7 +2246,7 @@ nodist_tests_testURL_SOURCES = \
tests_testURL_LDADD = \
$(COMMON_LIBS) \
icmp/libicmp.la icmp/libicmp-core.la \
comm/libcomm-listener.la \
comm/libcomm.la \
log/liblog.la \
$(REGEXLIB) \
$(REPL_OBJS) \
Expand Down
34 changes: 32 additions & 2 deletions src/PeerSelectState.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,36 @@
#ifndef SQUID_PEERSELECTSTATE_H
#define SQUID_PEERSELECTSTATE_H

#include "Array.h"
#include "cbdata.h"
#include "PingData.h"
#include "comm/Connection.h"
#include "ip/Address.h"
#include "PingData.h"

class HttpRequest;
class StoreEntry;

typedef void PSC(Vector<Comm::Connection*> *, void *);

SQUIDCEXTERN void peerSelect(Vector<Comm::Connection*> *, HttpRequest *, StoreEntry *, PSC *, void *data);
SQUIDCEXTERN void peerSelectInit(void);

/**
* A peer which has been selected as a possible destination.
* Listed as pointers here so as to prevent duplicates being added but will
* be converted to a set of IP address path options before handing back out
* to the caller.
*
* Certain connection flags and outgoing settings will also be looked up and
* set based on the received request and peer settings before handing back.
*/
class FwdServer
{
public:
peer *_peer; /* NULL --> origin server */
hier_code code;
FwdServer *next;
};

class ps_state
{
Expand All @@ -50,7 +77,10 @@ class ps_state
int direct;
PSC *callback;
void *callback_data;
FwdServer *servers;

Vector<Comm::Connection*> *paths; ///< the callers paths array. to be filled with our final results.
FwdServer *servers; ///< temporary linked list of peers we will pass back.

/*
* Why are these Ip::Address instead of peer *? Because a
* peer structure can become invalid during the peer selection
Expand Down
55 changes: 33 additions & 22 deletions src/adaptation/icap/Xaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "squid.h"
#include "comm.h"
#include "comm/ConnectStateData.h"
#include "CommCalls.h"
#include "HttpMsg.h"
#include "adaptation/icap/Xaction.h"
Expand Down Expand Up @@ -115,32 +116,21 @@ void Adaptation::Icap::Xaction::openConnection()

disableRetries(); // we only retry pconn failures

Ip::Address outgoing;
connection = comm_open(SOCK_STREAM, 0, outgoing,
COMM_NONBLOCKING, s.cfg().uri.termedBuf());
Comm::Connection *conn = new Comm::Connection;

if (connection < 0)
dieOnConnectionFailure(); // throws

debugs(93,3, typeName << " opens connection to " << s.cfg().host << ":" << s.cfg().port);

// TODO: service bypass status may differ from that of a transaction
typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommTimeoutCbParams> TimeoutDialer;
AsyncCall::Pointer timeoutCall = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommTimedout",
TimeoutDialer(this,&Adaptation::Icap::Xaction::noteCommTimedout));

commSetTimeout(connection, TheConfig.connect_timeout(
service().cfg().bypass), timeoutCall);

typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommCloseCbParams> CloseDialer;
closer = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommClosed",
CloseDialer(this,&Adaptation::Icap::Xaction::noteCommClosed));
comm_add_close_handler(connection, closer);
// TODO: where do we get the DNS info for the ICAP server host ??
// Ip::Address will do a BLOCKING lookup if s.cfg().host is a hostname
conn->remote = s.cfg().host.termedBuf();
conn->remote.SetPort(s.cfg().port);

typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommConnectCbParams> ConnectDialer;
connector = asyncCall(93,3, "Adaptation::Icap::Xaction::noteCommConnected",
ConnectDialer(this, &Adaptation::Icap::Xaction::noteCommConnected));
commConnectStart(connection, s.cfg().host.termedBuf(), s.cfg().port, connector);

ConnectStateData *cs = new ConnectStateData(conn, connector);
cs->host = xstrdup(s.cfg().host.termedBuf());
cs->connect_timeout = TheConfig.connect_timeout(service().cfg().bypass);
cs->connect();
}

/*
Expand Down Expand Up @@ -200,14 +190,35 @@ void Adaptation::Icap::Xaction::closeConnection()
// connection with the ICAP service established
void Adaptation::Icap::Xaction::noteCommConnected(const CommConnectCbParams &io)
{
if (io.flag == COMM_TIMEOUT) {
handleCommTimedout();
return;
}

Must(connector != NULL);
connector = NULL;

if (io.flag != COMM_OK)
dieOnConnectionFailure(); // throws

fd_table[connection].noteUse(icapPconnPool);
// TODO: do we still need the timeout handler set?
// there was no mention of un-setting it on success.

// TODO: service bypass status may differ from that of a transaction
typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommTimeoutCbParams> TimeoutDialer;
AsyncCall::Pointer timeoutCall = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommTimedout",
TimeoutDialer(this,&Adaptation::Icap::Xaction::noteCommTimedout));

commSetTimeout(io.conn->fd, TheConfig.connect_timeout(service().cfg().bypass), timeoutCall);

typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommCloseCbParams> CloseDialer;
closer = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommClosed",
CloseDialer(this,&Adaptation::Icap::Xaction::noteCommClosed));
comm_add_close_handler(io.conn->fd, closer);

fd_table[io.conn->fd].noteUse(icapPconnPool);

connection = io.conn->fd; // TODO: maybe store the full Comm::Connection object
handleCommConnected();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cache_cf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ parse_peer(peer ** head)

p->icp.version = ICP_VERSION_CURRENT;

p->test_fd = -1;
p->testing_now = false;

#if USE_CACHE_DIGESTS

Expand Down
Loading

0 comments on commit cfd6652

Please sign in to comment.