This commit is contained in:
Angelos Katharopoulos
2025-10-15 00:32:22 -07:00
parent 97f74543b1
commit 031e62539a
3 changed files with 25 additions and 16 deletions

View File

@@ -336,7 +336,7 @@ std::vector<int> accept_connections(
for (auto& address : addresses) {
detail::TCPSocket socket(RING_TAG);
socket.listen(RING_TAG, address);
sockets.push_back(socket.accept(RING_TAG));
sockets.push_back(socket.accept(RING_TAG).detach());
}
return sockets;
@@ -354,21 +354,22 @@ std::vector<int> make_connections(
for (auto& address : addresses) {
sockets.push_back(detail::TCPSocket::connect(
RING_TAG,
address,
CONN_ATTEMPTS,
CONN_WAIT,
[verbose](int attempt, int wait) {
log_info(
verbose,
"Attempt",
attempt,
"waiting",
wait,
"ms (error:",
errno,
")");
}));
RING_TAG,
address,
CONN_ATTEMPTS,
CONN_WAIT,
[verbose](int attempt, int wait) {
log_info(
verbose,
"Attempt",
attempt,
"waiting",
wait,
"ms (error:",
errno,
")");
})
.detach());
}
return sockets;

View File

@@ -80,6 +80,12 @@ TCPSocket::~TCPSocket() {
}
}
int TCPSocket::detach() {
int s = sock_;
sock_ = -1;
return s;
}
void TCPSocket::listen(const char* tag, const address_t& addr) {
int success;

View File

@@ -43,6 +43,8 @@ class TCPSocket {
void send(const char* tag, const void* data, size_t len);
void recv(const char* tag, void* data, size_t len);
int detach();
operator int() const {
return sock_;
}