Advanced settings noiseparams: Remove '}' left in .conf
[oweals/minetest.git] / src / network / socket.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #ifdef _WIN32
23 #ifndef _WIN32_WINNT
24 #define _WIN32_WINNT 0x0501
25 #endif
26 #include <windows.h>
27 #include <winsock2.h>
28 #include <ws2tcpip.h>
29 #else
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #endif
33
34 #include <ostream>
35 #include <cstring>
36 #include "address.h"
37 #include "irrlichttypes.h"
38 #include "networkexceptions.h"
39
40 extern bool socket_enable_debug_output;
41
42 void sockets_init();
43 void sockets_cleanup();
44
45 class UDPSocket
46 {
47 public:
48         UDPSocket() = default;
49
50         UDPSocket(bool ipv6);
51         ~UDPSocket();
52         void Bind(Address addr);
53
54         bool init(bool ipv6, bool noExceptions = false);
55
56         // void Close();
57         // bool IsOpen();
58         void Send(const Address &destination, const void *data, int size);
59         // Returns -1 if there is no data
60         int Receive(Address &sender, void *data, int size);
61         int GetHandle(); // For debugging purposes only
62         void setTimeoutMs(int timeout_ms);
63         // Returns true if there is data, false if timeout occurred
64         bool WaitData(int timeout_ms);
65
66 private:
67         int m_handle;
68         int m_timeout_ms;
69         int m_addr_family;
70 };