File: enet.h

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (95 lines) | stat: -rw-r--r-- 4,538 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef BACKENDS_NETWORKING_ENET_ENET_H
#define BACKENDS_NETWORKING_ENET_ENET_H

#include "common/str.h"

namespace Networking {

class Host;
class Socket;

class ENet {
public:
	/**
	 * The main object that allows for ENet host and socket creation.
	 */
	ENet();
	~ENet();

	/**
	 * Initializes the ENet library.  Must be called first before any other functions.
	 * @return true if successful, false on failure.
	 */
	bool initialize();
	/**
	 * Creates a new ENet Host instance for listening for/connecting to peers.
	 * @param address the address at which other peers may connect to this host.  "0.0.0.0" may be to used to use the default host.
	 * @param port a port number this host will use.
	 * @param numClients the maximum number of peers that should be allocated for the host.
	 * @param numChannels the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
	 * @param incBand downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
	 * @param outBand upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
	 * @retval Networking::Host object on success
	 * @retval nullptr on failure
	 * @see Networking::Host
	 */
	Host *createHost(const Common::String &address, int port, int numClients, int numChannels = 1, int incBand = 0, int outBand = 0);
	/**
	 * Creates a new ENet Host instance, and attempts to connect to the assigned address and port.
	 * @param hostAddress the address this host will use to connect to this peer.  "0.0.0.0" may be to used to use the default host.
	 * @param hostPort a port number this host will use.  If not used, the host will use an allocated port given by the operating system.
	 * @param address the address of the peer that will attempt to connect to.
	 * @param port the port number of the peer that will attempt to connect to.
	 * @param timeout specifies the connection timeout in milliseconds, 5 full seconds by default.  Will fail if the given time has passed.
	 * @param numChannels the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT. This must match with the connecting peer.
	 * @param incBand downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. This must match with the connecting peer.
	 * @param outBand upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. This must match with the connecting peer.
	 * @retval Networking::Host object on success
	 * @retval nullptr on failure
	 * @see Networking::Host
	 */
	Host *connectToHost(const Common::String &hostAddress, int hostPort, const Common::String &address, int port, int timeout = 5000, int numChannels = 1, int incBand = 0, int outBand = 0);
	Host *connectToHost(const Common::String &address, int port, int timeout = 5000, int numChannels = 1, int incBand = 0, int outBand = 0);
	/**
	 * Creates a Networking::Socket instance which is a representation of a raw UDP socket.
	 * Useful for and sending and receiving data that is outside the ENet library protocol.
	 * @param address the address this socket will send to and/or receive data from.
	 * @param port the port number this socket will send to and/or receive data from.
	 * @retval Networking::Socket object on success
	 * @retval nullptr on failure
	 * @see Networking::Socket
	 */
	Socket *createSocket(const Common::String &address, int port);
private:
	/** 
	 * Indicates if the ENet library has successfully initialized or not.
	 * @see initialize()
	 */
	bool _initialized;
};

} // End of namespace Networking


#endif