1 #include "platform_api.h"
2 #include <msp/core/systemerror.h>
3 #include <msp/io/handle_private.h>
4 #include <msp/strings/format.h>
5 #include "datagramsocket.h"
6 #include "sockaddr_private.h"
7 #include "socket_private.h"
12 DatagramSocket::DatagramSocket(Family f, int p):
13 ClientSocket(f, SOCK_DGRAM, p)
15 set_socket_events(S_INPUT);
18 bool DatagramSocket::connect(const SockAddr &addr)
20 SockAddr::SysAddr sa = addr.to_sys();
21 check_sys_connect_error(::connect(priv->handle, reinterpret_cast<const sockaddr *>(&sa.addr), sa.size));
24 peer_addr = addr.copy();
27 SockAddr::SysAddr lsa;
28 getsockname(priv->handle, reinterpret_cast<sockaddr *>(&lsa.addr), &lsa.size);
29 local_addr = SockAddr::new_from_sys(lsa);
36 unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &addr)
41 SockAddr::SysAddr sa = addr.to_sys();
42 return check_sys_error(::sendto(priv->handle, buf, size, 0, reinterpret_cast<const sockaddr *>(&sa.addr), sa.size), "sendto");
45 unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&from_addr)
51 unsigned ret = check_sys_error(::recvfrom(priv->handle, buf, size, 0, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size), "recvfrom");
52 from_addr = SockAddr::new_from_sys(sa);