mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
refactor: peer-socket pt 2 (#4326)
* refactor: tr_netOpenPeerSocket() now takes a tr_address reference * refactor: disable copy assignment, copy constructor * refactor: move log statements to peer_socket constructor
This commit is contained in:
@@ -3,12 +3,49 @@
|
||||
// or any future license endorsed by Mnemosyne LLC.
|
||||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <libutp/utp.h>
|
||||
|
||||
#include "transmission.h"
|
||||
|
||||
#include "peer-socket.h"
|
||||
#include "net.h"
|
||||
#include "session.h"
|
||||
|
||||
#define tr_logAddErrorIo(io, msg) tr_logAddError(msg, (io)->readable())
|
||||
#define tr_logAddWarnIo(io, msg) tr_logAddWarn(msg, (io)->readable())
|
||||
#define tr_logAddDebugIo(io, msg) tr_logAddDebug(msg, (io)->readable())
|
||||
#define tr_logAddTraceIo(io, msg) tr_logAddTrace(msg, (io)->readable())
|
||||
|
||||
tr_peer_socket::tr_peer_socket(tr_session* session, tr_address const& address, tr_port port, tr_socket_t sock)
|
||||
: handle{ sock }
|
||||
, address_{ address }
|
||||
, port_{ port }
|
||||
, type_{ Type::TCP }
|
||||
{
|
||||
TR_ASSERT(sock != TR_BAD_SOCKET);
|
||||
|
||||
session->setSocketTOS(sock, address_.type);
|
||||
|
||||
if (auto const& algo = session->peerCongestionAlgorithm(); !std::empty(algo))
|
||||
{
|
||||
tr_netSetCongestionControl(sock, algo.c_str());
|
||||
}
|
||||
|
||||
tr_logAddTraceIo(this, fmt::format("socket (tcp) is {}", handle.tcp));
|
||||
}
|
||||
|
||||
tr_peer_socket::tr_peer_socket(tr_address const& address, tr_port port, struct UTPSocket* const sock)
|
||||
: address_{ address }
|
||||
, port_{ port }
|
||||
, type_{ Type::UTP }
|
||||
{
|
||||
TR_ASSERT(sock != nullptr);
|
||||
handle.utp = sock;
|
||||
|
||||
tr_logAddTraceIo(this, fmt::format("socket (µTP) is {}", fmt::ptr(handle.utp)));
|
||||
}
|
||||
|
||||
void tr_peer_socket::close(tr_session* session)
|
||||
{
|
||||
@@ -23,4 +60,7 @@ void tr_peer_socket::close(tr_session* session)
|
||||
utp_close(handle.utp);
|
||||
}
|
||||
#endif
|
||||
|
||||
type_ = Type::None;
|
||||
handle = {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user