Skip to content

Commit

Permalink
avoid regeneration of the SocketHandler when calling shutDown
Browse files Browse the repository at this point in the history
  • Loading branch information
andreacasalino committed Aug 7, 2024
1 parent 40fe0ab commit 05d1048
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/header/MinimalSocket/core/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ class Socket {
*/
bool isBlocking() const { return isBlocking_; }

void shutDown() { resetHandler(); }
/**
* @brief shutdown this socket. Any pending operation like blocking read or blocking client
* accept done from any other thread are consequently terminated.
*/
void shutDown();

protected:
Socket();
Expand Down
8 changes: 7 additions & 1 deletion src/src/SocketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ void close(SocketID &socket_id) {
}
} // namespace

SocketHandler::~SocketHandler() { MinimalSocket::close(socket_id); }
SocketHandler::~SocketHandler() {
MinimalSocket::close(socket_id);
}

void SocketHandler::shutDown() {
MinimalSocket::close(socket_id);
}

void SocketHandler::reset(SocketID hndl) {
if (socket_id != SCK_INVALID_SOCKET) {
Expand Down
4 changes: 3 additions & 1 deletion src/src/SocketHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ class SocketHandler {
SocketHandler() = default;

/**
* @brief close and shutdown the current socket
* @brief internally calls shut down
*/
~SocketHandler();

void shutDown();

/**
* @brief regenerates the socket descriptor, i.e. creates a new socket
*/
Expand Down
2 changes: 2 additions & 0 deletions src/src/core/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Socket::~Socket() = default;

Socket::Socket() { resetHandler(); }

void Socket::shutDown() { socket_id_wrapper->shutDown(); }

int Socket::getSocketDescriptor() const {
return static_cast<int>(getHandler().accessId());
}
Expand Down

0 comments on commit 05d1048

Please sign in to comment.