From 6675ebd2964af48410a4843784b092026101de87 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sat, 9 Jun 2018 16:52:38 +0200 Subject: Change connection type to tcp, perhaps udt requires that --- src/DirectConnection.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 6872c27..ede5251 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -39,10 +39,10 @@ namespace sibs UDT::cleanup(); } - int DirectConnections::createSocket(const Ipv4 &addressToBind, bool rendezvous, bool reuseAddr) + int DirectConnections::createSocket(const Ipv4 &addressToBind, bool rendezvous, bool reuseAddr, bool bind) { Log::debug("UDT: Creating socket for ipv4 address %s, port: %d", addressToBind.getAddress().c_str(), addressToBind.getPort()); - UDTSOCKET socket = UDT::socket(AF_INET, SOCK_STREAM, IPPROTO_UDP); + UDTSOCKET socket = UDT::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(socket == UDT::INVALID_SOCK) { std::string errMsg = "UDT: Failed to create socket, error: "; @@ -60,11 +60,14 @@ namespace sibs UDT::setsockopt(socket, 0, UDT_MSS, &mss, sizeof(mss)); #endif - if(UDT::bind(socket, (sockaddr*)&addressToBind.address, sizeof(addressToBind.address)) == UDT::ERROR) + if(bind) { - std::string errMsg = "UDT: Failed to bind, error: "; - errMsg += UDT::getlasterror_desc(); - throw SocketCreateException(errMsg); + if(UDT::bind(socket, (sockaddr*)&addressToBind.address, sizeof(addressToBind.address)) == UDT::ERROR) + { + std::string errMsg = "UDT: Failed to bind, error: "; + errMsg += UDT::getlasterror_desc(); + throw SocketCreateException(errMsg); + } } return socket; @@ -88,7 +91,7 @@ namespace sibs UDTSOCKET socket; try { - socket = createSocket(Ipv4(nullptr, port), rendezvous, reuseAddr); + socket = createSocket(Ipv4(nullptr, port), rendezvous, reuseAddr, false); } catch(SocketCreateException &e) { @@ -158,16 +161,21 @@ namespace sibs std::vector data; data.reserve(MAX_RECEIVED_DATA_SIZE); + Log::debug("DirectConnections::recieveData(): waiting for events"); std::set readfds; while(alive) { - int numfsReady = UDT::epoll_wait(eid, &readfds, nullptr, 250); + int numfsReady = UDT::epoll_wait(eid, &readfds, nullptr, 1000); if(numfsReady == 0) + { continue; + } else if(numfsReady == -1) { if(UDT::getlasterror_code() == UDT::ERRORINFO::ETIMEOUT) + { continue; + } else { Log::error("UDT: Stop receiving data, got error: %s", UDT::getlasterror_desc()); -- cgit v1.2.3