CommunicationPolicy.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
18 #include "CommunicationPolicy.hh"
19 //#include "CommunicationPolicy.ih"
20 
21 // Custom includes
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <errno.h>
25 #include <senf/Utils/Exception.hh>
26 
27 //#include "CommunicationPolicy.mpp"
28 #define prefix_
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 prefix_ void senf::ConnectedCommunicationPolicy::do_listen(FileHandle const & handle,
32  unsigned backlog)
33 {
34  ::listen(handle.fd(),backlog);
35 }
36 
37 prefix_ int senf::ConnectedCommunicationPolicy::do_accept(FileHandle const & handle,
38  struct sockaddr * addr,
39  unsigned len)
40 {
41  int rv = -1;
42  do {
43  rv = ::accept(handle.fd(),addr,&len);
44  if (rv < 0)
45  switch (errno) {
46  case EWOULDBLOCK:
47  return -1;
48  case EINTR:
49  break;
50  default:
51  SENF_THROW_SYSTEM_EXCEPTION("ConnectedCommunicationPolicy::do_accept failed.");
52  }
53  } while (rv<0);
54  return rv;
55 }
56 
57 //-/////////////////////////////////////////////////////////////////////////////////////////////////
58 #undef prefix_
59 //#include "CommunicationPolicy.mpp"
60 
61 
62 // Local Variables:
63 // mode: c++
64 // fill-column: 100
65 // c-file-style: "senf"
66 // indent-tabs-mode: nil
67 // ispell-local-dictionary: "american"
68 // compile-command: "scons -u test"
69 // comment-column: 40
70 // End:
static int accept(ServerSocketHandle< SPolicy > const &handle, typename ServerSocketHandle< SPolicy >::Address &address)
accept a new connection on the socket.
CommunicationPolicy public header.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
#define prefix_
static void listen(ServerSocketHandle< SPolicy > const &handle, unsigned backlog)
Enable establishing new connections on the socket.