1 #include "otsdaq/NetworkUtilities/TCPSocket.h"
3 #include <sys/socket.h>
15 TCPSocket::~TCPSocket()
20 std::cout << __PRETTY_FUNCTION__ <<
"Clean close!" << std::endl;
36 void TCPSocket::open(
void)
38 if(fSocketId == invalidSocketId &&
39 (fSocketId = ::socket(AF_INET, SOCK_STREAM, 0)) == invalidSocketId)
40 throw std::runtime_error(std::string(
"Bad socket: ") + strerror(errno));
44 void TCPSocket::close(
void)
46 if(fSocketId == invalidSocketId)
48 throw std::logic_error(
"Bad socket object (this object was moved)");
50 int state = ::close(fSocketId);
51 std::cout << __PRETTY_FUNCTION__ <<
"Socket id: " << getSocketId()
52 <<
" close state: " << state <<
" errno: " << errno << std::endl;
54 fSocketId = invalidSocketId;
60 throw std::domain_error(std::string(
"Close: EBADF: ") +
61 std::to_string(fSocketId) +
" " + strerror(errno));
63 throw std::runtime_error(std::string(
"Close: EIO: ") +
64 std::to_string(fSocketId) +
" " + strerror(errno));
72 throw std::runtime_error(std::string(
"Close: ???: ") +
73 std::to_string(fSocketId) +
" " + strerror(errno));
82 swap(fSocketId, other.fSocketId);
96 void TCPSocket::sendClose()
98 if(::shutdown(getSocketId(), SHUT_WR) != 0)
100 throw std::domain_error(std::string(
"Shutdown: critical error: ") +
TCPSocket(int socketId=invalidSocketId)
Designed to be a base class not used used directly.