| 156 | } |
| 157 | |
| 158 | void 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 | |
| 199 | MNS::Server::Server() { |
| 200 | MNS::Server::response_msgs[200] = "200 OK\r\n"; |
nothing calls this directly
no test coverage detected