SNode.C
Loading...
Searching...
No Matches
net::un::phy::PhysicalSocket< PhysicalPeerSocketT > Class Template Reference

#include <PhysicalSocket.h>

Inheritance diagram for net::un::phy::PhysicalSocket< PhysicalPeerSocketT >:
Collaboration diagram for net::un::phy::PhysicalSocket< PhysicalPeerSocketT >:

Public Types

using Super = PhysicalPeerSocketT< net::un::SocketAddress >
 

Public Member Functions

 PhysicalSocket (int type, int protocol)
 
 PhysicalSocket (PhysicalSocket &&physicalSocket) noexcept
 
PhysicalSocketoperator= (PhysicalSocket &&physicalSocket) noexcept
 
 ~PhysicalSocket () override
 
int bind (SocketAddress &bindAddress)
 

Private Attributes

int lockFd = -1
 

Detailed Description

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

Definition at line 55 of file PhysicalSocket.h.

Member Typedef Documentation

◆ Super

template<template< typename SocketAddressT > typename PhysicalPeerSocketT>
using net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::Super = PhysicalPeerSocketT<net::un::SocketAddress>

Definition at line 57 of file PhysicalSocket.h.

Constructor & Destructor Documentation

◆ PhysicalSocket() [1/2]

template<template< typename SocketAddress > typename PhysicalPeerSocket>
net::un::phy::PhysicalSocket< PhysicalPeerSocket >::PhysicalSocket ( int  type,
int  protocol 
)

Definition at line 60 of file PhysicalSocket.hpp.

61 : Super(PF_UNIX, type, protocol) {
62 }
PhysicalPeerSocketT< net::un::SocketAddress > Super

Referenced by net::un::dgram::Socket::Socket().

Here is the caller graph for this function:

◆ PhysicalSocket() [2/2]

template<template< typename SocketAddress > typename PhysicalPeerSocket>
net::un::phy::PhysicalSocket< PhysicalPeerSocket >::PhysicalSocket ( PhysicalSocket< PhysicalPeerSocketT > &&  physicalSocket)
noexcept

Definition at line 65 of file PhysicalSocket.hpp.

66 : Super(std::move(physicalSocket))
67 , lockFd(std::exchange(physicalSocket.lockFd, -1)) {
68 }

◆ ~PhysicalSocket()

template<template< typename SocketAddress > typename PhysicalPeerSocket>
net::un::phy::PhysicalSocket< PhysicalPeerSocket >::~PhysicalSocket ( )
override

Definition at line 79 of file PhysicalSocket.hpp.

79 {
80 if (lockFd >= 0) {
81 if (std::remove(Super::getBindAddress().getSunPath().data()) == 0) {
82 LOG(DEBUG) << "Remove sun path: " << Super::getBindAddress().getSunPath();
83 } else {
84 PLOG(ERROR) << "Remove sun path: " << Super::getBindAddress().getSunPath();
85 }
86
87 if (core::system::flock(lockFd, LOCK_UN) == 0) {
88 LOG(DEBUG) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock");
89 } else {
90 PLOG(ERROR) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock");
91 }
92
93 if (std::remove(Super::bindAddress.getSunPath().append(".lock").data()) == 0) {
94 LOG(DEBUG) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock");
95 } else {
96 PLOG(ERROR) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock");
97 }
98
100 lockFd = -1;
101 }
102 }
int close(int fd)
Definition unistd.cpp:67
int flock(int lockFd, int operation)
Definition unistd.cpp:77

References core::system::close(), core::system::flock(), and net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::lockFd.

Here is the call graph for this function:

Member Function Documentation

◆ bind()

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

Definition at line 105 of file PhysicalSocket.hpp.

105 {
106 if (!bindAddress.getSunPath().empty() && !bindAddress.getSunPath().starts_with('\0')) {
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();
109 if (core::system::flock(lockFd, LOCK_EX | LOCK_NB) == 0) {
110 LOG(DEBUG) << "Locking lock file: " << bindAddress.getSunPath().append(".lock").data();
111 if (std::filesystem::exists(bindAddress.getSunPath().data())) {
112 if (std::remove(bindAddress.getSunPath().data()) == 0) {
113 LOG(WARNING) << "Removed stalled sun_path: " << bindAddress.getSunPath().data();
114 } else {
115 PLOG(ERROR) << "Removed stalled sun path: " << bindAddress.getSunPath().data();
116 }
117 }
118 } else {
119 PLOG(ERROR) << "Locking lock file " << bindAddress.getSunPath().append(".lock").data();
120
122 lockFd = -1;
123 }
124 } else {
125 PLOG(ERROR) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data();
126 }
127 }
128
129 return Super::bind(bindAddress);
130 }
int open(const char *pathname, int flags)
Definition unistd.cpp:52

References core::system::close(), core::system::flock(), net::un::SocketAddress::getSunPath(), and net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::lockFd.

Here is the call graph for this function:

◆ operator=()

template<template< typename SocketAddress > typename PhysicalPeerSocket>
PhysicalSocket< PhysicalPeerSocket > & net::un::phy::PhysicalSocket< PhysicalPeerSocket >::operator= ( PhysicalSocket< PhysicalPeerSocketT > &&  physicalSocket)
noexcept

Definition at line 71 of file PhysicalSocket.hpp.

71 {
72 Super::operator=(std::move(physicalSocket));
73 lockFd = std::exchange(physicalSocket.lockFd, -1);
74
75 return *this;
76 }

References net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::lockFd.

Member Data Documentation

◆ lockFd

template<template< typename SocketAddressT > typename PhysicalPeerSocketT>
int net::un::phy::PhysicalSocket< PhysicalPeerSocketT >::lockFd = -1
private

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