1 /**
2 TCP Stream peer.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.streampeertcp;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.streampeer;
24 import godot.reference;
25 /**
26 TCP Stream peer.
27 
28 This object can be used to connect to TCP servers, or also is returned by a TCP server.
29 */
30 @GodotBaseClass struct StreamPeerTCP
31 {
32 	enum string _GODOT_internal_name = "StreamPeerTCP";
33 public:
34 @nogc nothrow:
35 	union { godot_object _godot_object; StreamPeer _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct _classBinding
40 	{
41 		__gshared:
42 		@GodotName("connect_to_host") GodotMethod!(GodotError, String, long) connectToHost;
43 		@GodotName("is_connected_to_host") GodotMethod!(bool) isConnectedToHost;
44 		@GodotName("get_status") GodotMethod!(StreamPeerTCP.Status) getStatus;
45 		@GodotName("get_connected_host") GodotMethod!(String) getConnectedHost;
46 		@GodotName("get_connected_port") GodotMethod!(long) getConnectedPort;
47 		@GodotName("disconnect_from_host") GodotMethod!(void) disconnectFromHost;
48 		@GodotName("set_no_delay") GodotMethod!(void, bool) setNoDelay;
49 	}
50 	bool opEquals(in StreamPeerTCP other) const { return _godot_object.ptr is other._godot_object.ptr; }
51 	StreamPeerTCP opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
52 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
53 	mixin baseCasts;
54 	static StreamPeerTCP _new()
55 	{
56 		static godot_class_constructor constructor;
57 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StreamPeerTCP");
58 		if(constructor is null) return typeof(this).init;
59 		return cast(StreamPeerTCP)(constructor());
60 	}
61 	@disable new(size_t s);
62 	/// 
63 	enum Status : int
64 	{
65 		/**
66 		The initial status of the `StreamPeerTCP`, also the status after a disconnect.
67 		*/
68 		statusNone = 0,
69 		/**
70 		A status representing a `StreamPeerTCP` that is connecting to a host.
71 		*/
72 		statusConnecting = 1,
73 		/**
74 		A status representing a `StreamPeerTCP` that is connected to a host.
75 		*/
76 		statusConnected = 2,
77 		/**
78 		A status representing a `StreamPeerTCP` in error state.
79 		*/
80 		statusError = 3,
81 	}
82 	/// 
83 	enum Constants : int
84 	{
85 		statusNone = 0,
86 		statusConnecting = 1,
87 		statusConnected = 2,
88 		statusError = 3,
89 	}
90 	/**
91 	Connect to the specified host:port pair. A hostname will be resolved if valid. Returns $(D OK) on success or $(D FAILED) on failure.
92 	*/
93 	GodotError connectToHost(StringArg0)(in StringArg0 host, in long port)
94 	{
95 		checkClassBinding!(typeof(this))();
96 		return ptrcall!(GodotError)(_classBinding.connectToHost, _godot_object, host, port);
97 	}
98 	/**
99 	Returns `true` if this peer is currently connected to a host, $(D code)false$(D code) otherwise.
100 	*/
101 	bool isConnectedToHost() const
102 	{
103 		checkClassBinding!(typeof(this))();
104 		return ptrcall!(bool)(_classBinding.isConnectedToHost, _godot_object);
105 	}
106 	/**
107 	Return the status of the connection, one of STATUS_* enum.
108 	*/
109 	StreamPeerTCP.Status getStatus()
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(StreamPeerTCP.Status)(_classBinding.getStatus, _godot_object);
113 	}
114 	/**
115 	Return the IP of this peer.
116 	*/
117 	String getConnectedHost() const
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(String)(_classBinding.getConnectedHost, _godot_object);
121 	}
122 	/**
123 	Return the port of this peer.
124 	*/
125 	long getConnectedPort() const
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(long)(_classBinding.getConnectedPort, _godot_object);
129 	}
130 	/**
131 	Disconnect from host.
132 	*/
133 	void disconnectFromHost()
134 	{
135 		checkClassBinding!(typeof(this))();
136 		ptrcall!(void)(_classBinding.disconnectFromHost, _godot_object);
137 	}
138 	/**
139 	Disable Nagle algorithm to improve latency for small packets.
140 	Note that for applications that send large packets, or need to transfer a lot of data, this can reduce total bandwidth.
141 	*/
142 	void setNoDelay(in bool enabled)
143 	{
144 		checkClassBinding!(typeof(this))();
145 		ptrcall!(void)(_classBinding.setNoDelay, _godot_object, enabled);
146 	}
147 }