| 280 | } |
| 281 | |
| 282 | static int |
| 283 | serverIntercept(TSCont contp, TSEvent event, void *edata) |
| 284 | { |
| 285 | Dbg(dbg_ctl, "[%s] Received event: %d", __FUNCTION__, static_cast<int>(event)); |
| 286 | |
| 287 | SContData *cont_data = static_cast<SContData *>(TSContDataGet(contp)); |
| 288 | bool read_complete = false; |
| 289 | bool shutdown = false; |
| 290 | switch (event) { |
| 291 | case TS_EVENT_NET_ACCEPT: |
| 292 | Dbg(dbg_ctl, "[%s] Received net accept event", __FUNCTION__); |
| 293 | TSAssert(cont_data->initialized == false); |
| 294 | if (!cont_data->init(static_cast<TSVConn>(edata))) { |
| 295 | TSError("[server_intercept][%s] Could not initialize continuation data!", __FUNCTION__); |
| 296 | return 1; |
| 297 | } |
| 298 | break; |
| 299 | case TS_EVENT_VCONN_READ_READY: |
| 300 | Dbg(dbg_ctl, "[%s] Received read ready event", __FUNCTION__); |
| 301 | if (!handleRead(cont_data, read_complete)) { |
| 302 | TSError("[server_intercept][%s] Error while reading from input vio", __FUNCTION__); |
| 303 | return 0; |
| 304 | } |
| 305 | break; |
| 306 | case TS_EVENT_VCONN_READ_COMPLETE: |
| 307 | case TS_EVENT_VCONN_EOS: |
| 308 | // intentional fall-through |
| 309 | Dbg(dbg_ctl, "[%s] Received read complete/eos event %d", __FUNCTION__, event); |
| 310 | read_complete = true; |
| 311 | break; |
| 312 | case TS_EVENT_VCONN_WRITE_READY: |
| 313 | Dbg(dbg_ctl, "[%s] Received write ready event", __FUNCTION__); |
| 314 | break; |
| 315 | case TS_EVENT_VCONN_WRITE_COMPLETE: |
| 316 | Dbg(dbg_ctl, "[%s] Received write complete event", __FUNCTION__); |
| 317 | shutdown = true; |
| 318 | break; |
| 319 | case TS_EVENT_ERROR: |
| 320 | // todo: do some error handling here |
| 321 | TSError("[server_intercept][%s] Received error event; going to shutdown, event: %d", __FUNCTION__, event); |
| 322 | shutdown = true; |
| 323 | break; |
| 324 | default: |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | if (read_complete) { |
| 329 | if (!processRequest(cont_data)) { |
| 330 | TSError("[server_intercept][%s] Failed to process process", __FUNCTION__); |
| 331 | } else { |
| 332 | Dbg(dbg_ctl, "[%s] Processed request successfully", __FUNCTION__); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (shutdown) { |
| 337 | Dbg(dbg_ctl, "[%s] Completed request processing. Shutting down...", __FUNCTION__); |
| 338 | if (cont_data->net_vc) { |
| 339 | TSVConnClose(cont_data->net_vc); |
nothing calls this directly
no test coverage detected