]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/IoCallback.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / comm / IoCallback.h
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
bbc27441
AJ
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
ec41b64c
AJ
9#ifndef _SQUID_COMM_IOCALLBACK_H
10#define _SQUID_COMM_IOCALLBACK_H
11
ec41b64c 12#include "base/AsyncCall.h"
c8407295 13#include "comm/Flag.h"
b0388924 14#include "comm/forward.h"
6f5dc9e4 15#include "mem/forward.h"
92e8f3ad 16#include "sbuf/forward.h"
73042f2e 17
f31be4b0
A
18namespace Comm
19{
ec41b64c
AJ
20
21/// Type of IO callbacks the Comm layer deals with.
22typedef enum {
23 IOCB_NONE,
24 IOCB_READ,
25 IOCB_WRITE
26} iocb_type;
27
28/// Details about a particular Comm IO callback event.
f31be4b0
A
29class IoCallback
30{
ec41b64c
AJ
31public:
32 iocb_type type;
b0388924 33 Comm::ConnectionPointer conn;
ec41b64c
AJ
34 AsyncCall::Pointer callback;
35 char *buf;
36 FREE *freefunc;
37 int size;
38 int offset;
c8407295 39 Comm::Flag errcode;
ec41b64c 40 int xerrno;
9a0a18de 41#if USE_DELAY_POOLS
ec41b64c
AJ
42 unsigned int quotaQueueReserv; ///< reservation ID from CommQuotaQueue
43#endif
44
45 bool active() const { return callback != NULL; }
46 void setCallback(iocb_type type, AsyncCall::Pointer &cb, char *buf, FREE *func, int sz);
47
48 /// called when fd needs to write but may need to wait in line for its quota
49 void selectOrQueueWrite();
50
51 /// Actively cancel the given callback
52 void cancel(const char *reason);
53
54 /// finish the IO operation imediately and schedule the callback with the current state.
c8407295 55 void finish(Comm::Flag code, int xerrn);
ec41b64c
AJ
56
57private:
58 void reset();
59};
60
61/// Entry nodes for the IO callback table: iocb_table
62/// Keyed off the FD which the event applies to.
f31be4b0
A
63class CbEntry
64{
ec41b64c
AJ
65public:
66 int fd;
67 IoCallback readcb;
68 IoCallback writecb;
69};
70
71/// Table of scheduled IO events which have yet to be processed ??
72/// Callbacks which might be scheduled in future are stored in fd_table.
73extern CbEntry *iocb_table;
74
8a648e8d
FC
75void CallbackTableInit();
76void CallbackTableDestruct();
ec41b64c
AJ
77
78#define COMMIO_FD_READCB(fd) (&Comm::iocb_table[(fd)].readcb)
79#define COMMIO_FD_WRITECB(fd) (&Comm::iocb_table[(fd)].writecb)
80
e5519212 81} // namespace Comm
ec41b64c
AJ
82
83#endif /* _SQUID_COMM_IOCALLBACK_H */
f53969cc 84