Skip to content

Commit

Permalink
Vutils
Browse files Browse the repository at this point in the history
  • Loading branch information
vic4key committed Nov 4, 2023
1 parent 81cd508 commit 1230ec0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/Vutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ class Socket : public LastError
VUResult vuapi accept(Handle& socket);

VUResult vuapi connect(const Endpoint& endpoint);
VUResult vuapi disconnect(const shutdowns_t flags = SD_BOTH);
VUResult vuapi disconnect(const shutdowns_t flags = SD_BOTH, const bool cleanup = true);

IResult vuapi send(const char* ptr_data, int size, const flags_t flags = MSG_NONE);
IResult vuapi send(const Buffer& data, const flags_t flags = MSG_NONE);
Expand Down Expand Up @@ -1382,7 +1382,7 @@ class AsyncSocket : public LastError
IResult vuapi close();

std::set<SOCKET> vuapi get_connections();
VUResult vuapi disconnect_connections(const Socket::shutdowns_t flags = SD_BOTH);
VUResult vuapi disconnect_connections(const Socket::shutdowns_t flags = SD_BOTH, const bool cleanup = true);

IResult vuapi send(const SOCKET& connection, const char* ptr_data, int size, const Socket::flags_t flags = MSG_NONE);
IResult vuapi send(const SOCKET& connection, const Buffer& data, const Socket::flags_t flags = MSG_NONE);
Expand Down
4 changes: 2 additions & 2 deletions src/details/asyncsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ std::set<SOCKET> vuapi AsyncSocket::get_connections()
return result;
}

VUResult vuapi AsyncSocket::disconnect_connections(const Socket::shutdowns_t flags)
VUResult vuapi AsyncSocket::disconnect_connections(const Socket::shutdowns_t flags, const bool cleanup)
{
auto connections = this->get_connections();
for (const auto& e : connections)
{
vu::Socket socket;
socket.attach(e);
socket.disconnect(flags);
socket.disconnect(flags, cleanup);
}

return VU_OK;
Expand Down
14 changes: 13 additions & 1 deletion src/details/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,31 @@ VUResult vuapi Socket::close()
return VU_OK;
}

VUResult vuapi Socket::disconnect(const shutdowns_t flags)
VUResult vuapi Socket::disconnect(const shutdowns_t flags, const bool cleanup)
{
if (!this->available())
{
return 1;
}

if (cleanup) // clean-up all remaining data in the socket
{
vu::Buffer temp;
this->recv_all(temp);
}

if (::shutdown(m_socket, flags) == SOCKET_ERROR)
{
m_last_error_code = GetLastError();
return 2;
}

if (closesocket(m_socket) == SOCKET_ERROR)
{
m_last_error_code = GetLastError();
return 3;
}

return VU_OK;
}

Expand Down

0 comments on commit 1230ec0

Please sign in to comment.