summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/ipc/rtc_tcp_server.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-04-10 14:02:31 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-04-10 17:03:51 +0200
commitffbe0c66becfa5cf65aca3fef451cf162b251b4b (patch)
tree577722328262e22472133225072fd0a6a57018b3 /src/osd/modules/ipc/rtc_tcp_server.cpp
parentdd89b30c63a9d4a426d1be88a55a88c6c0109047 (diff)
Basic TCP server based on libuv [Inaki Baz Castillo,Miodrag Milanovic]
Diffstat (limited to 'src/osd/modules/ipc/rtc_tcp_server.cpp')
-rw-r--r--src/osd/modules/ipc/rtc_tcp_server.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/osd/modules/ipc/rtc_tcp_server.cpp b/src/osd/modules/ipc/rtc_tcp_server.cpp
new file mode 100644
index 00000000000..52345454983
--- /dev/null
+++ b/src/osd/modules/ipc/rtc_tcp_server.cpp
@@ -0,0 +1,42 @@
+// license:BSD-3-Clause
+// copyright-holders:Inaki Baz Castillo,Miodrag Milanovic
+
+#include "rtc_tcp_server.h"
+#include <string>
+
+#define MAX_TCP_CONNECTIONS_PER_SERVER 10
+
+/* Instance methods. */
+
+rtc_tcp_server::rtc_tcp_server(uv_loop_t* loop, const std::string &ip, uint16_t port, int backlog, listener* listener, rtc_tcp_connection::listener* connListener) :
+ tcp_server(loop, ip, port, backlog),
+ m_listener(listener),
+ m_conn_listener(connListener)
+{
+}
+
+void rtc_tcp_server::user_on_tcp_connection_alloc(tcp_connection** connection)
+{
+ // Allocate a new rtc_tcp_connection for the rtc_tcp_server to handle it.
+ *connection = new rtc_tcp_connection(m_conn_listener, 65536);
+}
+
+void rtc_tcp_server::user_on_new_tcp_connection(tcp_connection* connection)
+{
+ // Allow just MAX_TCP_CONNECTIONS_PER_SERVER.
+ if (get_num_connections() > MAX_TCP_CONNECTIONS_PER_SERVER)
+ connection->close();
+}
+
+void rtc_tcp_server::user_on_tcp_connection_closed(tcp_connection* connection, bool is_closed_by_peer)
+{
+ // Notify the listener.
+ // NOTE: Don't do it if closing (since at this point the listener is already freed).
+ // At the end, this is just called if the connection was remotely closed.
+ if (!is_closing())
+ m_listener->on_rtc_tcp_connection_closed(this, static_cast<rtc_tcp_connection*>(connection), is_closed_by_peer);
+}
+
+void rtc_tcp_server::user_on_tcp_server_closed()
+{
+}