SNode.C
Loading...
Searching...
No Matches
net::un::dgram::Socket Class Reference

#include <Socket.h>

Inheritance diagram for net::un::dgram::Socket:
Collaboration diagram for net::un::dgram::Socket:

Public Member Functions

 Socket ()
 
 ~Socket () override
 
ssize_t sendFd (SocketAddress &&destAddress, int sendfd)
 
ssize_t sendFd (SocketAddress &destAddress, int sendfd)
 
ssize_t recvFd (int *recvfd)
 
- Public Member Functions inherited from net::un::phy::PhysicalSocket< net::phy::dgram::PeerSocket >
 PhysicalSocket (int type, int protocol)
 
 PhysicalSocket (PhysicalSocket &&physicalSocket) noexcept
 
PhysicalSocketoperator= (PhysicalSocket &&physicalSocket) noexcept
 
 ~PhysicalSocket () override
 
int bind (SocketAddress &bindAddress)
 

Private Types

using Super = net::un::phy::PhysicalSocket< net::phy::dgram::PeerSocket >
 

Additional Inherited Members

- Public Types inherited from net::un::phy::PhysicalSocket< net::phy::dgram::PeerSocket >
using Super = net::phy::dgram::PeerSocket< net::un::SocketAddress >
 

Detailed Description

Definition at line 56 of file Socket.h.

Member Typedef Documentation

◆ Super

Constructor & Destructor Documentation

◆ Socket()

net::un::dgram::Socket::Socket ( )

Definition at line 56 of file Socket.cpp.

57 : Super(SOCK_DGRAM, 0) {
58 }
net::un::phy::PhysicalSocket< net::phy::dgram::PeerSocket > Super
Definition Socket.h:58

References net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::PhysicalSocket().

Here is the call graph for this function:

◆ ~Socket()

net::un::dgram::Socket::~Socket ( )
override

Definition at line 60 of file Socket.cpp.

60 {
61 }

Member Function Documentation

◆ recvFd()

ssize_t net::un::dgram::Socket::recvFd ( int *  recvfd)

Definition at line 97 of file Socket.cpp.

97 {
98 union {
99 struct cmsghdr cm;
100 char control[CMSG_SPACE(sizeof(int))] = {};
101 } control_un;
102
103 msghdr msg{};
104 msg.msg_control = control_un.control;
105 msg.msg_controllen = sizeof(control_un.control);
106
107 msg.msg_name = nullptr;
108 msg.msg_namelen = 0;
109
110 iovec iov[1];
111 msg.msg_iov = iov;
112 msg.msg_iovlen = 1;
113
114 char ptr = 0;
115 msg.msg_iov[0].iov_base = &ptr;
116 msg.msg_iov[0].iov_len = 1;
117
118 ssize_t n = 0;
119
120 if ((n = recvmsg(core::Descriptor::getFd(), &msg, 0)) > 0) {
121 cmsghdr* cmptr = nullptr;
122
123 if ((cmptr = CMSG_FIRSTHDR(&msg)) != nullptr && cmptr->cmsg_len == CMSG_LEN(sizeof(int))) {
124 if (cmptr->cmsg_level != SOL_SOCKET || cmptr->cmsg_type != SCM_RIGHTS) {
125 errno = EBADE;
126 *recvfd = -1;
127 n = -1;
128 } else {
129 *recvfd = *reinterpret_cast<int*>(CMSG_DATA(cmptr));
130 }
131 } else {
132 errno = ENOMSG;
133 *recvfd = -1;
134 n = -1;
135 }
136 }
137
138 return n;
139 }
int getFd() const

References core::Descriptor::getFd().

Here is the call graph for this function:

◆ sendFd() [1/2]

ssize_t net::un::dgram::Socket::sendFd ( SocketAddress &&  destAddress,
int  sendfd 
)

Definition at line 63 of file Socket.cpp.

63 {
64 return sendFd(destAddress, sendfd);
65 }
ssize_t sendFd(SocketAddress &&destAddress, int sendfd)
Definition Socket.cpp:63

References sendFd().

Here is the call graph for this function:

◆ sendFd() [2/2]

ssize_t net::un::dgram::Socket::sendFd ( SocketAddress destAddress,
int  sendfd 
)

Definition at line 67 of file Socket.cpp.

67 {
68 union {
69 struct cmsghdr cm;
70 char control[CMSG_SPACE(sizeof(int))] = {};
71 } control_un;
72
73 msghdr msg{};
74 msg.msg_name = const_cast<sockaddr*>(&destAddress.getSockAddr());
75 msg.msg_namelen = destAddress.getSockAddrLen();
76
77 msg.msg_control = control_un.control;
78 msg.msg_controllen = sizeof(control_un.control);
79
80 iovec iov[1];
81 msg.msg_iov = iov;
82 msg.msg_iovlen = 1;
83
84 char ptr = 0;
85 msg.msg_iov[0].iov_base = &ptr;
86 msg.msg_iov[0].iov_len = 1;
87
88 cmsghdr* cmptr = CMSG_FIRSTHDR(&msg);
89 cmptr->cmsg_level = SOL_SOCKET;
90 cmptr->cmsg_type = SCM_RIGHTS;
91 *reinterpret_cast<int*>(CMSG_DATA(cmptr)) = sendfd;
92 cmptr->cmsg_len = CMSG_LEN(sizeof(int));
93
94 return sendmsg(core::Descriptor::getFd(), &msg, 0);
95 }

References core::Descriptor::getFd(), net::SocketAddress< SockAddrT >::getSockAddr(), and net::SocketAddress< SockAddrT >::getSockAddrLen().

Referenced by sendFd().

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

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