3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
24 #include "exceptions.h"
26 extern bool socket_enable_debug_output;
28 class SocketException : public BaseException
31 SocketException(const char *s):
37 class ResolveError : public BaseException
40 ResolveError(const char *s):
46 class SendFailedException : public BaseException
49 SendFailedException(const char *s):
56 void sockets_cleanup();
62 Address(unsigned int address, unsigned short port);
63 Address(unsigned int a, unsigned int b,
64 unsigned int c, unsigned int d,
66 bool operator==(Address &address);
67 bool operator!=(Address &address);
68 void Resolve(const char *name);
69 unsigned int getAddress() const;
70 unsigned short getPort() const;
71 void setAddress(unsigned int address);
72 void setAddress(unsigned int a, unsigned int b,
73 unsigned int c, unsigned int d);
74 void setPort(unsigned short port);
75 void print(std::ostream *s) const;
77 std::string serializeString() const;
79 unsigned int m_address;
80 unsigned short m_port;
88 void Bind(unsigned short port);
91 void Send(const Address & destination, const void * data, int size);
92 // Returns -1 if there is no data
93 int Receive(Address & sender, void * data, int size);
94 int GetHandle(); // For debugging purposes only
95 void setTimeoutMs(int timeout_ms);
96 // Returns true if there is data, false if timeout occurred
97 bool WaitData(int timeout_ms);