void PluginVC::process_write_side() This function may only be called while holding this->mutex & while it is ok to callback the write side continuation Does write side processing directly to other read side writer
| 477 | // Does write side processing directly to other read side writer |
| 478 | // |
| 479 | void |
| 480 | PluginVC::process_write_side() |
| 481 | { |
| 482 | ink_assert(!deletable); |
| 483 | ink_assert(magic == PLUGIN_VC_MAGIC_ALIVE); |
| 484 | |
| 485 | Dbg(dbg_ctl_pvc, "[%u] %s: process_write_side", core_obj->id, PVC_TYPE); |
| 486 | need_write_process = false; |
| 487 | |
| 488 | // Check write_state |
| 489 | if (write_state.vio.cont == nullptr || write_state.vio.op != VIO::WRITE || closed || write_state.shutdown) { |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | // Check the state of our write buffer as well as ntodo |
| 494 | int64_t ntodo = write_state.vio.ntodo(); |
| 495 | if (ntodo == 0) { |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | IOBufferReader *reader = write_state.vio.get_reader(); |
| 500 | if (reader == nullptr) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | int64_t bytes_avail = reader->read_avail(); |
| 505 | int64_t act_on = std::min(bytes_avail, ntodo); |
| 506 | |
| 507 | Dbg(dbg_ctl_pvc, "[%u] %s: process_write_side; act_on %" PRId64 "", core_obj->id, PVC_TYPE, act_on); |
| 508 | |
| 509 | // Check read_state of other side |
| 510 | if (other_side->read_state.vio.op != VIO::READ || other_side->closed || other_side->read_state.shutdown) { |
| 511 | write_state.vio.cont->handleEvent(VC_EVENT_ERROR, &write_state.vio); |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | if (act_on <= 0) { |
| 516 | if (ntodo > 0) { |
| 517 | // Notify the continuation that we are "disabling" |
| 518 | // ourselves due to nothing to write |
| 519 | write_state.vio.cont->handleEvent(VC_EVENT_WRITE_READY, &write_state.vio); |
| 520 | } |
| 521 | return; |
| 522 | } |
| 523 | |
| 524 | // Check the state of the other side read buffer as well as ntodo |
| 525 | int64_t other_ntodo = other_side->read_state.vio.ntodo(); |
| 526 | if (other_ntodo == 0) { |
| 527 | return; |
| 528 | } |
| 529 | act_on = std::min(act_on, other_ntodo); |
| 530 | |
| 531 | // Other side read_state is open |
| 532 | // obtain the proper mutexes on other side |
| 533 | EThread *my_ethread = mutex->thread_holding; |
| 534 | ink_assert(my_ethread != nullptr); |
| 535 | MUTEX_TRY_LOCK(lock, other_side->read_state.vio.mutex, my_ethread); |
| 536 | if (!lock.is_locked()) { |
no test coverage detected