SNode.C
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
net::phy::PhysicalSocket< SocketAddressT > Class Template Reference

#include <PhysicalSocket.h>

Inheritance diagram for net::phy::PhysicalSocket< SocketAddressT >:
Collaboration diagram for net::phy::PhysicalSocket< SocketAddressT >:

Public Types

enum  Flags { NONE = 0 , NONBLOCK = SOCK_NONBLOCK , CLOEXIT = SOCK_CLOEXEC }
 

Public Member Functions

 PhysicalSocket ()=delete
 
 PhysicalSocket (PhysicalSocket &)=delete
 
PhysicalSocketoperator= (PhysicalSocket &)=delete
 
 PhysicalSocket (const PhysicalSocket &)=delete
 
PhysicalSocketoperator= (const PhysicalSocket &)=delete
 
 PhysicalSocket (int fd, const SocketAddress &bindAddress)
 
int open (const std::map< int, std::map< int, const PhysicalSocketOption > > &socketOptionsMapMap, Flags flags)
 
int bind (SocketAddress &bindAddress)
 
bool isValid () const
 
int getSockError (int &cErrno) const
 
int getSockName (typename SocketAddress::SockAddr &localSockAddr, typename SocketAddress::SockLen &localSockAddrLen)
 
int getPeerName (typename SocketAddress::SockAddr &remoteSockAddr, typename SocketAddress::SockLen &remoteSockAddrLen)
 
SocketAddress getBindAddress () const
 
- Public Member Functions inherited from core::Descriptor
 Descriptor ()=delete
 
 Descriptor (const Descriptor &d)=delete
 
Descriptoroperator= (int fd)
 
Descriptoroperator= (const Descriptor &descriptor)=delete
 
Descriptoroperator= (Descriptor &&descriptor) noexcept
 
int getFd () const
 

Protected Types

using SocketAddress = SocketAddressT
 

Protected Member Functions

 PhysicalSocket (int domain, int type, int protocol)
 
 PhysicalSocket (PhysicalSocket &&physicalSocket) noexcept=default
 
PhysicalSocketoperator= (PhysicalSocket &&) noexcept=default
 
 ~PhysicalSocket () override
 
- Protected Member Functions inherited from core::Descriptor
 Descriptor (int fd)
 
 Descriptor (Descriptor &&descriptor) noexcept
 
virtual ~Descriptor ()
 

Protected Attributes

SocketAddress bindAddress
 
int domain = 0
 
int type = 0
 
int protocol = 0
 

Private Types

using Super = core::Descriptor
 

Private Member Functions

int setSockopt (int level, int optname, const void *optval, typename SocketAddress::SockLen optlen) const
 
int getSockopt (int level, int optname, void *optval, typename SocketAddress::SockLen *optlen) const
 

Detailed Description

template<typename SocketAddressT>
class net::phy::PhysicalSocket< SocketAddressT >

Definition at line 60 of file PhysicalSocket.h.

Member Typedef Documentation

◆ SocketAddress

template<typename SocketAddressT >
using net::phy::PhysicalSocket< SocketAddressT >::SocketAddress = SocketAddressT
protected

Definition at line 68 of file PhysicalSocket.h.

◆ Super

template<typename SocketAddressT >
using net::phy::PhysicalSocket< SocketAddressT >::Super = core::Descriptor
private

Definition at line 62 of file PhysicalSocket.h.

Member Enumeration Documentation

◆ Flags

template<typename SocketAddressT >
enum net::phy::PhysicalSocket::Flags
Enumerator
NONE 
NONBLOCK 
CLOEXIT 

Definition at line 65 of file PhysicalSocket.h.

Constructor & Destructor Documentation

◆ PhysicalSocket() [1/6]

◆ PhysicalSocket() [2/6]

template<typename SocketAddressT >
net::phy::PhysicalSocket< SocketAddressT >::PhysicalSocket ( PhysicalSocket< SocketAddressT > &&  physicalSocket)
protecteddefaultnoexcept

◆ ~PhysicalSocket()

template<typename SocketAddress >
net::phy::PhysicalSocket< SocketAddress >::~PhysicalSocket ( )
overrideprotected

Definition at line 76 of file PhysicalSocket.hpp.

76 {
77 }

◆ PhysicalSocket() [3/6]

template<typename SocketAddressT >
net::phy::PhysicalSocket< SocketAddressT >::PhysicalSocket ( )
delete

◆ PhysicalSocket() [4/6]

template<typename SocketAddressT >
net::phy::PhysicalSocket< SocketAddressT >::PhysicalSocket ( PhysicalSocket< SocketAddressT > &  )
delete

◆ PhysicalSocket() [5/6]

template<typename SocketAddressT >
net::phy::PhysicalSocket< SocketAddressT >::PhysicalSocket ( const PhysicalSocket< SocketAddressT > &  )
delete

◆ PhysicalSocket() [6/6]

template<typename SocketAddress >
net::phy::PhysicalSocket< SocketAddress >::PhysicalSocket ( int  fd,
const SocketAddress bindAddress 
)

Definition at line 62 of file PhysicalSocket.hpp.

63 : Descriptor(fd)
65 typename SocketAddress::SockLen optLen = sizeof(domain);
66 getSockopt(SOL_SOCKET, SO_DOMAIN, &domain, &optLen);
67
68 optLen = sizeof(type);
69 getSockopt(SOL_SOCKET, SO_TYPE, &type, &optLen);
70
71 optLen = sizeof(protocol);
72 getSockopt(SOL_SOCKET, SO_PROTOCOL, &protocol, &optLen);
73 }
int getSockopt(int level, int optname, void *optval, typename SocketAddress::SockLen *optlen) const

References net::phy::PhysicalSocket< SocketAddressT >::bindAddress, net::phy::PhysicalSocket< SocketAddressT >::domain, net::phy::PhysicalSocket< SocketAddressT >::getSockopt(), net::phy::PhysicalSocket< SocketAddressT >::protocol, and net::phy::PhysicalSocket< SocketAddressT >::type.

Here is the call graph for this function:

Member Function Documentation

◆ bind()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::bind ( SocketAddress bindAddress)

Definition at line 107 of file PhysicalSocket.hpp.

107 {
108 int ret = core::system::bind(core::Descriptor::getFd(), &bindAddress.getSockAddr(), bindAddress.getSockAddrLen());
109
110 if (ret == 0) {
111 this->bindAddress = bindAddress;
112 }
113
114 return ret;
115 }
int getFd() const
int bind(int sockfd, const sockaddr *addr, socklen_t addrlen)
Definition socket.cpp:57

References core::system::bind(), net::phy::PhysicalSocket< SocketAddressT >::bindAddress, and core::Descriptor::getFd().

Here is the call graph for this function:

◆ getBindAddress()

template<typename SocketAddress >
SocketAddress net::phy::PhysicalSocket< SocketAddress >::getBindAddress ( ) const

Definition at line 152 of file PhysicalSocket.hpp.

152 {
153 return bindAddress;
154 }

References net::phy::PhysicalSocket< SocketAddressT >::bindAddress.

◆ getPeerName()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::getPeerName ( typename SocketAddress::SockAddr remoteSockAddr,
typename SocketAddress::SockLen remoteSockAddrLen 
)

Definition at line 146 of file PhysicalSocket.hpp.

147 {
148 return core::system::getpeername(core::Descriptor::getFd(), reinterpret_cast<sockaddr*>(&remoteSockAddr), &remoteSockAddrLen);
149 }
int getpeername(int sockfd, sockaddr *addr, socklen_t *addrlen)
Definition socket.cpp:86

References core::Descriptor::getFd(), and core::system::getpeername().

Here is the call graph for this function:

◆ getSockError()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::getSockError ( int &  cErrno) const

Definition at line 123 of file PhysicalSocket.hpp.

123 {
124 typename SocketAddress::SockLen cErrnoLen = sizeof(cErrno);
125 return getSockopt(SOL_SOCKET, SO_ERROR, &cErrno, &cErrnoLen);
126 }

References net::phy::PhysicalSocket< SocketAddressT >::getSockopt().

Here is the call graph for this function:

◆ getSockName()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::getSockName ( typename SocketAddress::SockAddr localSockAddr,
typename SocketAddress::SockLen localSockAddrLen 
)

Definition at line 140 of file PhysicalSocket.hpp.

141 {
142 return core::system::getsockname(core::Descriptor::getFd(), reinterpret_cast<sockaddr*>(&localSockAddr), &localSockAddrLen);
143 }
int getsockname(int sockfd, sockaddr *addr, socklen_t *addrlen)
Definition socket.cpp:81

References core::Descriptor::getFd(), and core::system::getsockname().

Here is the call graph for this function:

◆ getSockopt()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::getSockopt ( int  level,
int  optname,
void *  optval,
typename SocketAddress::SockLen optlen 
) const
private

Definition at line 135 of file PhysicalSocket.hpp.

135 {
136 return core::system::getsockopt(PhysicalSocket::getFd(), level, optname, optval, optlen);
137 }
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
Definition socket.cpp:101

References core::Descriptor::getFd(), and core::system::getsockopt().

Referenced by net::phy::PhysicalSocket< SocketAddressT >::getSockError(), and net::phy::PhysicalSocket< SocketAddressT >::PhysicalSocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValid()

template<typename SocketAddress >
bool net::phy::PhysicalSocket< SocketAddress >::isValid ( ) const

Definition at line 118 of file PhysicalSocket.hpp.

118 {
119 return core::Descriptor::getFd() >= 0;
120 }

References core::Descriptor::getFd().

Here is the call graph for this function:

◆ open()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::open ( const std::map< int, std::map< int, const PhysicalSocketOption > > &  socketOptionsMapMap,
Flags  flags 
)

Definition at line 80 of file PhysicalSocket.hpp.

81 {
83
84 if (ret >= 0) {
85 for (const auto& [optLevel, socketOptionsMap] : socketOptionsMapMap) {
86 for (const auto& [optName, socketOption] : socketOptionsMap) {
87 int setSockoptRet = setSockopt(
88 socketOption.getOptLevel(), socketOption.getOptName(), socketOption.getOptValue(), socketOption.getOptLen());
89
90 ret = (ret >= 0 && setSockoptRet < 0) ? setSockoptRet : ret;
91
92 if (ret < 0) {
93 break;
94 }
95 }
96
97 if (ret < 0) {
98 break;
99 }
100 }
101 }
102
103 return ret;
104 }
Descriptor & operator=(int fd)
int setSockopt(int level, int optname, const void *optval, typename SocketAddress::SockLen optlen) const
int socket(int domain, int type, int protocol)
Definition socket.cpp:52

References net::phy::PhysicalSocket< SocketAddressT >::domain, net::phy::PhysicalSocketOption::getOptLen(), net::phy::PhysicalSocketOption::getOptLevel(), net::phy::PhysicalSocketOption::getOptName(), net::phy::PhysicalSocketOption::getOptValue(), net::phy::PhysicalSocket< SocketAddressT >::protocol, net::phy::PhysicalSocket< SocketAddressT >::setSockopt(), core::system::socket(), and net::phy::PhysicalSocket< SocketAddressT >::type.

Here is the call graph for this function:

◆ operator=() [1/3]

template<typename SocketAddressT >
PhysicalSocket & net::phy::PhysicalSocket< SocketAddressT >::operator= ( const PhysicalSocket< SocketAddressT > &  )
delete

◆ operator=() [2/3]

template<typename SocketAddressT >
PhysicalSocket & net::phy::PhysicalSocket< SocketAddressT >::operator= ( PhysicalSocket< SocketAddressT > &&  )
protecteddefaultnoexcept

◆ operator=() [3/3]

template<typename SocketAddressT >
PhysicalSocket & net::phy::PhysicalSocket< SocketAddressT >::operator= ( PhysicalSocket< SocketAddressT > &  )
delete

◆ setSockopt()

template<typename SocketAddress >
int net::phy::PhysicalSocket< SocketAddress >::setSockopt ( int  level,
int  optname,
const void *  optval,
typename SocketAddress::SockLen  optlen 
) const
private

Definition at line 130 of file PhysicalSocket.hpp.

130 {
131 return core::system::setsockopt(PhysicalSocket::getFd(), level, optname, optval, optlen);
132 }
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
Definition socket.cpp:106

References core::Descriptor::getFd(), and core::system::setsockopt().

Referenced by net::phy::PhysicalSocket< SocketAddressT >::open().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ bindAddress

◆ domain

◆ protocol

◆ type


The documentation for this class was generated from the following files: