Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <ostream>
23#include <cstring>
24#include "address.h"
25#include "irrlichttypes.h"
26#include "networkexceptions.h"
27
29
30void sockets_init();
31void sockets_cleanup();
32
34{
35public:
36 UDPSocket() = default;
37 UDPSocket(bool ipv6); // calls init()
38 ~UDPSocket();
39 bool init(bool ipv6, bool noExceptions = false);
40
41 void Bind(Address addr);
42
43 void Send(const Address &destination, const void *data, int size);
44 // Returns -1 if there is no data
45 int Receive(Address &sender, void *data, int size);
46 void setTimeoutMs(int timeout_ms);
47 // Returns true if there is data, false if timeout occurred
48 bool WaitData(int timeout_ms);
49
50 // Debugging purposes only
51 int GetHandle() const { return m_handle; };
52
53private:
54 int m_handle = -1;
55 int m_timeout_ms = -1;
56 unsigned short m_addr_family = 0;
57};
Definition: address.h:43
Definition: socket.h:34
bool init(bool ipv6, bool noExceptions=false)
Definition: socket.cpp:88
void Bind(Address addr)
Definition: socket.cpp:152
int m_handle
Definition: socket.h:54
void Send(const Address &destination, const void *data, int size)
Definition: socket.cpp:198
int GetHandle() const
Definition: socket.h:51
unsigned short m_addr_family
Definition: socket.h:56
int m_timeout_ms
Definition: socket.h:55
UDPSocket()=default
int Receive(Address &sender, void *data, int size)
Definition: socket.cpp:262
void setTimeoutMs(int timeout_ms)
Definition: socket.cpp:328
~UDPSocket()
Definition: socket.cpp:136
bool WaitData(int timeout_ms)
Definition: socket.cpp:333
bool socket_enable_debug_output
Definition: socket.cpp:54
void sockets_cleanup()
Definition: socket.cpp:70
void sockets_init()
Definition: socket.cpp:59