ServerCore/TCPSocket.cpp
2022-10-17 20:03:23 -07:00

28 lines
804 B
C++

#include "TCPSocket.h"
#include "EPoll.h"
#include "Log.h"
#include "Exception.h"
#include "errno.h"
namespace core {
TCPSocket::TCPSocket(EPoll &ePoll) : Socket(ePoll) {}
TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {}
TCPSocket::~TCPSocket() {}
void TCPSocket::connect(IPAddress &address) {
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1)
throw coreutils::Exception("Error on connect to TCP socket." + errno);
coreutils::Log(coreutils::LOG_DEBUG_3) << "Connected to IP..." << address.getClientAddressAndPort();
}
void TCPSocket::output(std::stringstream &out) {
out << "|" << ipAddress.getClientAddressAndPort();
}
}