summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/UDPEndpointImpl.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-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);
+};
+
+
+
+