MCPcopy Create free account
hub / github.com/ddnet/ddnet / Recv

Method Recv

src/engine/shared/network_client.cpp:74–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74int CNetClient::Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken, bool Sixup)
75{
76 while(true)
77 {
78 // Unpack next chunk from stored packet if available
79 if(m_PacketChunkUnpacker.UnpackNextChunk(pChunk))
80 return 1;
81
82 // TODO: empty the recvinfo
83 NETADDR Addr;
84 unsigned char *pData;
85 int Bytes = net_udp_recv(m_Socket, &Addr, &pData);
86
87 // no more packets for now
88 if(Bytes <= 0)
89 break;
90
91 if(m_pStun->OnPacket(Addr, pData, Bytes))
92 {
93 continue;
94 }
95
96 SECURITY_TOKEN Token;
97 *pResponseToken = NET_SECURITY_TOKEN_UNKNOWN;
98 if(CNetBase::UnpackPacket(pData, Bytes, &m_RecvBuffer, Sixup, &Token, pResponseToken) == 0)
99 {
100 if(Sixup)
101 {
102 Addr.type |= NETTYPE_TW7;
103 }
104 if(m_RecvBuffer.m_Flags & NET_PACKETFLAG_CONNLESS)
105 {
106 pChunk->m_Flags = NETSENDFLAG_CONNLESS;
107 pChunk->m_ClientId = -1;
108 pChunk->m_Address = Addr;
109 pChunk->m_DataSize = m_RecvBuffer.m_DataSize;
110 pChunk->m_pData = m_RecvBuffer.m_aChunkData;
111 if(m_RecvBuffer.m_Flags & NET_PACKETFLAG_EXTENDED)
112 {
113 pChunk->m_Flags |= NETSENDFLAG_EXTENDED;
114 mem_copy(pChunk->m_aExtraData, m_RecvBuffer.m_aExtraData, sizeof(pChunk->m_aExtraData));
115 }
116 return 1;
117 }
118 else
119 {
120 const bool Control = (m_RecvBuffer.m_Flags & NET_PACKETFLAG_CONTROL) != 0;
121 if(Sixup &&
122 Control &&
123 m_RecvBuffer.m_DataSize >= 1 + (int)sizeof(SECURITY_TOKEN) &&
124 m_RecvBuffer.m_aChunkData[0] == protocol7::NET_CTRLMSG_TOKEN)
125 {
126 m_TokenCache.AddToken(&Addr, *pResponseToken);
127 }
128 if(m_Connection.State() != CNetConnection::EState::OFFLINE &&
129 m_Connection.State() != CNetConnection::EState::ERROR &&
130 m_Connection.Feed(&m_RecvBuffer, &Addr, Token, *pResponseToken))
131 {

Callers

nothing calls this directly

Calls 8

net_udp_recvFunction · 0.85
mem_copyFunction · 0.85
UnpackNextChunkMethod · 0.80
AddTokenMethod · 0.80
FeedMethod · 0.80
FeedPacketMethod · 0.80
OnPacketMethod · 0.45
StateMethod · 0.45

Tested by

no test coverage detected