E-MailRelay
gmsg.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gmsg.h
19///
20
21#ifndef G_MSG_H
22#define G_MSG_H
23
24#include "gdef.h"
25#include "gstringview.h"
26#include <vector>
27
28namespace G
29{
30 class Msg ;
31}
32
33//| \class G::Msg
34/// Wrappers for sendmsg() and recvmsg(). These are near drop-in replacements for
35/// send()/sendto() and recv()/recvto(), but with SIGPIPE disabled and optional
36/// file-descriptor-passing capabilities.
37/// \see man unix(7) and man cmsg(3)
38///
39class G::Msg
40{
41public:
42 static ssize_t send( SOCKET , const void * , std::size_t , int flags ) noexcept ;
43 ///< A send() wrapper.
44
45 static ssize_t sendto( SOCKET , const void * , std::size_t , int flags , const sockaddr * , socklen_t ) noexcept ;
46 ///< A sendto() wrapper.
47
48 static ssize_t sendto( SOCKET , const void * , std::size_t , int flags , const sockaddr * , socklen_t ,
49 int fd_to_send ) ;
50 ///< A sendmsg() wrapper. Not always implemented.
51
52 static ssize_t sendto( SOCKET , const std::vector<std::string_view> & , int flags , const sockaddr * , socklen_t ) ;
53 ///< A sendto() wrapper with scatter-gather data chunks. Not always implemented.
54
55 static ssize_t recv( SOCKET , void * , std::size_t , int flags ) noexcept ;
56 ///< A recv() wrapper.
57
58 static ssize_t recvfrom( SOCKET , void * , std::size_t , int , sockaddr * , socklen_t * ) noexcept ;
59 ///< A recvfrom() wrapper.
60
61 static ssize_t recvfrom( SOCKET , void * , std::size_t , int , sockaddr * , socklen_t * ,
62 int * fd_received_p ) ;
63 ///< A recvmsg() wrapper. The address and file descriptor pointers
64 ///< can be null independently. Not always implemented.
65
66 static bool fatal( int error ) noexcept ;
67 ///< Returns true if the error value indicates a permanent
68 ///< problem with the socket.
69
70public:
71 Msg() = delete ;
72} ;
73
74#endif
Wrappers for sendmsg() and recvmsg().
Definition: gmsg.h:40
static ssize_t recv(SOCKET, void *, std::size_t, int flags) noexcept
A recv() wrapper.
Definition: gmsg_mac.cpp:39
static bool fatal(int error) noexcept
Returns true if the error value indicates a permanent problem with the socket.
Definition: gmsg_mac.cpp:50
static ssize_t send(SOCKET, const void *, std::size_t, int flags) noexcept
A send() wrapper.
Definition: gmsg_mac.cpp:27
static ssize_t sendto(SOCKET, const void *, std::size_t, int flags, const sockaddr *, socklen_t) noexcept
A sendto() wrapper.
Definition: gmsg_mac.cpp:32
static ssize_t recvfrom(SOCKET, void *, std::size_t, int, sockaddr *, socklen_t *) noexcept
A recvfrom() wrapper.
Definition: gmsg_mac.cpp:44
Low-level classes.
Definition: garg.h:36