]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/StoreToCommWriter.cc
2 * DEBUG: section 16 Cache Manager API
7 #include "base/TextException.h"
8 #include "comm/Connection.h"
9 #include "comm/Write.h"
10 #include "CommCalls.h"
11 #include "ipc/FdNotes.h"
12 #include "mgr/StoreToCommWriter.h"
14 #include "StoreClient.h"
16 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, StoreToCommWriter
);
18 Mgr::StoreToCommWriter::StoreToCommWriter(const Comm::ConnectionPointer
&conn
, StoreEntry
* anEntry
):
19 AsyncJob("Mgr::StoreToCommWriter"),
20 clientConnection(conn
), entry(anEntry
), sc(NULL
), writeOffset(0), closer(NULL
)
22 debugs(16, 6, HERE
<< clientConnection
);
23 closer
= asyncCall(16, 5, "Mgr::StoreToCommWriter::noteCommClosed",
24 CommCbMemFunT
<StoreToCommWriter
, CommCloseCbParams
>(this, &StoreToCommWriter::noteCommClosed
));
25 comm_add_close_handler(clientConnection
->fd
, closer
);
28 Mgr::StoreToCommWriter::~StoreToCommWriter()
36 /// closes our copy of the client HTTP connection socket
38 Mgr::StoreToCommWriter::close()
40 if (Comm::IsConnOpen(clientConnection
)) {
42 comm_remove_close_handler(clientConnection
->fd
, closer
);
45 clientConnection
->close();
50 Mgr::StoreToCommWriter::start()
53 Must(Comm::IsConnOpen(clientConnection
));
55 entry
->registerAbort(&StoreToCommWriter::Abort
, this);
56 sc
= storeClientListAdd(entry
, this);
59 // initiate the receive-from-store, write-to-comm sequence
64 Mgr::StoreToCommWriter::scheduleStoreCopy()
69 StoreIOBuffer
readBuf(sizeof(buffer
), writeOffset
, buffer
);
70 storeClientCopy(sc
, entry
, readBuf
, &NoteStoreCopied
, this);
74 Mgr::StoreToCommWriter::NoteStoreCopied(void* data
, StoreIOBuffer ioBuf
)
77 // make sync Store call async to get async call protections and features
78 StoreToCommWriter
* writer
= static_cast<StoreToCommWriter
*>(data
);
79 typedef UnaryMemFunT
<StoreToCommWriter
, StoreIOBuffer
> MyDialer
;
80 AsyncCall::Pointer call
=
81 asyncCall(16, 5, "Mgr::StoreToCommWriter::noteStoreCopied",
82 MyDialer(writer
, &StoreToCommWriter::noteStoreCopied
, ioBuf
));
83 ScheduleCallHere(call
);
87 Mgr::StoreToCommWriter::noteStoreCopied(StoreIOBuffer ioBuf
)
90 Must(!ioBuf
.flags
.error
);
92 scheduleCommWrite(ioBuf
); // write received action results to client
94 Must(doneAll()); // otherwise, why would Store call us with no data?
98 Mgr::StoreToCommWriter::scheduleCommWrite(const StoreIOBuffer
& ioBuf
)
101 Must(Comm::IsConnOpen(clientConnection
));
102 Must(ioBuf
.data
!= NULL
);
103 // write filled buffer
104 typedef CommCbMemFunT
<StoreToCommWriter
, CommIoCbParams
> MyDialer
;
105 AsyncCall::Pointer writer
=
106 asyncCall(16, 5, "Mgr::StoreToCommWriter::noteCommWrote",
107 MyDialer(this, &StoreToCommWriter::noteCommWrote
));
108 Comm::Write(clientConnection
, ioBuf
.data
, ioBuf
.length
, writer
, NULL
);
112 Mgr::StoreToCommWriter::noteCommWrote(const CommIoCbParams
& params
)
115 Must(params
.flag
== COMM_OK
);
116 Must(clientConnection
!= NULL
&& params
.fd
== clientConnection
->fd
);
117 Must(params
.size
!= 0);
118 writeOffset
+= params
.size
;
120 scheduleStoreCopy(); // retrieve the next data portion
124 Mgr::StoreToCommWriter::noteCommClosed(const CommCloseCbParams
& params
)
127 Must(!Comm::IsConnOpen(clientConnection
));
128 mustStop("commClosed");
132 Mgr::StoreToCommWriter::swanSong()
137 storeUnregister(sc
, entry
, this);
140 entry
->unregisterAbort();
148 Mgr::StoreToCommWriter::doneAll() const
151 entry
->store_status
== STORE_OK
&& // the action is over
152 writeOffset
>= entry
->objectLen(); // we wrote all the results
156 Mgr::StoreToCommWriter::Abort(void* param
)
158 StoreToCommWriter
* mgrWriter
= static_cast<StoreToCommWriter
*>(param
);
159 if (Comm::IsConnOpen(mgrWriter
->clientConnection
))
160 mgrWriter
->clientConnection
->close();