MCPcopy Create free account
hub / github.com/SpartanJ/eepp / receive

Method receive

src/eepp/network/udpsocket.cpp:83–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83Socket::Status UdpSocket::receive( void* data, std::size_t size, std::size_t& received,
84 IpAddress& remoteAddress, unsigned short& remotePort ) {
85 // First clear the variables to fill
86 received = 0;
87 remoteAddress = IpAddress();
88 remotePort = 0;
89
90 // Check the destination buffer
91 if ( !data ) {
92 Log::error( "Cannot receive data from the network (the destination buffer is invalid)" );
93 return Error;
94 }
95
96 // Data that will be filled with the other computer's address
97 sockaddr_in address = Private::SocketImpl::createAddress( INADDR_ANY, 0 );
98
99 // Receive a chunk of bytes
100 Private::SocketImpl::AddrLength addressSize = sizeof( address );
101 int sizeReceived = recvfrom( getHandle(), static_cast<char*>( data ), static_cast<int>( size ),
102 0, reinterpret_cast<sockaddr*>( &address ), &addressSize );
103
104 // Check for errors
105 if ( sizeReceived < 0 )
106 return Private::SocketImpl::getErrorStatus();
107
108 // Fill the sender information
109 received = static_cast<std::size_t>( sizeReceived );
110 remoteAddress = IpAddress( ntohl( address.sin_addr.s_addr ) );
111 remotePort = ntohs( address.sin_port );
112
113 return Done;
114}
115
116Socket::Status UdpSocket::send( Packet& packet, const IpAddress& remoteAddress,
117 unsigned short remotePort ) {

Callers

nothing calls this directly

Calls 6

errorFunction · 0.85
getHandleFunction · 0.85
IpAddressClass · 0.50
sizeMethod · 0.45
clearMethod · 0.45
onReceiveMethod · 0.45

Tested by

no test coverage detected