2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "net/un/phy/PhysicalSocket.h"
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
46#include "core/system/unistd.h"
47#include "log/Logger.h"
57namespace net::un::
phy {
59 template <
template <
typename SocketAddress>
typename PhysicalPeerSocket>
61 : Super(PF_UNIX, type, protocol) {
64 template <
template <
typename SocketAddress>
typename PhysicalPeerSocket>
66 : Super(std::move(physicalSocket))
70 template <
template <
typename SocketAddress>
typename PhysicalPeerSocket>
72 Super::operator=(std::move(physicalSocket));
78 template <
template <
typename SocketAddress>
typename PhysicalPeerSocket>
81 if (std::remove(Super::getBindAddress().getSunPath().data()) == 0) {
82 LOG(DEBUG) <<
"Remove sun path: " << Super::getBindAddress().getSunPath();
84 PLOG(ERROR) <<
"Remove sun path: " << Super::getBindAddress().getSunPath();
88 LOG(DEBUG) <<
"Remove lock from file: " << Super::getBindAddress().getSunPath().append(
".lock");
90 PLOG(ERROR) <<
"Remove lock from file: " << Super::getBindAddress().getSunPath().append(
".lock");
93 if (std::remove(Super::bindAddress.getSunPath().append(
".lock").data()) == 0) {
94 LOG(DEBUG) <<
"Remove lock file: " << Super::getBindAddress().getSunPath().append(
".lock");
96 PLOG(ERROR) <<
"Remove lock file: " << Super::getBindAddress().getSunPath().append(
".lock");
104 template <
template <
typename SocketAddress>
typename PhysicalPeerSocket>
107 if ((
lockFd = open(bindAddress
.getSunPath().append(
".lock").data(), O_RDONLY | O_CREAT, 0600)) >= 0) {
108 LOG(DEBUG) <<
"Opening lock file: " << bindAddress
.getSunPath().append(
".lock").data();
110 LOG(DEBUG) <<
"Locking lock file: " << bindAddress
.getSunPath().append(
".lock").data();
111 if (std::filesystem::exists(bindAddress
.getSunPath().data())) {
113 LOG(WARNING) <<
"Removed stalled sun_path: " << bindAddress
.getSunPath().data();
115 PLOG(ERROR) <<
"Removed stalled sun path: " << bindAddress
.getSunPath().data();
119 PLOG(ERROR) <<
"Locking lock file " << bindAddress
.getSunPath().append(
".lock").data();
125 PLOG(ERROR) <<
"Opening lock file: " << bindAddress
.getSunPath().append(
".lock").data();
129 return Super::bind(bindAddress);
const SockLen & getSockAddrLen() const
const sockaddr & getSockAddr()
std::string getSunPath() const
ssize_t recvFd(int *recvfd)
ssize_t sendFd(SocketAddress &&destAddress, int sendfd)
ssize_t sendFd(SocketAddress &destAddress, int sendfd)
PhysicalSocket & operator=(PhysicalSocket &&physicalSocket) noexcept
PhysicalSocket(int type, int protocol)
PhysicalSocket(PhysicalSocket &&physicalSocket) noexcept
~PhysicalSocket() override
int bind(SocketAddress &bindAddress)
int flock(int lockFd, int operation)