MCPcopy Create free account
hub / github.com/apache/trafficserver / load_buffer_and_write

Method load_buffer_and_write

src/iocore/net/UnixNetVConnection.cc:856–941  ·  view source on GitHub ↗

This code was pulled out of write_to_net so I could overwrite it for the SSL implementation (SSL read does not support overlapped i/o) without duplicating all the code in write_to_net.

Source from the content-addressed store, hash-verified

854// (SSL read does not support overlapped i/o)
855// without duplicating all the code in write_to_net.
856int64_t
857UnixNetVConnection::load_buffer_and_write(int64_t towrite, MIOBufferAccessor &buf, int64_t &total_written, int &needs)
858{
859 int64_t r = 0;
860 int64_t try_to_write = 0;
861 IOBufferReader *tmp_reader = buf.reader()->clone();
862
863 do {
864 IOVec tiovec[NET_MAX_IOV];
865 unsigned niov = 0;
866 try_to_write = 0;
867
868 while (niov < NET_MAX_IOV) {
869 int64_t wavail = towrite - total_written - try_to_write;
870 int64_t len = tmp_reader->block_read_avail();
871
872 // Check if we have done this block.
873 if (len <= 0) {
874 break;
875 }
876
877 // Check if the amount to write exceeds that in this buffer.
878 if (len > wavail) {
879 len = wavail;
880 }
881
882 if (len == 0) {
883 break;
884 }
885
886 // build an iov entry
887 tiovec[niov].iov_len = len;
888 tiovec[niov].iov_base = tmp_reader->start();
889 niov++;
890
891 try_to_write += len;
892 tmp_reader->consume(len);
893 }
894
895 ink_assert(niov > 0);
896 ink_assert(niov <= countof(tiovec));
897
898 // If the platform doesn't support TCP Fast Open, verify that we
899 // correctly disabled support in the socket option configuration.
900 ink_assert(MSG_FASTOPEN != 0 || this->options.f_tcp_fastopen == false);
901 struct msghdr msg;
902
903 ink_zero(msg);
904 if (!ats_is_unix(this->get_local_addr())) {
905 msg.msg_name = const_cast<sockaddr *>(this->get_remote_addr());
906 msg.msg_namelen = ats_ip_size(this->get_remote_addr());
907 }
908 msg.msg_iov = &tiovec[0];
909 msg.msg_iovlen = niov;
910 int flags = 0;
911
912 if (!this->con.is_connected && this->options.f_tcp_fastopen) {
913 Metrics::Counter::increment(net_rsb.fastopen_attempts);

Callers 1

net_write_ioMethod · 0.95

Calls 14

ink_zeroFunction · 0.85
ats_is_unixFunction · 0.85
ats_ip_sizeFunction · 0.85
incrementFunction · 0.85
block_read_availMethod · 0.80
sendmsgMethod · 0.80
countofFunction · 0.50
cloneMethod · 0.45
readerMethod · 0.45
startMethod · 0.45
consumeMethod · 0.45
get_local_addrMethod · 0.45

Tested by

no test coverage detected