MCPcopy Create free account
hub / github.com/catboost/catboost / RecvFrom

Method RecvFrom

library/cpp/netliba/v6/udp_socket.cpp:199–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197 }
198
199 bool TNetSocket::RecvFrom(char* buf, int* size, sockaddr_in6* fromAddress) const {
200 for (;;) {
201 int rv;
202 if (s->IsRecvMsgSupported()) {
203 const NNetlibaSocket::TIoVec v = NNetlibaSocket::CreateIoVec(buf, *size);
204 NNetlibaSocket::TMsgHdr hdr = NNetlibaSocket::CreateRecvMsgHdr(fromAddress, v);
205 rv = s->RecvMsg(&hdr, 0);
206
207 } else {
208 sockaddr_in6 dummy;
209 TAutoPtr<NNetlibaSocket::TUdpRecvPacket> pkt = s->Recv(fromAddress, &dummy, -1);
210 rv = !!pkt ? pkt->DataSize - pkt->DataStart : -1;
211 if (rv > 0) {
212 memcpy(buf, pkt->Data.get() + pkt->DataStart, rv);
213 }
214 }
215
216 if (rv < 0)
217 return false;
218 // ignore empty packets
219 if (rv == 0)
220 continue;
221 // skip small packets
222 if (rv < UDP_LOW_LEVEL_HEADER_SIZE)
223 continue;
224 *size = rv;
225 ui32 pktCrc = *(ui32*)buf;
226 ui32 crc = CalcChecksum(buf + UDP_LOW_LEVEL_HEADER_SIZE, rv - UDP_LOW_LEVEL_HEADER_SIZE);
227 if (!CrcMatches(pktCrc, crc + PortCrc, *fromAddress)) {
228 // crc is really failed, discard packet
229 continue;
230 }
231 return true;
232 }
233 }
234
235 void TNetSocket::Wait(float timeoutSec) const {
236 s->Wait(timeoutSec);

Callers 3

RecvCycleMethod · 0.45
RespondMethod · 0.45
RequestMethod · 0.45

Calls 8

CreateIoVecFunction · 0.85
CreateRecvMsgHdrFunction · 0.85
CrcMatchesFunction · 0.85
CalcChecksumFunction · 0.70
IsRecvMsgSupportedMethod · 0.45
RecvMsgMethod · 0.45
RecvMethod · 0.45
getMethod · 0.45

Tested by 2

RespondMethod · 0.36
RequestMethod · 0.36