UNSocketProtocol.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 
17 #include "UNSocketProtocol.hh"
18 
19 // Custom includes
20 #include <unistd.h>
21 #include <sys/socket.h>
22 #include <sys/ioctl.h>
23 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
25 #include <senf/Utils/Exception.hh>
27 #include "UNAddressing.hh"
28 
29 #define prefix_
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32  const
33 {
34  int n;
35  if (::ioctl(fd(), SIOCINQ, &n) < 0)
36  SENF_THROW_SYSTEM_EXCEPTION("Could not call available() on UNSocket.");
37  return n;
38 }
39 
41  const
42 {
43  return false;
44 }
45 
47 {
48  check_and_unlink();
49 
51 }
52 
54  const
55 {
56  check_and_unlink();
57 
59 }
60 
61 prefix_ void senf::UNSocketProtocol::check_and_unlink()
62  const
63 {
65  try {
66  UNSocketAddress una (static_socket_cast<UNSocketHandle>(fh()).local());
67  ::unlink(una.path().c_str());
68  }
69  catch (SystemException & e) {
70  SENF_LOG(("UNSocketProtocol::check_and_unlink() failed; [" << e.errorString() << "]."));
71  }
72 }
73 
74 //-/////////////////////////////////////////////////////////////////////////////////////////////////
75 #undef prefix_
76 
77 
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // comment-column: 40
82 // c-file-style: "senf"
83 // indent-tabs-mode: nil
84 // ispell-local-dictionary: "american"
85 // compile-command: "scons -u test"
86 // End:
ClientSocketHandle public header.
char const * errorString() const
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
Generic SocketHandle with client interface.
Unix domain socket address.
Definition: UNAddressing.hh:41
virtual void terminate() const
Forcibly close socket.
#define prefix_
int fd() const
Get file descriptor.
bool eof() const
Check for end-of-file condition.
UNSocketProtocol public header.
UNAddressing public header.
FileHandle fh() const
Get a FileHandle for this instance.
virtual void close()
Close socket.
unsigned available() const
Return (maximum) number of bytes available for reading without < blocking.
virtual void terminate() const
Forcibly close socket.
#define SENF_LOG(args)
std::string path() const
Return path as string.
virtual void close()
Close socket.