aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DirectConnection.cpp24
1 files changed, 16 insertions, 8 deletions
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<char> data;
data.reserve(MAX_RECEIVED_DATA_SIZE);
+ Log::debug("DirectConnections::recieveData(): waiting for events");
std::set<UDTSOCKET> 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());