live
NetInterface.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "groupsock"
17// Copyright (c) 1996-2024 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
29public:
30 virtual ~NetInterface();
31
33 // if non-NULL, used for each new interface
34
35protected:
36 NetInterface(); // virtual base class
37};
38
39class Socket: public NetInterface {
40public:
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
59protected:
60 Socket(UsageEnvironment& env, Port port, int family); // virtual base class
61
62 Boolean changePort(Port newPort); // will also cause socketNum() to change
63
64private:
69};
70
72
73// A data structure for looking up a Socket by port:
74
76public:
78
80 // Creates a new Socket if none already exists
81 Boolean Remove(Socket const* sock);
82
83protected:
84 SocketLookupTable(); // abstract base class
85 virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0;
86
87private:
89};
90
91// A data structure for counting traffic:
92
94public:
96
97 void countPacket(unsigned packetSize);
98
99 float totNumPackets() const {return fTotNumPackets;}
100 float totNumBytes() const {return fTotNumBytes;}
101
103
104private:
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()
Socket * Fetch(UsageEnvironment &env, Port port, Boolean &isNew)
HashTable * fTable
Definition: NetInterface.hh:88
virtual ~SocketLookupTable()
virtual Socket * CreateNew(UsageEnvironment &env, Port port)=0
Boolean Remove(Socket const *sock)
int fFamily
Definition: NetInterface.hh:68
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
UsageEnvironment & env() const
Definition: NetInterface.hh:55