MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / ReadFrom

Method ReadFrom

sourcecommon/udp.cpp:416–472  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

414}
415//---------------------------------------------------------------------------
416bool TUDP::ReadFrom(void * data, int size, struct sockaddr * p, bool bPeek)
417{
418 WSAError = 0;
419 Error = 0;
420 bytes = 0;
421
422 if( !handle || size<=0 )
423 {
424 WSAError = MYERROR_UNKNOWNPARAMS;
425 Error = 1;
426 if( Exceptions ) throw 0;
427 return !Error;
428 }
429 // ������� �������� �������� ������
430 if( bBlockProtected )
431 {
432 DWORD bufsize;
433 if( ioctlsocket(handle, FIONREAD, &bufsize) == SOCKET_ERROR )
434 {
435 WSAError = WSAGetLastError();
436 Error = 2;
437 if( Exceptions ) throw 0;
438 return !Error;
439 }
440 if( bufsize < (DWORD)size )
441 {
442 WSAError = MYERROR_NOREQSIZE;
443 Error = 3;
444 if( Exceptions ) throw 0;
445 return !Error;
446 }
447 }
448
449 int fromlen = sizeof(struct sockaddr);
450 bytes = recvfrom(handle, (char *)data, size, bPeek ? MSG_PEEK : 0, p, &fromlen);
451 if( bytes==SOCKET_ERROR )
452 {
453 WSAError = WSAGetLastError();
454 Error = 4;
455 bytes = 0;
456 if( Exceptions ) throw 0;
457 return !Error;
458 }
459 if( bytes != size )
460 {
461 // ������ ����������, ����� � �������� ������ ��������� UPD �������
462 // �������� UDP ������ ����� ������ �� ������
463 // ������� ����� ��������� ������ ������ bytes < size
464 // ReadLength() ���� ��������� ������ ���� ������� � �������� ������
465 WSAError = MYERROR_READCOUNT;
466 Error = 5;
467 if( Exceptions ) throw 0;
468 return !Error;
469 }
470 InBytes += bytes;
471 return ! Error;
472}
473//---------------------------------------------------------------------------

Callers 1

UdpReceiveMessageFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected