IoCallback.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
21void
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
33void
35{
36 // release any Comm::Connections being held.
37 for (int pos = 0; pos < Squid_MaxFD; ++pos) {
38 iocb_table[pos].readcb.conn = nullptr;
39 iocb_table[pos].writecb.conn = nullptr;
40 }
42}
43
54void
56{
57 assert(!active());
58 assert(type == t);
59 assert(cb != nullptr);
60
61 callback = cb;
62 buf = b;
63 freefunc = f;
64 size = sz;
65 offset = 0;
66}
67
68void
70{
71#if USE_DELAY_POOLS
73 bucket->scheduleWrite(this);
74 return;
75 }
76#endif
77
79}
80
81void
82Comm::IoCallback::cancel(const char *reason)
83{
84 if (!active())
85 return;
86
87 callback->cancel(reason);
88 callback = nullptr;
89 reset();
90}
91
92void
94{
95 conn = nullptr;
96 if (freefunc) {
97 freefunc(buf);
98 buf = nullptr;
99 freefunc = nullptr;
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
109void
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 = nullptr;
119 freefunc = nullptr;
120 }
121
122 if (callback != nullptr) {
123 typedef CommIoCbParams Params;
124 Params &params = GetCommParams<Params>(callback);
125 if (conn != nullptr) 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;
131 ScheduleCallHere(callback);
132 callback = nullptr;
133 }
134
135 /* Reset for next round. */
136 reset();
137}
138
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:17
Base class for Squid-to-client bandwidth limiting.
static BandwidthBucket * SelectBucket(fde *f)
IoCallback writecb
Definition: IoCallback.h:68
IoCallback readcb
Definition: IoCallback.h:67
void setCallback(iocb_type type, AsyncCall::Pointer &cb, char *buf, FREE *func, int sz)
Definition: IoCallback.cc:55
bool active() const
Definition: IoCallback.h:45
void selectOrQueueWrite()
called when fd needs to write but may need to wait in line for its quota
Definition: IoCallback.cc:69
AsyncCall::Pointer callback
Definition: IoCallback.h:34
void finish(Comm::Flag code, int xerrn)
finish the IO operation immediately and schedule the callback with the current state.
Definition: IoCallback.cc:110
void cancel(const char *reason)
Actively cancel the given callback.
Definition: IoCallback.cc:82
iocb_type type
Definition: IoCallback.h:32
Comm::ConnectionPointer conn
Definition: IoCallback.h:33
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define COMM_SELECT_WRITE
Definition: defines.h:25
#define fd_table
Definition: fde.h:189
int Squid_MaxFD
void FREE(void *)
Definition: forward.h:37
PF HandleWrite
Definition: forward.h:33
void CallbackTableDestruct()
Definition: IoCallback.cc:34
iocb_type
Type of IO callbacks the Comm layer deals with.
Definition: IoCallback.h:22
@ IOCB_WRITE
Definition: IoCallback.h:25
@ IOCB_READ
Definition: IoCallback.h:24
CbEntry * iocb_table
Definition: IoCallback.cc:19
Flag
Definition: Flag.h:15
void CallbackTableInit()
Definition: IoCallback.cc:22
void SetSelect(int, unsigned int, PF *, void *, time_t)
Mark an FD to be watched for its IO status.
Definition: ModDevPoll.cc:223
int code
Definition: smb-errors.c:145
void * xcalloc(size_t n, size_t sz)
Definition: xalloc.cc:71
#define safe_free(x)
Definition: xalloc.h:73

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors