Port.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 54 Interprocess Communication */
10 
11 #include "squid.h"
12 #include "comm.h"
13 #include "comm/Connection.h"
14 #include "comm/Read.h"
15 #include "CommCalls.h"
16 #include "ipc/Port.h"
17 #include "tools.h"
18 #include "util.h"
19 
20 static const char channelPathPfx[] = DEFAULT_STATEDIR "/";
21 static const char coordinatorAddrLabel[] = "-coordinator";
22 const char Ipc::strandAddrLabel[] = "-kid";
23 
24 Ipc::Port::Port(const String& aListenAddr):
25  UdsOp(aListenAddr)
26 {
28 }
29 
31 {
32  UdsOp::start();
33  doListen();
34 }
35 
37 {
38  debugs(54, 6, HERE);
39  buf.prepForReading();
41  AsyncCall::Pointer readHandler = JobCallback(54, 6,
42  Dialer, this, Port::noteRead);
43  comm_read(conn(), buf.raw(), buf.size(), readHandler);
44 }
45 
46 bool Ipc::Port::doneAll() const
47 {
48  return false; // listen forever
49 }
50 
51 String Ipc::Port::MakeAddr(const char* processLabel, int id)
52 {
53  assert(id >= 0);
55  addr.append(service_name.c_str());
56  addr.append(processLabel);
57  addr.append('-');
58  addr.append(xitoa(id));
59  addr.append(".ipc");
60  return addr;
61 }
62 
63 String
65 {
66  static String coordinatorAddr;
67  if (!coordinatorAddr.size()) {
68  coordinatorAddr= channelPathPfx;
69  coordinatorAddr.append(service_name.c_str());
70  coordinatorAddr.append(coordinatorAddrLabel);
71  coordinatorAddr.append(".ipc");
72  }
73  return coordinatorAddr;
74 }
75 
77 {
78  debugs(54, 6, HERE << params.conn << " flag " << params.flag <<
79  " [" << this << ']');
80  if (params.flag == Comm::OK) {
81  assert(params.buf == buf.raw());
82  receive(buf);
83  }
84  // TODO: if there was a fatal error on our socket, close the socket before
85  // trying to listen again and print a level-1 error message.
86 
87  doListen();
88 }
89 
void setOptions(int newOptions)
changes socket options
Definition: UdsOp.cc:35
virtual void start()=0
called by AsyncStart; do not call directly
Definition: Port.cc:30
#define JobCallback(dbgSection, dbgLevel, Dialer, job, method)
Convenience macro to create a Dialer-based job callback.
Definition: AsyncJobCalls.h:68
#define assert(EX)
Definition: assert.h:17
Port(const String &aListenAddr)
Definition: Port.cc:24
SQUIDCEXTERN const char * xitoa(int num)
Definition: util.c:79
static const char coordinatorAddrLabel[]
Definition: Port.cc:21
Definition: Flag.h:16
int conn
the current server connection FD
Definition: Transport.cc:26
size_type size() const
Definition: SquidString.h:71
static const char channelPathPfx[]
Definition: Port.cc:20
void append(char const *buf, int len)
Definition: String.cc:161
virtual bool doneAll() const
whether positive goal has been reached
Definition: Port.cc:46
#define COMM_DOBIND
Definition: Connection.h:47
Comm::ConnectionPointer conn
Definition: CommCalls.h:85
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
void doListen()
read the next incoming message
Definition: Port.cc:36
void noteRead(const CommIoCbParams &params)
Definition: Port.cc:76
static String MakeAddr(const char *proccessLabel, int id)
calculates IPC message address for strand id of processLabel type
Definition: Port.cc:51
void comm_read(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer &callback)
Definition: Read.h:57
void * addr
Definition: membanger.c:46
const char * c_str()
Definition: SBuf.cc:546
void const char * buf
Definition: stub_helper.cc:16
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
const char strandAddrLabel[]
strand's listening address unique label
Definition: Port.cc:22
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:87
#define COMM_NONBLOCKING
Definition: Connection.h:44
SBuf service_name(APP_SHORTNAME)
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:43
static String CoordinatorAddr()
get the IPC message address for coordinator process
Definition: Port.cc:64

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors