Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <ostream>
8#include <cstring>
9#include "address.h"
10#include "irrlichttypes.h"
11#include "networkexceptions.h"
12
13void sockets_init();
14void sockets_cleanup();
15
17{
18public:
19 UDPSocket() = default;
20 UDPSocket(bool ipv6); // calls init()
21 ~UDPSocket();
22 bool init(bool ipv6, bool noExceptions = false);
23
24 void Bind(Address addr);
25
26 void Send(const Address &destination, const void *data, int size);
27 // Returns -1 if there is no data
28 int Receive(Address &sender, void *data, int size);
29 void setTimeoutMs(int timeout_ms);
30 // Returns true if there is data, false if timeout occurred
31 bool WaitData(int timeout_ms);
32
33 // Debugging purposes only
34 int GetHandle() const { return m_handle; };
35
36private:
37 int m_handle = -1;
38 int m_timeout_ms = -1;
39 unsigned short m_addr_family = 0;
40};
Definition address.h:28
Definition socket.h:17
bool init(bool ipv6, bool noExceptions=false)
Definition socket.cpp:70
void Bind(Address addr)
Definition socket.cpp:123
int m_handle
Definition socket.h:37
void Send(const Address &destination, const void *data, int size)
Definition socket.cpp:163
int GetHandle() const
Definition socket.h:34
unsigned short m_addr_family
Definition socket.h:39
int m_timeout_ms
Definition socket.h:38
UDPSocket()=default
int Receive(Address &sender, void *data, int size)
Definition socket.cpp:203
void setTimeoutMs(int timeout_ms)
Definition socket.cpp:249
~UDPSocket()
Definition socket.cpp:112
bool WaitData(int timeout_ms)
Definition socket.cpp:254
void sockets_cleanup()
Definition socket.cpp:52
void sockets_init()
Definition socket.cpp:41