Write the data for a UnixNetVConnection. Rescheduling the UnixNetVConnection when necessary.
| 633 | // Rescheduling the UnixNetVConnection when necessary. |
| 634 | // |
| 635 | void |
| 636 | UnixNetVConnection::net_write_io(NetHandler *nh) |
| 637 | { |
| 638 | Metrics::Counter::increment(net_rsb.calls_to_writetonet); |
| 639 | NetState *s = &this->write; |
| 640 | Continuation *c = this->write.vio.cont; |
| 641 | |
| 642 | if (c == nullptr) { |
| 643 | // If Continuation to callback is nullptr, we can do nothing |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | MUTEX_TRY_LOCK(lock, s->vio.mutex, thread); |
| 648 | |
| 649 | if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.get()) { |
| 650 | write_reschedule(nh, this); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | if (this->has_error()) { |
| 655 | this->lerrno = this->error; |
| 656 | write_signal_and_update(VC_EVENT_ERROR, this); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | // This function will always return true unless |
| 661 | // this vc is an SSLNetVConnection. |
| 662 | if (!this->getSSLHandShakeComplete()) { |
| 663 | if (this->trackFirstHandshake()) { |
| 664 | // Eat the first write-ready. Until the TLS handshake is complete, |
| 665 | // we should still be under the connect timeout and shouldn't bother |
| 666 | // the state machine until the TLS handshake is complete |
| 667 | this->write.triggered = 0; |
| 668 | nh->write_ready_list.remove(this); |
| 669 | } |
| 670 | |
| 671 | int err, ret; |
| 672 | |
| 673 | if (this->get_context() == NET_VCONNECTION_OUT) { |
| 674 | ret = this->sslStartHandShake(SSL_EVENT_CLIENT, err); |
| 675 | } else { |
| 676 | ret = this->sslStartHandShake(SSL_EVENT_SERVER, err); |
| 677 | } |
| 678 | |
| 679 | if (ret == EVENT_ERROR) { |
| 680 | this->write.triggered = 0; |
| 681 | write_signal_error(nh, this, err); |
| 682 | } else if (ret == SSL_HANDSHAKE_WANT_READ || ret == SSL_HANDSHAKE_WANT_ACCEPT) { |
| 683 | this->read.triggered = 0; |
| 684 | nh->read_ready_list.remove(this); |
| 685 | read_reschedule(nh, this); |
| 686 | } else if (ret == SSL_HANDSHAKE_WANT_CONNECT || ret == SSL_HANDSHAKE_WANT_WRITE) { |
| 687 | this->write.triggered = 0; |
| 688 | nh->write_ready_list.remove(this); |
| 689 | write_reschedule(nh, this); |
| 690 | } else if (ret == EVENT_DONE) { |
| 691 | this->write.triggered = 1; |
| 692 | if (this->write.enabled) { |
no test coverage detected