blob: dee5fb2729920a19324d530ae94a1abc4dcf5217 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* netmanager.h
*
* Copyright (c) 1998, 1999, Alexander Neundorf
* [email protected]
*
* You may distribute under the terms of the GNU General Public
* License as specified in the COPYING file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef NETMANAGER_H
#define NETMANAGER_H
#include <list>
#include "netscanner.h"
#include "client.h"
#include "mystring.h"
#include "configfile.h"
#include "lisadefines.h"
struct MyFrameType
{
int id;
//keep some room for later extensions
int unused1;
int unused2;
int unused3;
};
#define MYFRAMELENGTH 16
class NetManager:public NetScanner
{
public:
NetManager(int& rawSocketFD, int portToUse, MyString configFile, int configStyle=UNIXCONFIGSTYLE, int strictMode=0);
~NetManager();
int prepare();
int run();
int writeDataToFD(int fd, int serverServer);
void readConfig();
void configure(Config& config);
int isBeingScanned() {return m_isBeingScanned;};
int isInformed() {return m_isInformed;};
//int uptime();
void printState();
protected:
int m_listenFD;
int m_bcFD;
int m_basePort;
int m_pipeFD;
char *m_receiveBuffer;
size_t m_receivedBytes;
struct timeval tv;
pid_t m_childPid;
time_t m_lastUpdate;
time_t m_startedAt;
int m_isInformed;
int m_isBeingScanned;
int m_firstRun;
int m_serverServer;
int m_servedThisPeriod;
int m_serveCount;
int m_refreshTime;
int m_initialRefreshTime;
int m_increasedRefreshTime;
int m_broadcastAddress;
std::list<Client> clients;
struct client_is_done : std::unary_function<Client, bool>
{
bool operator() (Client& c)
{
return (c.done() != 0 || c.age() > 30);
}
};
int getMaxFD();
void generateFDset(fd_set *tmpFDs);
//returns 0 on timeout, otherwise 1
int waitForSomethingToHappen(fd_set *tmpFDs);
void scan();
void addClient(int socketFD);
void checkClientsAndPipes(fd_set *tmpFDs);
int readDataFromFD(int fd);
int processScanResults();
int findServerServer();
void getListFromServerServer(int address);
void enableServerServer(int on);
void serveAndClean();
void answerBroadcast();
void adjustRefreshTime(int serverServer);
MyString m_extraConfigFile;
int m_configStyle;
MyString getConfigFileName();
MyString m_usedConfigFileName;
};
#endif
|