live
NetInterface.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "groupsock"
17 // Copyright (c) 1996-2021 Live Networks, Inc. All rights reserved.
18 // Network Interfaces
19 // C++ header
20 
21 #ifndef _NET_INTERFACE_HH
22 #define _NET_INTERFACE_HH
23 
24 #ifndef _NET_ADDRESS_HH
25 #include "NetAddress.hh"
26 #endif
27 
28 class NetInterface {
29 public:
30  virtual ~NetInterface();
31 
33  // if non-NULL, used for each new interface
34 
35 protected:
36  NetInterface(); // virtual base class
37 };
38 
39 class Socket: public NetInterface {
40 public:
41  virtual ~Socket();
42  void reset(); // closes the socket, and sets "fSocketNum" to -1
43 
44  virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize,
45  unsigned& bytesRead,
46  struct sockaddr_storage& fromAddress) = 0;
47  // Returns False on error; resultData == NULL if data ignored
48 
49  int socketNum() const { return fSocketNum; }
50 
51  Port port() const {
52  return fPort;
53  }
54 
55  UsageEnvironment& env() const { return fEnv; }
56 
57  static int DebugLevel;
58 
59 protected:
60  Socket(UsageEnvironment& env, Port port, int family); // virtual base class
61 
62  Boolean changePort(Port newPort); // will also cause socketNum() to change
63 
64 private:
68  int fFamily;
69 };
70 
72 
73 // A data structure for looking up a Socket by port:
74 
76 public:
77  virtual ~SocketLookupTable();
78 
79  Socket* Fetch(UsageEnvironment& env, Port port, Boolean& isNew);
80  // Creates a new Socket if none already exists
81  Boolean Remove(Socket const* sock);
82 
83 protected:
84  SocketLookupTable(); // abstract base class
85  virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0;
86 
87 private:
89 };
90 
91 // A data structure for counting traffic:
92 
94 public:
96 
97  void countPacket(unsigned packetSize);
98 
99  float totNumPackets() const {return fTotNumPackets;}
100  float totNumBytes() const {return fTotNumBytes;}
101 
103 
104 private:
107 };
108 
109 #endif
unsigned char Boolean
Definition: Boolean.hh:25
UsageEnvironment & operator<<(UsageEnvironment &s, const Socket &sock)
Boolean haveSeenTraffic() const
void countPacket(unsigned packetSize)
float totNumPackets() const
Definition: NetInterface.hh:99
static UsageEnvironment * DefaultUsageEnvironment
Definition: NetInterface.hh:32
virtual ~NetInterface()
virtual Socket * CreateNew(UsageEnvironment &env, Port port)=0
Socket * Fetch(UsageEnvironment &env, Port port, Boolean &isNew)
HashTable * fTable
Definition: NetInterface.hh:88
virtual ~SocketLookupTable()
Boolean Remove(Socket const *sock)
int fFamily
Definition: NetInterface.hh:68
UsageEnvironment & env() const
Definition: NetInterface.hh:55
UsageEnvironment & fEnv
Definition: NetInterface.hh:66
virtual Boolean handleRead(unsigned char *buffer, unsigned bufferMaxSize, unsigned &bytesRead, struct sockaddr_storage &fromAddress)=0
Boolean changePort(Port newPort)
virtual ~Socket()
int fSocketNum
Definition: NetInterface.hh:65
Port port() const
Definition: NetInterface.hh:51
int socketNum() const
Definition: NetInterface.hh:49
Socket(UsageEnvironment &env, Port port, int family)
void reset()
static int DebugLevel
Definition: NetInterface.hh:57
Port fPort
Definition: NetInterface.hh:67