IoCallback.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 #include "squid.h"
10 #include "ClientInfo.h"
11 #include "comm/Connection.h"
12 #include "comm/IoCallback.h"
13 #include "comm/Loops.h"
14 #include "comm/Write.h"
15 #include "CommCalls.h"
16 #include "fde.h"
17 #include "globals.h"
18 
20 
21 void
23 {
24  // XXX: convert this to a std::map<> ?
25  iocb_table = static_cast<CbEntry*>(xcalloc(Squid_MaxFD, sizeof(CbEntry)));
26  for (int pos = 0; pos < Squid_MaxFD; ++pos) {
27  iocb_table[pos].fd = pos;
30  }
31 }
32 
33 void
35 {
36  // release any Comm::Connections being held.
37  for (int pos = 0; pos < Squid_MaxFD; ++pos) {
38  iocb_table[pos].readcb.conn = NULL;
39  iocb_table[pos].writecb.conn = NULL;
40  }
42 }
43 
54 void
56 {
57  assert(!active());
58  assert(type == t);
59  assert(cb != NULL);
60 
61  callback = cb;
62  buf = b;
63  freefunc = f;
64  size = sz;
65  offset = 0;
66 }
67 
68 void
70 {
71 #if USE_DELAY_POOLS
73  bucket->scheduleWrite(this);
74  return;
75  }
76 #endif
77 
79 }
80 
81 void
82 Comm::IoCallback::cancel(const char *reason)
83 {
84  if (!active())
85  return;
86 
87  callback->cancel(reason);
88  callback = NULL;
89  reset();
90 }
91 
92 void
94 {
95  conn = NULL;
96  if (freefunc) {
97  freefunc(buf);
98  buf = NULL;
99  freefunc = NULL;
100  }
101  xerrno = 0;
102 
103 #if USE_DELAY_POOLS
104  quotaQueueReserv = 0;
105 #endif
106 }
107 
108 // Schedule the callback call and clear the callback
109 void
111 {
112  debugs(5, 3, "called for " << conn << " (" << code << ", " << xerrn << ")");
113  assert(active());
114 
115  /* free data */
116  if (freefunc && buf) {
117  freefunc(buf);
118  buf = NULL;
119  freefunc = NULL;
120  }
121 
122  if (callback != NULL) {
123  typedef CommIoCbParams Params;
124  Params &params = GetCommParams<Params>(callback);
125  if (conn != NULL) params.fd = conn->fd; // for legacy write handlers...
126  params.conn = conn;
127  params.buf = buf;
128  params.size = offset;
129  params.flag = code;
130  params.xerrno = xerrn;
132  callback = NULL;
133  }
134 
135  /* Reset for next round. */
136  reset();
137 }
138 
Base class for Squid-to-client bandwidth limiting.
PF HandleWrite
Definition: forward.h:34
#define fd_table
Definition: fde.h:174
#define assert(EX)
Definition: assert.h:17
int Squid_MaxFD
void finish(Comm::Flag code, int xerrn)
finish the IO operation imediately and schedule the callback with the current state.
Definition: IoCallback.cc:110
#define xcalloc
Definition: membanger.c:57
CbEntry * iocb_table
Definition: IoCallback.cc:19
#define safe_free(x)
Definition: xalloc.h:73
AsyncCall::Pointer callback
Definition: IoCallback.h:34
bool cancel(const char *reason)
Definition: AsyncCall.cc:52
void FREE(void *)
Definition: forward.h:36
void setCallback(iocb_type type, AsyncCall::Pointer &cb, char *buf, FREE *func, int sz)
Definition: IoCallback.cc:55
void CallbackTableInit()
Definition: IoCallback.cc:22
void CallbackTableDestruct()
Definition: IoCallback.cc:34
iocb_type
Type of IO callbacks the Comm layer deals with.
Definition: IoCallback.h:22
int fd
FD which the call was about. Set by the async call creator.
Definition: CommCalls.h:90
Comm::ConnectionPointer conn
Definition: IoCallback.h:33
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
void cancel(const char *reason)
Actively cancel the given callback.
Definition: IoCallback.cc:82
void SetSelect(int, unsigned int, PF *, void *, time_t)
Mark an FD to be watched for its IO status.
Definition: ModDevPoll.cc:225
void const char int sz
Definition: stub_cbdata.cc:16
#define COMM_SELECT_WRITE
Definition: defines.h:37
IoCallback writecb
Definition: IoCallback.h:68
static BandwidthBucket * SelectBucket(fde *f)
void selectOrQueueWrite()
called when fd needs to write but may need to wait in line for its quota
Definition: IoCallback.cc:69
unsigned char code
Definition: html_quote.c:20
unsigned int quotaQueueReserv
reservation ID from CommQuotaQueue
Definition: IoCallback.h:42
Flag
Definition: Flag.h:15
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
iocb_type type
Definition: IoCallback.h:32
IoCallback readcb
Definition: IoCallback.h:67
bool active() const
Definition: IoCallback.h:45
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors