48b4c725
Peter M. Groen
Setting up Socket-pp
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
datagram_socket::datagram_socket(const sock_address& addr)
{
auto domain = addr.family();
socket_t h = create_handle(domain);
if (check_socket_bool(h)) {
reset(h);
// TODO: If the bind fails, should we close the socket and fail completely?
bind(addr);
}
}
ssize_t datagram_socket::recv_from(void* buf, size_t n, int flags,
sock_address* srcAddr /*=nullptr*/)
{
sockaddr* p = srcAddr ? srcAddr->sockaddr_ptr() : nullptr;
socklen_t len = srcAddr ? srcAddr->size() : 0;
// TODO: Check returned length
#if defined(_WIN32)
return check_ret(::recvfrom(handle(), reinterpret_cast<char*>(buf),
int(n), flags, p, &len));
#else
return check_ret(::recvfrom(handle(), buf, n, flags, p, &len));
#endif
}
|