]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/StoreToCommWriter.cc
4 * DEBUG: section 16 Cache Manager API
9 #include "base/TextException.h"
10 #include "CommCalls.h"
11 #include "comm/Write.h"
12 #include "ipc/FdNotes.h"
13 #include "mgr/StoreToCommWriter.h"
14 #include "StoreClient.h"
18 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, StoreToCommWriter
);
21 Mgr::StoreToCommWriter::StoreToCommWriter(int aFd
, StoreEntry
* anEntry
):
22 AsyncJob("Mgr::StoreToCommWriter"),
23 fd(aFd
), entry(anEntry
), sc(NULL
), writeOffset(0), closer(NULL
)
25 debugs(16, 6, HERE
<< "FD " << fd
);
26 closer
= asyncCall(16, 5, "Mgr::StoreToCommWriter::noteCommClosed",
27 CommCbMemFunT
<StoreToCommWriter
, CommCloseCbParams
>(this, &StoreToCommWriter::noteCommClosed
));
28 comm_add_close_handler(fd
, closer
);
31 Mgr::StoreToCommWriter::~StoreToCommWriter()
39 /// closes our copy of the client HTTP connection socket
41 Mgr::StoreToCommWriter::close()
45 comm_remove_close_handler(fd
, closer
);
54 Mgr::StoreToCommWriter::start()
59 entry
->registerAbort(&StoreToCommWriter::Abort
, this);
60 sc
= storeClientListAdd(entry
, this);
63 // initiate the receive-from-store, write-to-comm sequence
68 Mgr::StoreToCommWriter::scheduleStoreCopy()
73 StoreIOBuffer
readBuf(sizeof(buffer
), writeOffset
, buffer
);
74 storeClientCopy(sc
, entry
, readBuf
, &NoteStoreCopied
, this);
78 Mgr::StoreToCommWriter::NoteStoreCopied(void* data
, StoreIOBuffer ioBuf
)
81 // make sync Store call async to get async call protections and features
82 StoreToCommWriter
* writer
= static_cast<StoreToCommWriter
*>(data
);
83 typedef UnaryMemFunT
<StoreToCommWriter
, StoreIOBuffer
> MyDialer
;
84 AsyncCall::Pointer call
=
85 asyncCall(16, 5, "Mgr::StoreToCommWriter::noteStoreCopied",
86 MyDialer(writer
, &StoreToCommWriter::noteStoreCopied
, ioBuf
));
87 ScheduleCallHere(call
);
91 Mgr::StoreToCommWriter::noteStoreCopied(StoreIOBuffer ioBuf
)
94 Must(!ioBuf
.flags
.error
);
96 scheduleCommWrite(ioBuf
); // write received action results to client
98 Must(doneAll()); // otherwise, why would Store call us with no data?
102 Mgr::StoreToCommWriter::scheduleCommWrite(const StoreIOBuffer
& ioBuf
)
106 Must(ioBuf
.data
!= NULL
);
107 // write filled buffer
108 typedef CommCbMemFunT
<StoreToCommWriter
, CommIoCbParams
> MyDialer
;
109 AsyncCall::Pointer writer
=
110 asyncCall(16, 5, "Mgr::StoreToCommWriter::noteCommWrote",
111 MyDialer(this, &StoreToCommWriter::noteCommWrote
));
112 Comm::Write(fd
, ioBuf
.data
, ioBuf
.length
, writer
, NULL
);
116 Mgr::StoreToCommWriter::noteCommWrote(const CommIoCbParams
& params
)
119 Must(params
.flag
== COMM_OK
);
120 Must(params
.fd
== fd
);
121 Must(params
.size
!= 0);
122 writeOffset
+= params
.size
;
124 scheduleStoreCopy(); // retrieve the next data portion
128 Mgr::StoreToCommWriter::noteCommClosed(const CommCloseCbParams
& params
)
131 Must(fd
== params
.fd
);
133 mustStop("commClosed");
137 Mgr::StoreToCommWriter::swanSong()
142 storeUnregister(sc
, entry
, this);
145 entry
->unregisterAbort();
153 Mgr::StoreToCommWriter::doneAll() const
156 entry
->store_status
== STORE_OK
&& // the action is over
157 writeOffset
>= entry
->objectLen(); // we wrote all the results
161 Mgr::StoreToCommWriter::Abort(void* param
)
163 StoreToCommWriter
* mgrWriter
= static_cast<StoreToCommWriter
*>(param
);
164 if (mgrWriter
->fd
>= 0)
165 comm_close(mgrWriter
->fd
);