E-MailRelay

gmsg_unix.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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_unix.cpp
19///
20
21#include "gdef.h"
22#include "gmsg.h"
23#include "gprocess.h"
24#include "gassert.h"
25#include "gstr.h"
26#include <cstring> // std::memcpy()
27#include <cerrno> // EINTR etc
28#include <stdexcept>
29#include <array>
30#include <sys/types.h>
31#include <sys/socket.h>
32#include <sys/uio.h>
33
34ssize_t G::Msg::send( int fd , const void * buffer , std::size_t size , int flags ) noexcept
35{
36 return ::sendto( fd , buffer , size , flags | MSG_NOSIGNAL , nullptr , 0U ) ;
37}
38
39ssize_t G::Msg::sendto( int fd , const void * buffer , std::size_t size , int flags ,
40 const sockaddr * address_p , socklen_t address_n ) noexcept
41{
42 return ::sendto( fd , buffer , size , flags | MSG_NOSIGNAL , const_cast<sockaddr*>(address_p) , address_n ) ;
43}
44
45ssize_t G::Msg::recv( int fd , void * buffer , std::size_t size , int flags )
46{
47 return ::recv( fd , buffer , size , flags ) ;
48}
49
50ssize_t G::Msg::recvfrom( int fd , void * buffer , std::size_t size , int flags ,
51 sockaddr * address_p , socklen_t * address_np )
52{
53 return ::recvfrom( fd , buffer , size , flags , address_p , address_np ) ;
54}
55
56 bool G::Msg::fatal( int error ) noexcept
57{
58 return !(
59 error == 0 ||
60 error == EAGAIN ||
61 error == EINTR ||
62 error == EMSGSIZE || // moot
63 error == ENOBUFS ||
64 error == ENOMEM ||
65 false ) ;
66}
67
G::Msg::recvfrom
static ssize_t recvfrom(SOCKET, void *, std::size_t, int flags, sockaddr *, socklen_t *)
A recvfrom() replacement using recvmsg().
Definition: gmsg_unix.cpp:50
G::Msg::recv
static ssize_t recv(SOCKET, void *, std::size_t, int flags)
A recv() wrapper.
Definition: gmsg_unix.cpp:45
G::Msg::fatal
static bool fatal(int error) noexcept
Returns true if the error value indicates a permanent problem with the socket.
Definition: gmsg_unix.cpp:56
G::Msg::send
static ssize_t send(SOCKET, const void *, std::size_t, int flags) noexcept
A send() replacement using sendmsg().
Definition: gmsg_unix.cpp:34
G::Msg::sendto
static ssize_t sendto(SOCKET, const void *, std::size_t, int flags, const sockaddr *, socklen_t) noexcept
A sendto() replacement using sendmsg().
Definition: gmsg_unix.cpp:39
gassert.h
gmsg.h
gprocess.h
gstr.h