| 410 | } |
| 411 | |
| 412 | size_t |
| 413 | TransformationPlugin::setOutputComplete() |
| 414 | { |
| 415 | if (state_->type_ == CLIENT_RESPONSE_SINK_TRANSFORMATION || state_->type_ == CLIENT_REQUEST_SINK_TRANSFORMATION) { |
| 416 | // There's no output stream for a sink transform, so we do nothing |
| 417 | // |
| 418 | // Warning: don't try to shutdown the VConn, since the default implementation (DummyVConnection) |
| 419 | // has a stubbed out shutdown/close implementation |
| 420 | return 0; |
| 421 | } else if (state_->type_ == REQUEST_TRANSFORMATION) { |
| 422 | doProduce(state_->request_xform_output_); |
| 423 | } |
| 424 | |
| 425 | int connection_closed = TSVConnClosedGet(state_->vconn_); |
| 426 | LOG_DEBUG("OutputComplete TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d, total bytes written=%" PRId64, this, |
| 427 | state_->txn_, state_->vconn_, connection_closed, state_->bytes_written_); |
| 428 | |
| 429 | if (!connection_closed && !state_->output_vio_) { |
| 430 | LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p output complete without writing any data, initiating write of 0 bytes.", this, |
| 431 | state_->txn_); |
| 432 | |
| 433 | // We're done without ever outputting anything, to correctly |
| 434 | // clean up we'll initiate a write then immediately set it to 0 bytes done. |
| 435 | state_->output_vio_ = TSVConnWrite(TSTransformOutputVConnGet(state_->vconn_), state_->vconn_, state_->output_buffer_reader_, 0); |
| 436 | |
| 437 | if (state_->output_vio_) { |
| 438 | TSVIONDoneSet(state_->output_vio_, 0); |
| 439 | TSVIOReenable(state_->output_vio_); // Wake up the downstream vio |
| 440 | } else { |
| 441 | LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p because VConnWrite failed.", this, |
| 442 | state_->txn_, state_->output_vio_); |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | if (!connection_closed) { |
| 449 | // So there is a possible race condition here, if we wake up a dead |
| 450 | // VIO it can cause a segfault, so we must check that the VCONN is not dead. |
| 451 | int connection_closed = TSVConnClosedGet(state_->vconn_); |
| 452 | if (!connection_closed) { |
| 453 | TSVIONBytesSet(state_->output_vio_, state_->bytes_written_); |
| 454 | TSVIOReenable(state_->output_vio_); // Wake up the downstream vio |
| 455 | } else { |
| 456 | LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, |
| 457 | state_->txn_, state_->output_vio_, connection_closed); |
| 458 | } |
| 459 | } else { |
| 460 | LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, state_->txn_, |
| 461 | state_->output_vio_, connection_closed); |
| 462 | } |
| 463 | |
| 464 | return state_->bytes_written_; |
| 465 | } |
nothing calls this directly
no test coverage detected