diff --git a/srcs/DccClient.cpp b/srcs/DccClient.cpp index 86d98d9..ffa86e9 100644 --- a/srcs/DccClient.cpp +++ b/srcs/DccClient.cpp @@ -63,13 +63,8 @@ int DccClient::init() return (-1); } - if (fcntl(_sockfd, F_SETFL, O_NONBLOCK) < 0) - { - std::cerr << "Error: setting socket DCC Client non-blocking" << std::endl; - close(_sockfd); - _sockfd = -1; - return (-1); - } + int flags = fcntl(_sockfd, F_GETFL, 0); + fcntl(_sockfd, F_SETFL, flags | O_NONBLOCK); struct sockaddr_in serv_addr; memset(&serv_addr, 0, sizeof(serv_addr)); diff --git a/srcs/DccServer.cpp b/srcs/DccServer.cpp index 1f54e36..38769b5 100644 --- a/srcs/DccServer.cpp +++ b/srcs/DccServer.cpp @@ -42,12 +42,8 @@ int DccServer::init() } //config socket non-blocking - if (fcntl(_sockfd, F_SETFL, O_NONBLOCK) < 0) - { - std::cerr << "Error: setting socket DCC non-blocking" << std::endl; - close(_sockfd); - return (-1); - } + int flags = fcntl(_sockfd, F_GETFL, 0); + fcntl(_sockfd, F_SETFL, flags | O_NONBLOCK); //config address struct sockaddr_in addr; @@ -139,6 +135,3 @@ bool DccServer::handleConnection() std::cout << "File " << _filename << " sent successfully." << std::endl; return false; } - - -