libcosmos
Linux C++ System Programming Library
Loading...
Searching...
No Matches
TCPConnection.hxx
1#pragma once
2
3// cosmos
4#include <cosmos/net/IPSocket.hxx>
5#include <cosmos/net/TCPOptions.hxx>
6#include <cosmos/net/types.hxx>
7
8namespace cosmos {
9
11
20template <SocketFamily FAMILY>
22 public IPSocketT<FAMILY> {
23public: // functions
24
25 explicit TCPConnectionT(FileDescriptor fd, const AutoCloseFD auto_close = AutoCloseFD{true}) :
26 IPSocketT<FAMILY>{fd, auto_close} {
27 }
28
29 auto tcpOptions() {
30 return TCPOptions{this->m_fd};
31 }
32
33 auto tcpOptions() const {
34 return TCPOptions{this->m_fd};
35 }
36
37 using Socket::receive;
38 using Socket::send;
39
40 void sendMessage(SendMessageHeader &header) {
41 return Socket::sendMessage(header);
42 }
43
44 Socket::AddressFilledIn receiveMessage(ReceiveMessageHeader &header) {
45 return Socket::receiveMessage(header);
46 }
47};
48
51
52} // end ns
FileDescriptor fd() const
Allows access to the underlying fd with const semantics.
Definition FileBase.hxx:74
Thin Wrapper around OS file descriptors.
Base class for IPv4 or IPv6 based sockets.
Definition IPSocket.hxx:21
Wrapper for struct msghdr for receiving message via Socket::receiveMessage().
Wrapper for struct msghdr for sending messages via Socket::sendMessage().
void sendMessage(SendMessageHeader &header, const SocketAddress *addr=nullptr)
Sends a message over the socket using extended SendMessageHeader data.
Definition Socket.cxx:126
AddressFilledIn receiveMessage(ReceiveMessageHeader &header, SocketAddress *addr=nullptr)
Receives a message from the socket using extended ReceiveMessageHeader data.
Definition Socket.cxx:145
size_t receive(void *buf, size_t length, const MessageFlags flags=MessageFlags{})
Receive data from the socket, using specific receive flags.
Definition Socket.cxx:84
size_t send(const void *buf, size_t length, const MessageFlags flags=MessageFlags{})
Send the given data over the socket, using specific send flags.
Definition Socket.cxx:66
Template for an active IPv4 and IPv6 based TCP connection.
TCP level socket option setter/getter helper.