TCPSocketProtocol.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 "TCPSocketProtocol.hh"
19 //#include "TCPSocketProtocol.ih"
20 
21 // Custom includes
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <netinet/tcp.h>
25 #include <sys/ioctl.h>
26 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
27 
28 //#include "TCPSocketProtocol.mpp"
29 #define prefix_
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
33  const
34 {
35  int value;
36  socklen_t len (sizeof(value));
37  if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
38  SENF_THROW_SYSTEM_EXCEPTION("could not get sockopt TCP_NODELAY");
39  return value;
40 }
41 
43  const
44 {
45  int ivalue (value);
46  if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
47  SENF_THROW_SYSTEM_EXCEPTION("could not set sockopt TCP_NODELAY");
48 }
49 
51  const
52 {
53  int n;
54  if (::ioctl(fd(),SIOCINQ,&n) < 0)
55  SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCINQ)");
56  return n;
57 }
58 
60  const
61 {
62  int n;
63  if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
64  SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCOUTQ)");
65  return n;
66 }
67 
69  const
70 {
71  if (::shutdown(fd(), type) < 0)
72  SENF_THROW_SYSTEM_EXCEPTION("::shutdown()");
73 }
74 
76 {
79 }
80 
82  const
83 {
84  return siocinq();
85 }
86 
88  const
89 {
90  return fh().readable() && available()==0;
91 }
92 
93 
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
96 //#include "TCPSocketProtocol.mpp"
97 
98 
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // comment-column: 40
107 // End:
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
TCPSocketProtocol public header.
unsigned siocinq() const
Return current size of the input queue.
int fd() const
Get file descriptor.
unsigned available() const
Return (maximum) number of bytes available for reading without < blocking.
void close()
Close socket.
bool nodelay() const
Check current SO_NODELAY status.
#define prefix_
bool eof() const
Check for end-of-file condition.
FileHandle fh() const
Get a FileHandle for this instance.
bool readable() const
Check, whether a read on the handle would not block (ignoring blocking state)
virtual void close()
Close socket.
void shutdown(ShutType type) const
unsigned siocoutq() const
Return current size of the output queue.