Skip to content

Commit

Permalink
Added TCP socket (#45).
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jul 13, 2024
1 parent dd3fa68 commit 8797e03
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 1 deletion.
31 changes: 30 additions & 1 deletion xtransmit/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,36 @@ shared_sock_t create_connection(const vector<UriParser>& parsed_urls, shared_soc
return make_shared<socket::udp>(uri);
}

if (uri.type() == UriParser::SRT)
const auto uri_type = uri.type();

if (uri_type == UriParser::TCP)
{
const bool is_listening = !!listening_sock;
if (!is_listening)
listening_sock = make_shared<socket::tcp>(uri);
socket::tcp* s = dynamic_cast<socket::tcp*>(listening_sock.get());
const bool accept = !s->is_caller();
if (accept && !is_listening)
s->listen();
shared_sock_t connection;

try {
connection = accept ? s->accept() : s->connect();
}
catch (const socket::exception& e)
{
listening_sock.reset();
throw e;
}

// Only save the shared pointer for a listener to re-accept a connection.
if (!s->is_caller())
listening_sock.reset();

return connection;
}

if (uri_type == UriParser::SRT)
{
const bool is_listening = !!listening_sock;
if (!is_listening)
Expand Down
1 change: 1 addition & 0 deletions xtransmit/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "netaddr_any.hpp"
#include "srt_socket.hpp"
#include "udp_socket.hpp"
#include "tcp_socket.hpp"


namespace xtransmit {
Expand Down
Loading

0 comments on commit 8797e03

Please sign in to comment.