Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
socket_guard Class Reference

RAII-style socket wrapper. Since socket is closed on wrapper destruction, initializing multiple guards with same(valid) socket descriptor is considered UB. For same reason wrapper isn't copyable. More...

#include <socket_guard.h>

Public Member Functions

 socket_guard (const socket_guard &)=delete
 
socket_guardoperator= (const socket_guard &)=delete
 
 socket_guard (SOCKET sock=INVALID_SOCKET) noexcept
 
 socket_guard (socket_guard &&rhs) noexcept
 
 operator bool () const noexcept
 
socket_guardoperator= (socket_guard &&rhs) noexcept
 
SOCKET operator* () const noexcept
 Alias for socket_guard::get. More...
 
SOCKET get () const noexcept
 
SOCKET release () noexcept
 Returns the socket descriptor and releases ownership. More...
 
void reset () noexcept
 Closes the socket. More...
 
 ~socket_guard () noexcept
 

Private Attributes

SOCKET mSocket {INVALID_SOCKET}
 

Detailed Description

RAII-style socket wrapper. Since socket is closed on wrapper destruction, initializing multiple guards with same(valid) socket descriptor is considered UB. For same reason wrapper isn't copyable.

Definition at line 23 of file socket_guard.h.

Constructor & Destructor Documentation

◆ socket_guard() [1/3]

socket_guard::socket_guard ( const socket_guard )
explicitdelete

◆ socket_guard() [2/3]

socket_guard::socket_guard ( SOCKET  sock = INVALID_SOCKET)
inlineexplicitnoexcept

Definition at line 30 of file socket_guard.h.

30: mSocket(sock) { }
SOCKET mSocket
Definition: socket_guard.h:25

◆ socket_guard() [3/3]

socket_guard::socket_guard ( socket_guard &&  rhs)
inlineexplicitnoexcept

Definition at line 32 of file socket_guard.h.

33 : mSocket(rhs.mSocket)
34 {
36 }
#define INVALID_SOCKET
Definition: ipc-types.h:28

References INVALID_SOCKET.

◆ ~socket_guard()

socket_guard::~socket_guard ( )
inlinenoexcept

Definition at line 80 of file socket_guard.h.

81 {
82 reset();
83 }
void reset() noexcept
Closes the socket.
Definition: socket_guard.h:71

References reset().

Here is the call graph for this function:

Member Function Documentation

◆ get()

SOCKET socket_guard::get ( ) const
inlinenoexcept
Returns
Underlying socket descriptor

Definition at line 60 of file socket_guard.h.

60{ return mSocket; }

References mSocket.

◆ operator bool()

socket_guard::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 38 of file socket_guard.h.

39 {
40 return mSocket != INVALID_SOCKET;
41 }

References INVALID_SOCKET, and mSocket.

◆ operator*()

SOCKET socket_guard::operator* ( ) const
inlinenoexcept

Alias for socket_guard::get.

Definition at line 57 of file socket_guard.h.

57{ return mSocket; }

References mSocket.

◆ operator=() [1/2]

socket_guard & socket_guard::operator= ( const socket_guard )
delete

◆ operator=() [2/2]

socket_guard & socket_guard::operator= ( socket_guard &&  rhs)
inlinenoexcept

Definition at line 43 of file socket_guard.h.

44 {
45 if(this == &rhs)
46 return * this;
47
48 assert(mSocket == INVALID_SOCKET || rhs.mSocket != mSocket);
49
51 rhs.reset();
52
53 return *this;
54 }
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

References INVALID_SOCKET, mSocket, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ release()

SOCKET socket_guard::release ( )
inlinenoexcept

Returns the socket descriptor and releases ownership.

Definition at line 63 of file socket_guard.h.

64 {
66 std::swap(sock, mSocket);
67 return sock;
68 }
#define SOCKET
Definition: ipc-types.h:30

References INVALID_SOCKET, mSocket, SOCKET, and anonymous_namespace{NoteTrack.cpp}::swap().

Referenced by IPCServer::Impl::Impl().

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

◆ reset()

void socket_guard::reset ( )
inlinenoexcept

Closes the socket.

Definition at line 71 of file socket_guard.h.

72 {
74 {
77 }
78 }
#define CLOSE_SOCKET
Definition: ipc-types.h:31

References CLOSE_SOCKET, INVALID_SOCKET, and mSocket.

Referenced by IPCServer::Impl::Impl(), IPCServer::Impl::~Impl(), and ~socket_guard().

Here is the caller graph for this function:

Member Data Documentation

◆ mSocket

SOCKET socket_guard::mSocket {INVALID_SOCKET}
private

Definition at line 25 of file socket_guard.h.

Referenced by get(), operator bool(), operator*(), operator=(), release(), and reset().


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