Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarUdp.hpp
blob: 81d28a497529a7f0e2f69993997043850ec838d2 (plain)
1
2
3
4
5
6
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
34
35
36
37
38
39
40
41
#ifndef STAR_UDP_HPP
#define STAR_UDP_HPP

#include "StarSocket.hpp"

namespace Star {

STAR_CLASS(UdpSocket);
STAR_CLASS(UdpServer);

// A Good default assumption for a maximum size of a UDP datagram without
// fragmentation
unsigned const MaxUdpData = 1460;

class UdpSocket : public Socket {
public:
  UdpSocket(NetworkMode networkMode);

  size_t receive(HostAddressWithPort* address, char* data, size_t size);
  size_t send(HostAddressWithPort const& address, char const* data, size_t size);
};

class UdpServer {
public:
  UdpServer(HostAddressWithPort const& address);
  ~UdpServer();

  void close();
  bool isListening() const;

  size_t receive(HostAddressWithPort* address, char* data, size_t size, unsigned timeout);
  size_t send(HostAddressWithPort const& address, char const* data, size_t size);

private:
  HostAddressWithPort const m_hostAddress;
  UdpSocketPtr m_listenSocket;
};

}

#endif