summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/UDPEndpointImpl.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2015-03-09 22:39:11 +0100
committerHowaner <franzi.moos@googlemail.com>2015-03-09 22:39:11 +0100
commita96c21fc0d4326ffda93cc78c5dfcfc4bd034e24 (patch)
tree38dba8f86163283d90d1d6d9d2fa420cb4e99231 /src/OSSupport/UDPEndpointImpl.h
parentReadded old comment (diff)
parentFixed client kick/crash if many block changes happend (diff)
downloadcuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar.gz
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar.bz2
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar.lz
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar.xz
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.tar.zst
cuberite-a96c21fc0d4326ffda93cc78c5dfcfc4bd034e24.zip
Diffstat (limited to 'src/OSSupport/UDPEndpointImpl.h')
-rw-r--r--src/OSSupport/UDPEndpointImpl.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/OSSupport/UDPEndpointImpl.h b/src/OSSupport/UDPEndpointImpl.h
new file mode 100644
index 000000000..75942b0cf
--- /dev/null
+++ b/src/OSSupport/UDPEndpointImpl.h
@@ -0,0 +1,81 @@
+
+// UDPEndpointImpl.h
+
+// Declares the cUDPEndpointImpl class representing an implementation of an endpoint in UDP communication
+
+
+
+
+
+#pragma once
+
+#include "Network.h"
+#include <event2/event.h>
+
+
+
+
+
+// fwd:
+class cUDPEndpointImpl;
+typedef SharedPtr<cUDPEndpointImpl> cUDPEndpointImplPtr;
+
+
+
+
+
+class cUDPEndpointImpl:
+ public cUDPEndpoint
+{
+ typedef cUDPEndpoint super;
+
+public:
+ /** Creates a new instance of the endpoint, with the specified callbacks.
+ Tries to open on the specified port; if it fails, the endpoint is left in the "closed" state.
+ If a_Port is 0, the OS is free to assign any port number it likes to the endpoint. */
+ cUDPEndpointImpl(UInt16 a_Port, cUDPEndpoint::cCallbacks & a_Callbacks);
+
+ // cUDPEndpoint overrides:
+ virtual void Close(void) override;
+ virtual bool IsOpen(void) const override;
+ virtual UInt16 GetPort(void) const override;
+ virtual bool Send(const AString & a_Payload, const AString & a_Host, UInt16 a_Port) override;
+ virtual void EnableBroadcasts(void) override;
+
+protected:
+ /** The local port on which the endpoint is open.
+ If this is zero, it means the endpoint is closed - either opening has failed, or it has been closed explicitly. */
+ UInt16 m_Port;
+
+ /** The primary underlying OS socket. */
+ evutil_socket_t m_MainSock;
+
+ /** True if m_MainSock is in the IPv6 namespace (needs IPv6 addresses for sending). */
+ bool m_IsMainSockIPv6;
+
+ /** The secondary OS socket (if primary doesn't support dualstack). */
+ evutil_socket_t m_SecondarySock;
+
+ /** The LibEvent handle for the primary socket. */
+ event * m_MainEvent;
+
+ /** The LibEvent handle for the secondary socket. */
+ event * m_SecondaryEvent;
+
+
+ /** Creates and opens the socket on the specified port.
+ If a_Port is 0, the OS is free to assign any port number it likes to the endpoint.
+ If the opening fails, the OnError() callback is called and the endpoint is left "closed" (IsOpen() returns false). */
+ void Open(UInt16 a_Port);
+
+ /** The callback that LibEvent calls when an event occurs on one of the sockets.
+ Calls Callback() on a_Self. */
+ static void RawCallback(evutil_socket_t a_Socket, short a_What, void * a_Self);
+
+ /** The callback that is called when an event occurs on one of the sockets. */
+ void Callback(evutil_socket_t a_Socket, short a_What);
+};
+
+
+
+