MCPcopy Create free account
hub / github.com/Helidium/Mitol / onWriteData

Method onWriteData

src/Server.cpp:158–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158void MNS::Server::onWriteData(uv_poll_t *handle, int status, int events) {
159 MNS::SocketData *data = static_cast<MNS::SocketData *>(handle->data);
160
161 if (status < 0) {
162 if (errno != EAGAIN) {
163 uv_poll_stop(handle);
164 uv_close((uv_handle_t *) handle, MNS::Server::onClose);
165 return;
166 }
167 }
168
169 if (data) {
170 MNS::Response *response = data->response;
171
172 ssize_t numSent = send(data->fd, response->getBuffer(), response->getBufferLen(), 0);
173 if (numSent == (int) response->getBufferLen()) {
174 response->clear();
175
176 if (data->request->isFinished()) {
177 data->request->clear();
178 if(!uv_is_closing((uv_handle_t*)handle))
179 uv_poll_start(handle, UV_READABLE, onReadData);
180 } else {
181 // Request not finished, pipelining, continue serving data
182 if(!uv_is_closing((uv_handle_t*)handle))
183 uv_poll_start(handle, UV_WRITABLE, onReadDataPipelined);
184 //onReadDataPipelined(handle, 0, 0);
185 }
186 } else if (numSent < 0) {
187 int err = errno;
188
189 if (err != EAGAIN) {
190 uv_poll_stop(handle);
191 uv_close((uv_handle_t *) handle, MNS::Server::onClose);
192 return;
193 }
194 }
195
196 }
197}
198
199MNS::Server::Server() {
200 MNS::Server::response_msgs[200] = "200 OK\r\n";

Callers

nothing calls this directly

Calls 4

isFinishedMethod · 0.80
getBufferMethod · 0.45
getBufferLenMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected