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 // "mTunnel" multicast access service
17 // Copyright (c) 1996-2019 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 interfaces
34 
35 protected:
36  NetInterface(); // virtual base class
37 };
38 
40 public:
41  virtual ~DirectedNetInterface();
42 
43  virtual Boolean write(unsigned char* data, unsigned numBytes) = 0;
44 
46  unsigned addr) = 0;
47 
48 protected:
49  DirectedNetInterface(); // virtual base class
50 };
51 
53 public:
55  virtual ~DirectedNetInterfaceSet();
56 
58  // Returns the old value if different, otherwise 0
59  Boolean Remove(DirectedNetInterface const* interf);
60 
61  Boolean IsEmpty() { return fTable->IsEmpty(); }
62 
63  // Used to iterate through the interfaces in the set
64  class Iterator {
65  public:
66  Iterator(DirectedNetInterfaceSet& interfaces);
67  virtual ~Iterator();
68 
69  DirectedNetInterface* next(); // NULL iff none
70 
71  private:
73  };
74 
75 private:
76  friend class Iterator;
78 };
79 
80 class Socket: public NetInterface {
81 public:
82  virtual ~Socket();
83  void reset(); // closes the socket, and sets "fSocketNum" to -1
84 
85  virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize,
86  unsigned& bytesRead,
87  struct sockaddr_in& fromAddress) = 0;
88  // Returns False on error; resultData == NULL if data ignored
89 
90  int socketNum() const { return fSocketNum; }
91 
92  Port port() const {
93  return fPort;
94  }
95 
96  UsageEnvironment& env() const { return fEnv; }
97 
98  static int DebugLevel;
99 
100 protected:
101  Socket(UsageEnvironment& env, Port port); // virtual base class
102 
103  Boolean changePort(Port newPort); // will also cause socketNum() to change
104 
105 private:
109 };
110 
112 
113 // A data structure for looking up a Socket by port:
114 
116 public:
117  virtual ~SocketLookupTable();
118 
119  Socket* Fetch(UsageEnvironment& env, Port port, Boolean& isNew);
120  // Creates a new Socket if none already exists
121  Boolean Remove(Socket const* sock);
122 
123 protected:
124  SocketLookupTable(); // abstract base class
125  virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0;
126 
127 private:
129 };
130 
131 // A data structure for counting traffic:
132 
134 public:
136 
137  void countPacket(unsigned packetSize);
138 
139  float totNumPackets() const {return fTotNumPackets;}
140  float totNumBytes() const {return fTotNumBytes;}
141 
142  Boolean haveSeenTraffic() const;
143 
144 private:
147 };
148 
149 #endif
unsigned char Boolean
Definition: Boolean.hh:25
virtual Socket * CreateNew(UsageEnvironment &env, Port port)=0
Port fPort
virtual Boolean SourceAddrOKForRelaying(UsageEnvironment &env, unsigned addr)=0
Boolean changePort(Port newPort)
HashTable * fTable
virtual Boolean handleRead(unsigned char *buffer, unsigned bufferMaxSize, unsigned &bytesRead, struct sockaddr_in &fromAddress)=0
virtual ~Socket()
Iterator(DirectedNetInterfaceSet &interfaces)
virtual Boolean write(unsigned char *data, unsigned numBytes)=0
virtual ~NetInterface()
Boolean Remove(DirectedNetInterface const *interf)
virtual ~DirectedNetInterfaceSet()
int fSocketNum
void reset()
Boolean IsEmpty() const
Definition: HashTable.hh:41
UsageEnvironment & fEnv
DirectedNetInterface * next()
Boolean Remove(Socket const *sock)
Port port() const
Definition: NetInterface.hh:92
float totNumPackets() const
Boolean haveSeenTraffic() const
UsageEnvironment & operator<<(UsageEnvironment &s, const Socket &sock)
HashTable::Iterator * fIter
Definition: NetInterface.hh:72
virtual ~SocketLookupTable()
static int DebugLevel
Definition: NetInterface.hh:98
void countPacket(unsigned packetSize)
virtual ~DirectedNetInterface()
static UsageEnvironment * DefaultUsageEnvironment
Definition: NetInterface.hh:32
UsageEnvironment & env() const
Definition: NetInterface.hh:96
Socket * Fetch(UsageEnvironment &env, Port port, Boolean &isNew)
Socket(UsageEnvironment &env, Port port)
int socketNum() const
Definition: NetInterface.hh:90
DirectedNetInterface * Add(DirectedNetInterface const *interf)