15 #ifndef THRILL_NET_TCP_CONNECTION_HEADER 16 #define THRILL_NET_TCP_CONNECTION_HEADER 56 static constexpr
bool debug =
false;
86 sLOG1 <<
"Assignment-destruction of valid Connection" <<
this;
89 socket_ = std::move(other.socket_);
144 throw Exception(
"Error setting socket non-blocking flag", errno);
166 if (
socket_.
send(data, size, f) !=
static_cast<ssize_t
>(size))
167 throw Exception(
"Error during SyncSend", errno);
176 int f = MSG_DONTWAIT;
185 if (
socket_.
recv(out_data, size) !=
static_cast<ssize_t
>(size))
186 throw Exception(
"Error during SyncRecv", errno);
190 ssize_t
RecvOne(
void* out_data,
size_t size)
final {
201 void* recv_data,
size_t recv_size)
final {
207 void* recv_data,
size_t recv_size)
final {
219 os <<
"[tcp::Connection" 249 #endif // !THRILL_NET_TCP_CONNECTION_HEADER size_t peer_id_
The id of the worker this connection is connected to.
ConnectionState state() const
Gets the state of this connection.
Socket & GetSocket()
Return the raw socket object for more low-level network programming.
void SyncRecvSend(const void *send_data, size_t send_size, void *recv_data, size_t recv_size) final
void SyncSend(const void *data, size_t size, Flags flags) final
size_t peer_id() const
Gets the id of the worker this connection is connected to.
ssize_t SendOne(const void *data, size_t size, Flags flags) final
bool close()
Close socket.
std::string ToString() const final
return a string representation of this connection, for user output.
std::atomic< size_t > tx_bytes_
sent bytes
Connection(Connection &&other)
move-constructor
void set_peer_id(size_t peerId)
Sets the id of the worker this connection is connected to.
const Socket & GetSocket() const
Return the raw socket object for more low-level network programming.
void SyncSendRecv(const void *send_data, size_t send_size, void *recv_data, size_t recv_size) final
Connection(Socket &&s)
Construct Connection from a Socket.
void Close()
Close this Connection.
ssize_t recv_one(void *out_data, size_t max_size, int flags=0)
Recv (out_data,max_size) from socket (BSD socket API function wrapper)
int GetError() const
Return the associated socket error.
ssize_t send_one(const void *data, size_t size, int flags=0)
Connection is a rich point-to-point socket connection to another client (worker, master, or whatever).
static by_string to_string(int val)
convert to string
size_t group_id_
The id of the group this connection is associated with.
A Exception is thrown by Connection on all errors instead of returning error codes.
void SyncRecv(void *out_data, size_t size) final
std::string GetPeerAddress() const
Return the socket peer address.
Socket is a light-weight wrapper around the BSD socket API.
std::ostream & OutputOstream(std::ostream &os) const final
make ostreamable
A Connection represents a link to another peer in a network group.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
static constexpr bool debug
Connection()=default
default construction, contains invalid socket
ssize_t recv(void *out_data, size_t size, int flags=0)
Receive (data,size) from socket, retry recvs if short-reads occur.
void set_group_id(size_t groupId)
Sets the group id of this connection.
int GetError() const
Query socket for its current error state.
static bool SetNonBlocking(int fd, bool non_blocking)
Turn socket into non-blocking state.
bool IsValid() const final
Check whether the contained file descriptor is valid.
Socket socket_
Underlying socket or connection handle.
void SetNonBlocking(bool non_blocking)
Set socket to non-blocking.
int fd() const
Return the associated file descriptor.
std::string ToStringHostPort() const
Return the enclosed socket address as a string with the port number.
Connection(Socket &&s, size_t group_id, size_t peer_id)
Flags
Additional flags for sending or receiving.
ssize_t RecvOne(void *out_data, size_t size) final
SocketAddress GetPeerAddress() const
Return the current peer socket address.
ssize_t send(const void *data, size_t size, int flags=0)
Send (data,size) to socket, retry sends if short-sends occur.
Connection & operator=(Connection &&other)
move assignment-operator
size_t group_id() const
Gets the id of the net group this connection is associated with.
bool operator==(const Connection &c) const noexcept
Checks wether two connections have the same underlying socket or not.
bool IsValid() const
Check whether the contained file descriptor is valid.
std::atomic< size_t > rx_bytes_
received bytes
void set_state(ConnectionState state)
Sets the state of this connection.