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 33 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 35 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 38 of file PhysicalSocket.hpp.

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

◆ PhysicalSocket() [2/2]

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

Definition at line 43 of file PhysicalSocket.hpp.

44 : Super(std::move(physicalSocket))
45 , lockFd(std::exchange(physicalSocket.lockFd, -1)) {
46 }

◆ ~PhysicalSocket()

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

Definition at line 57 of file PhysicalSocket.hpp.

57 {
58 if (lockFd >= 0) {
59 if (std::remove(Super::getBindAddress().getSunPath().data()) == 0) {
60 LOG(DEBUG) << "Remove sun path: " << Super::getBindAddress().getSunPath();
61 } else {
62 PLOG(ERROR) << "Remove sun path: " << Super::getBindAddress().getSunPath();
63 }
64
65 if (core::system::flock(lockFd, LOCK_UN) == 0) {
66 LOG(DEBUG) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock");
67 } else {
68 PLOG(ERROR) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock");
69 }
70
71 if (std::remove(Super::bindAddress.getSunPath().append(".lock").data()) == 0) {
72 LOG(DEBUG) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock");
73 } else {
74 PLOG(ERROR) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock");
75 }
76
78 lockFd = -1;
79 }
80 }
int close(int fd)
Definition unistd.cpp:45
int flock(int lockFd, int operation)
Definition unistd.cpp:55

Member Function Documentation

◆ bind()

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

Definition at line 83 of file PhysicalSocket.hpp.

83 {
84 if (!bindAddress.getSunPath().empty() && !bindAddress.getSunPath().starts_with('\0')) {
85 if ((lockFd = open(bindAddress.getSunPath().append(".lock").data(), O_RDONLY | O_CREAT, 0600)) >= 0) {
86 LOG(DEBUG) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data();
87 if (core::system::flock(lockFd, LOCK_EX | LOCK_NB) == 0) {
88 LOG(DEBUG) << "Locking lock file: " << bindAddress.getSunPath().append(".lock").data();
89 if (std::filesystem::exists(bindAddress.getSunPath().data())) {
90 if (std::remove(bindAddress.getSunPath().data()) == 0) {
91 LOG(WARNING) << "Removed stalled sun_path: " << bindAddress.getSunPath().data();
92 } else {
93 PLOG(ERROR) << "Removed stalled sun path: " << bindAddress.getSunPath().data();
94 }
95 }
96 } else {
97 PLOG(ERROR) << "Locking lock file " << bindAddress.getSunPath().append(".lock").data();
98
100 lockFd = -1;
101 }
102 } else {
103 PLOG(ERROR) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data();
104 }
105 }
106
107 return Super::bind(bindAddress);
108 }
int open(const char *pathname, int flags)
Definition unistd.cpp:30

◆ operator=()

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

Definition at line 49 of file PhysicalSocket.hpp.

49 {
50 Super::operator=(std::move(physicalSocket));
51 lockFd = std::exchange(physicalSocket.lockFd, -1);
52
53 return *this;
54 }

Member Data Documentation

◆ lockFd

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

Definition at line 48 of file PhysicalSocket.h.


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