public:
typedef void (*Handler)(int fd, int errNo, http_port_list *portCfg);
ListeningStartedDialer(Handler aHandler, http_port_list *aPortCfg):
- handler(aHandler), portCfg(aPortCfg) {}
+ handler(aHandler), portCfg(aPortCfg) {}
- virtual void print(std::ostream &os) const { startPrint(os) <<
- ", port=" << (void*)portCfg << ')'; }
+ virtual void print(std::ostream &os) const {
+ startPrint(os) <<
+ ", port=" << (void*)portCfg << ')';
+ }
virtual bool canDial(AsyncCall &) const { return true; }
virtual void dial(AsyncCall &) { (handler)(fd, errNo, portCfg); }
/* AYJ: 2009-12-27: bit bumpy. new ListenStateData(...) should be doing all the Comm:: stuff ... */
const int openFlags = COMM_NONBLOCKING |
- (s->spoof_client_ip ? COMM_TRANSPARENT : 0);
+ (s->spoof_client_ip ? COMM_TRANSPARENT : 0);
AsyncCall::Pointer callback = asyncCall(33,2,
- "clientHttpConnectionOpened",
- ListeningStartedDialer(&clientHttpConnectionOpened, s));
+ "clientHttpConnectionOpened",
+ ListeningStartedDialer(&clientHttpConnectionOpened, s));
Ipc::StartListening(SOCK_STREAM, IPPROTO_TCP, s->s, openFlags,
- Ipc::fdnHttpSocket, callback);
+ Ipc::fdnHttpSocket, callback);
HttpSockets[NHttpSockets++] = -1; // set in clientHttpConnectionOpened
}
Must(s);
- AsyncCall::Pointer call = commCbCall(5,5, "SomeCommAcceptHandler(httpAccept)",
- CommAcceptCbPtrFun(httpAccept, s));
+ AsyncCall::Pointer call = commCbCall(5,5, "SomeCommAcceptHandler(httpAccept)",
+ CommAcceptCbPtrFun(httpAccept, s));
- s->listener = new Comm::ListenStateData(fd, call, true);
+ s->listener = new Comm::ListenStateData(fd, call, true);
- debugs(1, 1, "Accepting " <<
- (s->intercepted ? " intercepted" : "") <<
- (s->spoof_client_ip ? " spoofing" : "") <<
- (s->sslBump ? " bumpy" : "") <<
- (s->accel ? " accelerated" : "")
- << " HTTP connections at " << s->s
- << ", FD " << fd << "." );
+ debugs(1, 1, "Accepting " <<
+ (s->intercepted ? " intercepted" : "") <<
+ (s->spoof_client_ip ? " spoofing" : "") <<
+ (s->sslBump ? " bumpy" : "") <<
+ (s->accel ? " accelerated" : "")
+ << " HTTP connections at " << s->s
+ << ", FD " << fd << "." );
Must(AddOpenedHttpSocket(fd)); // otherwise, we have received a fd we did not ask for
}
}
AsyncCall::Pointer call = asyncCall(33, 2, "clientHttpsConnectionOpened",
- ListeningStartedDialer(&clientHttpsConnectionOpened, &s->http));
+ ListeningStartedDialer(&clientHttpsConnectionOpened, &s->http));
Ipc::StartListening(SOCK_STREAM, IPPROTO_TCP, s->http.s, COMM_NONBLOCKING,
- Ipc::fdnHttpsSocket, call);
+ Ipc::fdnHttpsSocket, call);
HttpSockets[NHttpSockets++] = -1;
}
Must(s);
- AsyncCall::Pointer call = commCbCall(5,5, "SomeCommAcceptHandler(httpsAccept)",
- CommAcceptCbPtrFun(httpsAccept, s));
+ AsyncCall::Pointer call = commCbCall(5,5, "SomeCommAcceptHandler(httpsAccept)",
+ CommAcceptCbPtrFun(httpsAccept, s));
- s->listener = new Comm::ListenStateData(fd, call, true);
+ s->listener = new Comm::ListenStateData(fd, call, true);
- debugs(1, 1, "Accepting HTTPS connections at " << s->s << ", FD " << fd << ".");
+ debugs(1, 1, "Accepting HTTPS connections at " << s->s << ", FD " << fd << ".");
Must(AddOpenedHttpSocket(fd)); // otherwise, we have received a fd we did not ask for
}
/// update FD tables after a local or remote (IPC) comm_openex();
void
comm_init_opened(int new_socket,
- IpAddress &addr,
- unsigned char TOS,
- const char *note,
- struct addrinfo *AI)
+ IpAddress &addr,
+ unsigned char TOS,
+ const char *note,
+ struct addrinfo *AI)
{
assert(new_socket >= 0);
assert(AI);
/// returns new_socket or -1 on error
static int
comm_apply_flags(int new_socket,
- IpAddress &addr,
- int flags,
- struct addrinfo *AI)
+ IpAddress &addr,
+ int flags,
+ struct addrinfo *AI)
{
assert(new_socket >= 0);
assert(AI);
void
comm_import_opened(int fd,
- IpAddress &addr,
- int flags,
- const char *note,
- struct addrinfo *AI)
+ IpAddress &addr,
+ int flags,
+ const char *note,
+ struct addrinfo *AI)
{
debugs(5, 2, HERE << " FD " << fd << " at " << addr);
assert(fd >= 0);
debugLogKid(void)
{
if (KidIdentifier != 0) {
- static char buf[16];
+ static char buf[16];
if (!*buf) // optimization: fill only once after KidIdentifier is set
snprintf(buf, sizeof(buf), " kid%d", KidIdentifier);
- return buf;
+ return buf;
}
return "";
/// dials htcpIncomingConnectionOpened call
class HtcpListeningStartedDialer: public CallDialer,
- public Ipc::StartListeningCb
+ public Ipc::StartListeningCb
{
public:
typedef void (*Handler)(int fd, int errNo);
incomingAddr.SetPort(Config.Port.htcp);
AsyncCall::Pointer call = asyncCall(31, 2,
- "htcpIncomingConnectionOpened",
- HtcpListeningStartedDialer(&htcpIncomingConnectionOpened));
+ "htcpIncomingConnectionOpened",
+ HtcpListeningStartedDialer(&htcpIncomingConnectionOpened));
Ipc::StartListening(SOCK_DGRAM,
- IPPROTO_UDP,
- incomingAddr,
- COMM_NONBLOCKING,
- Ipc::fdnInHtcpSocket, call);
+ IPPROTO_UDP,
+ incomingAddr,
+ COMM_NONBLOCKING,
+ Ipc::fdnInHtcpSocket, call);
if (!Config.Addrs.udp_outgoing.IsNoAddr()) {
IpAddress outgoingAddr = Config.Addrs.udp_outgoing;
/// dials icpIncomingConnectionOpened call
class IcpListeningStartedDialer: public CallDialer,
- public Ipc::StartListeningCb
+ public Ipc::StartListeningCb
{
public:
typedef void (*Handler)(int fd, int errNo, IpAddress& addr);
IcpListeningStartedDialer(Handler aHandler, IpAddress& anAddr):
- handler(aHandler), addr(anAddr) {}
+ handler(aHandler), addr(anAddr) {}
- virtual void print(std::ostream &os) const { startPrint(os) <<
- ", address=" << addr << ')'; }
+ virtual void print(std::ostream &os) const {
+ startPrint(os) <<
+ ", address=" << addr << ')';
+ }
virtual bool canDial(AsyncCall &) const { return true; }
virtual void dial(AsyncCall &) { (handler)(fd, errNo, addr); }
addr.SetPort(port);
AsyncCall::Pointer call = asyncCall(12, 2,
- "icpIncomingConnectionOpened",
- IcpListeningStartedDialer(&icpIncomingConnectionOpened, addr));
+ "icpIncomingConnectionOpened",
+ IcpListeningStartedDialer(&icpIncomingConnectionOpened, addr));
Ipc::StartListening(SOCK_DGRAM,
- IPPROTO_UDP,
- addr,
- COMM_NONBLOCKING,
- Ipc::fdnInIcpSocket, call);
+ IPPROTO_UDP,
+ addr,
+ COMM_NONBLOCKING,
+ Ipc::fdnInIcpSocket, call);
addr.SetEmpty(); // clear for next use.
addr = Config.Addrs.udp_outgoing;
debugs(12, 1, "Accepting ICP messages at " << addr << ", FD " << theInIcpConnection << ".");
- fd_note(theInIcpConnection, "Incoming ICP socket");
+ fd_note(theInIcpConnection, "Incoming ICP socket");
if (Config.Addrs.udp_outgoing.IsNoAddr())
theOutIcpConnection = theInIcpConnection;
Ipc::Coordinator::Coordinator():
- Port(coordinatorAddr)
+ Port(coordinatorAddr)
{
}
Ipc::Coordinator::handleSharedListenRequest(const SharedListenRequest& request)
{
debugs(54, 4, HERE << "kid" << request.requestorId <<
- " needs shared listen FD for " << request.params.addr);
+ " needs shared listen FD for " << request.params.addr);
Listeners::const_iterator i = listeners.find(request.params);
int errNo = 0;
const int sock = (i != listeners.end()) ?
- i->second : openListenSocket(request, errNo);
+ i->second : openListenSocket(request, errNo);
debugs(54, 3, HERE << "sending shared listen FD " << sock << " for " <<
- request.params.addr << " to kid" << request.requestorId <<
- " mapId=" << request.mapId);
+ request.params.addr << " to kid" << request.requestorId <<
+ " mapId=" << request.mapId);
SharedListenResponse response(sock, errNo, request.mapId);
TypedMsgHdr message;
int
Ipc::Coordinator::openListenSocket(const SharedListenRequest& request,
- int &errNo)
+ int &errNo)
{
const OpenListenerParams &p = request.params;
debugs(54, 6, HERE << "opening listen FD at " << p.addr << " for kid" <<
- request.requestorId);
+ request.requestorId);
IpAddress addr = p.addr; // comm_open_listener may modify it
enter_suid();
const int sock = comm_open_listener(p.sock_type, p.proto, addr, p.flags,
- FdNote(p.fdNote));
+ FdNote(p.fdNote));
errNo = (sock >= 0) ? 0 : errno;
leave_suid();
typedef Strands::const_iterator SCI;
for (SCI iter = strands.begin(); iter != strands.end(); ++iter) {
debugs(54, 5, HERE << "signal " << sig << " to kid" << iter->kidId <<
- ", PID=" << iter->pid);
+ ", PID=" << iter->pid);
kill(iter->pid, sig);
}
}
/// fd_note() label ID
typedef enum { fdnNone, fdnHttpSocket, fdnHttpsSocket,
- fdnInSnmpSocket, fdnOutSnmpSocket,
- fdnInIcpSocket, fdnInHtcpSocket, fdnEnd } FdNoteId;
+ fdnInSnmpSocket, fdnOutSnmpSocket,
+ fdnInIcpSocket, fdnInHtcpSocket, fdnEnd
+ } FdNoteId;
extern const char *FdNote(int fdNodeId); ///< converts FdNoteId into a string
#include "ipc/Kid.h"
Kid::Kid():
- badFailures(0),
- pid(-1),
- startTime(0),
- isRunning(false)
+ badFailures(0),
+ pid(-1),
+ startTime(0),
+ isRunning(false)
{
}
Kid::Kid(const String& kid_name):
- theName(kid_name),
- badFailures(0),
- pid(-1),
- startTime(0),
- isRunning(false)
+ theName(kid_name),
+ badFailures(0),
+ pid(-1),
+ startTime(0),
+ isRunning(false)
{
}
/// message class identifier
typedef enum { mtNone = 0, mtRegistration,
- mtSharedListenRequest, mtSharedListenResponse } MessageType;
+ mtSharedListenRequest, mtSharedListenResponse
+ } MessageType;
/// Strand location details
-class StrandCoord {
+class StrandCoord
+{
public:
StrandCoord(); ///< unknown location
StrandCoord(int akidId, pid_t aPid); ///< from registrant
Ipc::Port::Port(const String& aListenAddr):
- UdsOp(aListenAddr)
+ UdsOp(aListenAddr)
{
setOptions(COMM_NONBLOCKING | COMM_DOBIND);
}
debugs(54, 6, HERE);
buf.prepForReading();
AsyncCall::Pointer readHandler = asyncCall(54, 6, "Ipc::Port::noteRead",
- CommCbMemFunT<Port, CommIoCbParams>(this, &Port::noteRead));
+ CommCbMemFunT<Port, CommIoCbParams>(this, &Port::noteRead));
comm_read(fd(), buf.raw(), buf.size(), readHandler);
}
void Ipc::Port::noteRead(const CommIoCbParams& params)
{
debugs(54, 6, HERE << "FD " << params.fd << " flag " << params.flag <<
- " [" << this << ']');
+ " [" << this << ']');
if (params.flag == COMM_OK) {
assert(params.buf == buf.raw());
receive(buf);
Ipc::SharedListenResponse::SharedListenResponse(int aFd, int anErrNo, int aMapId):
- fd(aFd), errNo(anErrNo), mapId(aMapId)
+ fd(aFd), errNo(anErrNo), mapId(aMapId)
{
}
Ipc::SharedListenResponse::SharedListenResponse(const TypedMsgHdr &hdrMsg):
- fd(-1), errNo(0), mapId(-1)
+ fd(-1), errNo(0), mapId(-1)
{
hdrMsg.getData(mtSharedListenResponse, this, sizeof(*this));
fd = hdrMsg.getFd();
void Ipc::JoinSharedListen(const OpenListenerParams ¶ms,
- AsyncCall::Pointer &callback)
+ AsyncCall::Pointer &callback)
{
PendingOpenRequest por;
por.params = params;
request.mapId = AddToMap(por);
debugs(54, 3, HERE << "getting listening FD for " << request.params.addr <<
- " mapId=" << request.mapId);
+ " mapId=" << request.mapId);
TypedMsgHdr message;
request.pack(message);
const int fd = response.fd;
debugs(54, 3, HERE << "got listening FD " << fd << " errNo=" <<
- response.errNo << " mapId=" << response.mapId);
+ response.errNo << " mapId=" << response.mapId);
Must(TheSharedListenRequestMap.find(response.mapId) != TheSharedListenRequestMap.end());
PendingOpenRequest por = TheSharedListenRequestMap[response.mapId];
void Ipc::StartListening(int sock_type, int proto, IpAddress &addr,
- int flags, FdNoteId fdNote, AsyncCall::Pointer &callback)
+ int flags, FdNoteId fdNote, AsyncCall::Pointer &callback)
{
OpenListenerParams p;
p.sock_type = sock_type;
enter_suid();
const int sock = comm_open_listener(p.sock_type, p.proto, p.addr, p.flags,
- FdNote(p.fdNote));
+ FdNote(p.fdNote));
const int errNo = (sock >= 0) ? 0 : errno;
leave_suid();
/// Depending on whether SMP is on, either ask Coordinator to send us
/// the listening FD or call comm_open_listener() directly.
extern void StartListening(int sock_type, int proto, IpAddress &addr,
- int flags, FdNoteId fdNote, AsyncCall::Pointer &callback);
+ int flags, FdNoteId fdNote, AsyncCall::Pointer &callback);
} // namespace Ipc;
Ipc::Strand::Strand():
- Port(MakeAddr(strandAddrPfx, KidIdentifier)),
- isRegistered(false)
+ Port(MakeAddr(strandAddrPfx, KidIdentifier)),
+ isRegistered(false)
{
}
Ipc::TypedMsgHdr::TypedMsgHdr()
{
- xmemset(this, 0, sizeof(*this));
- sync();
+ xmemset(this, 0, sizeof(*this));
+ sync();
}
Ipc::TypedMsgHdr::TypedMsgHdr(const TypedMsgHdr &tmh)
{
- xmemcpy(this, &tmh, sizeof(*this));
- sync();
+ xmemcpy(this, &tmh, sizeof(*this));
+ sync();
}
Ipc::TypedMsgHdr &Ipc::TypedMsgHdr::operator =(const TypedMsgHdr &tmh)
{
- if (this != &tmh) { // skip assignment to self
- xmemcpy(this, &tmh, sizeof(*this));
- sync();
- }
- return *this;
+ if (this != &tmh) { // skip assignment to self
+ xmemcpy(this, &tmh, sizeof(*this));
+ sync();
+ }
+ return *this;
}
// update msghdr and ios pointers based on msghdr counters
void Ipc::TypedMsgHdr::sync()
{
- if (msg_name) { // we have a name
- msg_name = &name;
- } else {
- Must(!msg_namelen && !msg_name);
- }
-
- if (msg_iov) { // we have a data component
- Must(msg_iovlen == 1);
- msg_iov = ios;
- ios[0].iov_base = &data;
- Must(ios[0].iov_len == sizeof(data));
- } else {
- Must(!msg_iovlen && !msg_iov);
- }
-
- if (msg_control) { // we have a control component
- Must(msg_controllen > 0);
- msg_control = &ctrl;
- } else {
- Must(!msg_controllen && !msg_control);
- }
+ if (msg_name) { // we have a name
+ msg_name = &name;
+ } else {
+ Must(!msg_namelen && !msg_name);
+ }
+
+ if (msg_iov) { // we have a data component
+ Must(msg_iovlen == 1);
+ msg_iov = ios;
+ ios[0].iov_base = &data;
+ Must(ios[0].iov_len == sizeof(data));
+ } else {
+ Must(!msg_iovlen && !msg_iov);
+ }
+
+ if (msg_control) { // we have a control component
+ Must(msg_controllen > 0);
+ msg_control = &ctrl;
+ } else {
+ Must(!msg_controllen && !msg_control);
+ }
}
int
Ipc::TypedMsgHdr::type() const
{
- Must(msg_iovlen == 1);
- return data.type_;
+ Must(msg_iovlen == 1);
+ return data.type_;
}
void
Ipc::TypedMsgHdr::address(const struct sockaddr_un& addr)
{
- allocName();
- name = addr;
+ allocName();
+ name = addr;
msg_name = &name;
msg_namelen = SUN_LEN(&name);
}
void
Ipc::TypedMsgHdr::getData(int destType, void *raw, size_t size) const
{
- Must(type() == destType);
- Must(size == data.size);
- xmemcpy(raw, data.raw, size);
+ Must(type() == destType);
+ Must(size == data.size);
+ xmemcpy(raw, data.raw, size);
}
void
Ipc::TypedMsgHdr::putData(int aType, const void *raw, size_t size)
{
- Must(size <= sizeof(data.raw));
- allocData();
- data.type_ = aType;
- data.size = size;
- xmemcpy(data.raw, raw, size);
+ Must(size <= sizeof(data.raw));
+ allocData();
+ data.type_ = aType;
+ data.size = size;
+ xmemcpy(data.raw, raw, size);
}
void
Ipc::TypedMsgHdr::putFd(int fd)
{
- Must(fd >= 0);
- allocControl();
+ Must(fd >= 0);
+ allocControl();
- const int fdCount = 1;
+ const int fdCount = 1;
- struct cmsghdr *cmsg = CMSG_FIRSTHDR(this);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fdCount);
+ struct cmsghdr *cmsg = CMSG_FIRSTHDR(this);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fdCount);
int *fdStore = reinterpret_cast<int*>(CMSG_DATA(cmsg));
- xmemcpy(fdStore, &fd, fdCount * sizeof(int));
+ xmemcpy(fdStore, &fd, fdCount * sizeof(int));
msg_controllen = cmsg->cmsg_len;
}
int
Ipc::TypedMsgHdr::getFd() const
{
- Must(msg_control && msg_controllen);
+ Must(msg_control && msg_controllen);
- struct cmsghdr *cmsg = CMSG_FIRSTHDR(this);
- Must(cmsg->cmsg_level == SOL_SOCKET);
- Must(cmsg->cmsg_type == SCM_RIGHTS);
+ struct cmsghdr *cmsg = CMSG_FIRSTHDR(this);
+ Must(cmsg->cmsg_level == SOL_SOCKET);
+ Must(cmsg->cmsg_type == SCM_RIGHTS);
- const int fdCount = 1;
+ const int fdCount = 1;
const int *fdStore = reinterpret_cast<const int*>(CMSG_DATA(cmsg));
- int fd = -1;
- xmemcpy(&fd, fdStore, fdCount * sizeof(int));
- return fd;
+ int fd = -1;
+ xmemcpy(&fd, fdStore, fdCount * sizeof(int));
+ return fd;
}
void
Ipc::TypedMsgHdr::prepForReading()
{
- xmemset(this, 0, sizeof(*this));
- allocName();
- allocData();
- allocControl();
+ xmemset(this, 0, sizeof(*this));
+ allocName();
+ allocData();
+ allocControl();
}
/// initialize io vector with one io record
void
Ipc::TypedMsgHdr::allocData()
{
- Must(!msg_iovlen && !msg_iov);
- msg_iovlen = 1;
- msg_iov = ios;
- ios[0].iov_base = &data;
- ios[0].iov_len = sizeof(data);
- data.type_ = 0;
- data.size = 0;
+ Must(!msg_iovlen && !msg_iov);
+ msg_iovlen = 1;
+ msg_iov = ios;
+ ios[0].iov_base = &data;
+ ios[0].iov_len = sizeof(data);
+ data.type_ = 0;
+ data.size = 0;
}
void
Ipc::TypedMsgHdr::allocName()
{
- Must(!msg_name && !msg_namelen);
+ Must(!msg_name && !msg_namelen);
msg_name = &name;
msg_namelen = sizeof(name); // is that the right size?
}
void
Ipc::TypedMsgHdr::allocControl()
{
- Must(!msg_control && !msg_controllen);
- msg_control = &ctrl;
- msg_controllen = sizeof(ctrl);
+ Must(!msg_control && !msg_controllen);
+ msg_control = &ctrl;
+ msg_controllen = sizeof(ctrl);
}
void address(const struct sockaddr_un& addr); ///< sets [dest.] address
void getData(int ofType, void *raw, size_t size) const; ///< checks type
void putData(int aType, const void *raw, size_t size); ///< stores type
- void putFd(int aFd); ///< stores descriptor
- int getFd() const; ///< returns descriptor
+ void putFd(int aFd); ///< stores descriptor
+ int getFd() const; ///< returns descriptor
/// raw, type-independent access for I/O
- void prepForReading(); ///< reset and provide all buffers
- char *raw() { return reinterpret_cast<char*>(this); }
- const char *raw() const { return reinterpret_cast<const char*>(this); }
+ void prepForReading(); ///< reset and provide all buffers
+ char *raw() { return reinterpret_cast<char*>(this); }
+ const char *raw() const { return reinterpret_cast<const char*>(this); }
size_t size() const { return sizeof(*this); } ///< not true message size
private:
- void sync();
- void allocData();
- void allocName();
- void allocControl();
+ void sync();
+ void allocData();
+ void allocName();
+ void allocControl();
private:
- struct sockaddr_un name; ///< same as .msg_name
+ struct sockaddr_un name; ///< same as .msg_name
- struct iovec ios[1]; ///< same as .msg_iov[]
+ struct iovec ios[1]; ///< same as .msg_iov[]
- struct DataBuffer {
- int type_; ///< Message kind, uses MessageType values
- size_t size; ///< actual raw data size (for sanity checks)
- char raw[250]; ///< buffer with type-specific data
- } data; ///< same as .msg_iov[0].iov_base
+ struct DataBuffer {
+ int type_; ///< Message kind, uses MessageType values
+ size_t size; ///< actual raw data size (for sanity checks)
+ char raw[250]; ///< buffer with type-specific data
+ } data; ///< same as .msg_iov[0].iov_base
- struct CtrlBuffer {
- char raw[CMSG_SPACE(sizeof(int))]; ///< control buffer space for one fd
- } ctrl; ///< same as .msg_control
+ struct CtrlBuffer {
+ char raw[CMSG_SPACE(sizeof(int))]; ///< control buffer space for one fd
+ } ctrl; ///< same as .msg_control
};
} // namespace Ipc
Ipc::UdsOp::UdsOp(const String& pathAddr):
- AsyncJob("Ipc::UdsOp"),
- address(PathToAddress(pathAddr)),
- options(COMM_NONBLOCKING),
- fd_(-1)
+ AsyncJob("Ipc::UdsOp"),
+ address(PathToAddress(pathAddr)),
+ options(COMM_NONBLOCKING),
+ fd_(-1)
{
debugs(54, 5, HERE << '[' << this << "] pathAddr=" << pathAddr);
}
void Ipc::UdsOp::setTimeout(int seconds, const char *handlerName)
{
AsyncCall::Pointer handler = asyncCall(54,5, handlerName,
- CommCbMemFunT<UdsOp, CommTimeoutCbParams>(this,
- &UdsOp::noteTimeout));
+ CommCbMemFunT<UdsOp, CommTimeoutCbParams>(this,
+ &UdsOp::noteTimeout));
commSetTimeout(fd(), seconds, handler);
}
struct sockaddr_un
-Ipc::PathToAddress(const String& pathAddr)
-{
+Ipc::PathToAddress(const String& pathAddr) {
assert(pathAddr.size() != 0);
struct sockaddr_un unixAddr;
memset(&unixAddr, 0, sizeof(unixAddr));
CBDATA_NAMESPACED_CLASS_INIT(Ipc, UdsSender);
Ipc::UdsSender::UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage):
- UdsOp(pathAddr),
- message(aMessage),
- retries(10), // TODO: make configurable?
- timeout(10), // TODO: make configurable?
- writing(false)
+ UdsOp(pathAddr),
+ message(aMessage),
+ retries(10), // TODO: make configurable?
+ timeout(10), // TODO: make configurable?
+ writing(false)
{
message.address(address);
}
{
debugs(54, 5, HERE);
AsyncCall::Pointer writeHandler = asyncCall(54, 5, "Ipc::UdsSender::wrote",
- CommCbMemFunT<UdsSender, CommIoCbParams>(this, &UdsSender::wrote));
+ CommCbMemFunT<UdsSender, CommIoCbParams>(this, &UdsSender::wrote));
comm_write(fd(), message.raw(), message.size(), writeHandler);
writing = true;
}
void setTimeout(int seconds, const char *handlerName);
void clearTimeout(); ///< remove previously set timeout, if any
- void setOptions(int newOptions); ///< changes socket options
+ void setOptions(int newOptions); ///< changes socket options
private:
/// Comm timeout callback; calls timedout()
if (IamPrimaryProcess()) {
#if USE_WCCP
- wccpConnectionOpen();
+ wccpConnectionOpen();
#endif
#if USE_WCCPv2
- wccp2ConnectionOpen();
+ wccp2ConnectionOpen();
#endif
}
// Coordinator does not start proxying services
if (!IamCoordinatorProcess()) {
- clientOpenListenSockets();
- icpConnectionsOpen();
+ clientOpenListenSockets();
+ icpConnectionsOpen();
#if USE_HTCP
- htcpInit();
+ htcpInit();
#endif
#ifdef SQUID_SNMP
- snmpConnectionOpen();
+ snmpConnectionOpen();
#endif
- clientdbInit();
- icmpEngine.Open();
- netdbInit();
- asnInit();
- ACL::Initialize();
- peerSelectInit();
-
- carpInit();
- peerUserHashInit();
- peerSourceHashInit();
+ clientdbInit();
+ icmpEngine.Open();
+ netdbInit();
+ asnInit();
+ ACL::Initialize();
+ peerSelectInit();
+
+ carpInit();
+ peerUserHashInit();
+ peerSourceHashInit();
}
}
if (IamPrimaryProcess()) {
#if USE_WCCP
- wccpConnectionClose();
+ wccpConnectionClose();
#endif
#if USE_WCCPv2
- wccp2ConnectionClose();
+ wccp2ConnectionClose();
#endif
}
if (!IamCoordinatorProcess()) {
- clientHttpConnectionsClose();
- icpConnectionShutdown();
+ clientHttpConnectionsClose();
+ icpConnectionShutdown();
#if USE_HTCP
- htcpSocketShutdown();
+ htcpSocketShutdown();
#endif
- icmpEngine.Close();
+ icmpEngine.Close();
#ifdef SQUID_SNMP
- snmpConnectionShutdown();
+ snmpConnectionShutdown();
#endif
- asnFreeMemory();
+ asnFreeMemory();
}
}
}
if (oldWorkers != Config.workers) {
debugs(1, DBG_CRITICAL, "WARNING: Changing 'workers' (from " <<
- oldWorkers << " to " << Config.workers <<
- ") is not supported and ignored");
+ oldWorkers << " to " << Config.workers <<
+ ") is not supported and ignored");
Config.workers = oldWorkers;
}
if (IamPrimaryProcess()) {
#if USE_WCCP
- wccpInit();
+ wccpInit();
#endif
#if USE_WCCPv2
- wccp2Init();
+ wccp2Init();
#endif
}
if (IamPrimaryProcess()) {
#if USE_WCCP
- wccpInit();
+ wccpInit();
#endif
#if USE_WCCPv2
- wccp2Init();
+ wccp2Init();
#endif
}
static void
ConfigureCurrentKid(const char *processName)
{
- // kids are marked with parenthesis around their process names
+ // kids are marked with parenthesis around their process names
if (processName && processName[0] == '(') {
if (const char *idStart = strrchr(processName, '-')) {
KidIdentifier = atoi(idStart + 1);
if (Config.workers > 128) {
syslog(LOG_ALERT, "Suspiciously high workers value: %d",
- Config.workers);
+ Config.workers);
// but we keep going in hope that user knows best
- }
+ }
TheKids.init(Config.workers);
// keep [re]starting kids until it is time to quit
#endif
// Loop to collect all stopped kids before we go to sleep below.
- do
- {
+ do {
Kid* kid = TheKids.find(pid);
if (kid) {
kid->stop(status);
if (kid->calledExit()) {
syslog(LOG_NOTICE,
- "Squid Parent: child process %d exited with status %d",
- kid->getPid(), kid->exitStatus());
+ "Squid Parent: child process %d exited with status %d",
+ kid->getPid(), kid->exitStatus());
} else if (kid->signaled()) {
syslog(LOG_NOTICE,
- "Squid Parent: child process %d exited due to signal %d with status %d",
- kid->getPid(), kid->termSignal(), kid->exitStatus());
+ "Squid Parent: child process %d exited due to signal %d with status %d",
+ kid->getPid(), kid->termSignal(), kid->exitStatus());
} else {
syslog(LOG_NOTICE, "Squid Parent: child process %d exited", kid->getPid());
}
#ifdef _SQUID_NEXT_
} while ((pid = wait3(&status, WNOHANG, NULL)) > 0);
#else
- } while ((pid = waitpid(-1, &status, WNOHANG)) > 0);
+ }
+ while ((pid = waitpid(-1, &status, WNOHANG)) > 0);
#endif
if (TheKids.allExitedHappy()) {
SQUIDCEXTERN void BroadcastSignalIfAny(int& sig);
/// whether the current process is the parent of all other Squid processes
SQUIDCEXTERN bool IamMasterProcess();
-/**
+/**
whether the current process is dedicated to doing things that only
a single process should do, such as PID file maintenance and WCCP
*/
/// dials snmpConnectionOpened call
class SnmpListeningStartedDialer: public CallDialer,
- public Ipc::StartListeningCb
+ public Ipc::StartListeningCb
{
public:
typedef void (*Handler)(int fd, int errNo);
Config.Addrs.snmp_incoming.SetPort(Config.Port.snmp);
AsyncCall::Pointer call = asyncCall(49, 2,
- "snmpIncomingConnectionOpened",
- SnmpListeningStartedDialer(&snmpIncomingConnectionOpened));
+ "snmpIncomingConnectionOpened",
+ SnmpListeningStartedDialer(&snmpIncomingConnectionOpened));
Ipc::StartListening(SOCK_DGRAM,
- IPPROTO_UDP,
- Config.Addrs.snmp_incoming,
- COMM_NONBLOCKING,
- Ipc::fdnInSnmpSocket, call);
+ IPPROTO_UDP,
+ Config.Addrs.snmp_incoming,
+ COMM_NONBLOCKING,
+ Ipc::fdnInSnmpSocket, call);
if (!Config.Addrs.snmp_outgoing.IsNoAddr()) {
Config.Addrs.snmp_outgoing.SetPort(Config.Port.snmp);
AsyncCall::Pointer call = asyncCall(49, 2,
- "snmpOutgoingConnectionOpened",
- SnmpListeningStartedDialer(&snmpOutgoingConnectionOpened));
-
- Ipc::StartListening(SOCK_DGRAM,
- IPPROTO_UDP,
- Config.Addrs.snmp_outgoing,
- COMM_NONBLOCKING,
- Ipc::fdnOutSnmpSocket, call);
+ "snmpOutgoingConnectionOpened",
+ SnmpListeningStartedDialer(&snmpOutgoingConnectionOpened));
+
+ Ipc::StartListening(SOCK_DGRAM,
+ IPPROTO_UDP,
+ Config.Addrs.snmp_outgoing,
+ COMM_NONBLOCKING,
+ Ipc::fdnOutSnmpSocket, call);
}
}
}
fatal("Cannot open Incoming SNMP Port");
commSetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL,
- 0);
+ 0);
debugs(1, 1, "Accepting SNMP messages on " << Config.Addrs.snmp_incoming <<
- ", FD " << theInSnmpConnection << ".");
+ ", FD " << theInSnmpConnection << ".");
if (Config.Addrs.snmp_outgoing.IsNoAddr())
theOutSnmpConnection = theInSnmpConnection;
fatal("Cannot open Outgoing SNMP Port");
commSetSelect(theOutSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL,
- 0);
+ 0);
debugs(1, 1, "Outgoing SNMP messages on " << Config.Addrs.snmp_outgoing <<
- ", FD " << theOutSnmpConnection << ".");
+ ", FD " << theOutSnmpConnection << ".");
{
struct addrinfo *xaddr = NULL;