MCPcopy Create free account
hub / github.com/e2wugui/zeze / Send

Method Send

cxx/Net.cpp:860–913  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

858 }
859
860 void Socket::Send(const char* data, int offset, int length)
861 {
862 std::lock_guard<std::recursive_mutex> g(mutex);
863 activeSendTime = time(0);
864
865 bool noPendingSend = OutputBuffer->buffer.empty();
866 bool hasCodec = false;
867 if (OutputCodec.get())
868 {
869 OutputCodec->update((int8_t*)data, offset, length);
870 OutputCodec->flush();
871 data = OutputBuffer->buffer.data();
872 offset = 0;
873 length = (int)OutputBuffer->buffer.size();
874 hasCodec = true;
875 }
876
877 if (noPendingSend)
878 {
879 // try send direct
880 int rc = ::send(socket, data + offset, length, 0);
881 if (rc == -1)
882 {
883 if (false == platform_ignore_error_for_send())
884 {
885 std::exception senderr("send error");
886 this->Close(&senderr);
887 return;
888 }
889 rc = 0;
890 }
891
892 if (hasCodec)
893 {
894 OutputBuffer->buffer.erase(0, rc);
895 if (false == OutputBuffer->buffer.empty())
896 Selector::Instance->Select(This, Selector::OpWrite, 0);
897 return;
898 }
899 if (rc >= length)
900 {
901 return; // all send and hasn't Codec
902 }
903 // part send
904 offset += rc;
905 length -= rc;
906 OutputBuffer->buffer.append(data + offset, length);
907 Selector::Instance->Select(This, Selector::OpWrite, 0);
908 return;
909 }
910 // in sending
911 if (false == hasCodec) // 如果有Codec,那么将要发送的数据已经被处理(update)到buffer中,不需要再次添加。
912 OutputBuffer->buffer.append(data + offset, length);
913 }
914
915 inline void AssignAddressBytes(struct addrinfo* ai, std::string& out)
916 {

Callers 10

OnHandshakeDoneMethod · 0.45
OnSocketConnectedMethod · 0.45
sendCsMethod · 0.45
ProcessKeepAliveMethod · 0.45
Test2Method · 0.45
StartHandshakeMethod · 0.45
ProcessSHandshake0Method · 0.45
ProcessSHandshakeMethod · 0.45
SendProtocolMethod · 0.45
SendFunction · 0.45

Calls 9

CloseMethod · 0.95
SelectMethod · 0.80
getMethod · 0.65
updateMethod · 0.65
flushMethod · 0.65
sizeMethod · 0.65
eraseMethod · 0.45
appendMethod · 0.45

Tested by 1

Test2Method · 0.36