Add TCP support #12

Merged
Persson-dev merged 12 commits from tcp into main 2025-03-03 10:04:42 +00:00
2 changed files with 7 additions and 3 deletions
Showing only changes of commit 643da71e34 - Show all commits

View File

@@ -41,6 +41,7 @@ class IOInterface<TcpTag> : private NonCopyable {
IOInterface();
IOInterface(const std::string& a_Host, std::uint16_t a_Port);
IOInterface(IOInterface&& a_Other);
IOInterface& operator=(IOInterface&& a_Other);
virtual ~IOInterface();
DataBuffer Read(std::size_t a_Amount);

View File

@@ -91,7 +91,8 @@ DataBuffer TcpSocket::Read(std::size_t a_Amount) {
std::size_t totalRecieved = 0;
while (totalRecieved < a_Amount) {
int recvAmount = recv(m_Handle, reinterpret_cast<char*>(buffer.data() + totalRecieved), static_cast<int>(a_Amount - totalRecieved), 0);
int recvAmount =
recv(m_Handle, reinterpret_cast<char*>(buffer.data() + totalRecieved), static_cast<int>(a_Amount - totalRecieved), 0);
if (recvAmount <= 0) {
#if defined(_WIN32) || defined(WIN32)
int err = WSAGetLastError();
@@ -150,8 +151,10 @@ void TcpSocket::Disconnect() {
m_Status = Status::Disconnected;
}
TcpSocket& TcpSocket::operator=(IOInterface&& a_Other) {
std::swap(m_Handle, a_Other.m_Handle);
std::swap(m_Status, a_Other.m_Status);
}
} // namespace io
} // namespace sp