xrootd
Server.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef SERVER_HH
20 #define SERVER_HH
21 
22 #include <map>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 #include <stdint.h>
27 #include <pthread.h>
28 
29 namespace XrdClTests {
30 
31 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
35 {
36  public:
37  //--------------------------------------------------------------------------
39  //--------------------------------------------------------------------------
40  ClientHandler();
41 
42  //--------------------------------------------------------------------------
44  //--------------------------------------------------------------------------
45  virtual ~ClientHandler();
46 
47  //--------------------------------------------------------------------------
51  //--------------------------------------------------------------------------
52  virtual void HandleConnection( int socket ) = 0;
53 
54  //--------------------------------------------------------------------------
56  //--------------------------------------------------------------------------
57  void UpdateSentData( char *buffer, uint32_t size );
58 
59  //--------------------------------------------------------------------------
61  //--------------------------------------------------------------------------
62  void UpdateReceivedData( char *buffer, uint32_t size );
63 
64  //--------------------------------------------------------------------------
66  //--------------------------------------------------------------------------
67  uint64_t GetSentBytes() const
68  {
69  return pSentBytes;
70  }
71 
72  //--------------------------------------------------------------------------
74  //--------------------------------------------------------------------------
75  uint32_t GetSentChecksum() const
76  {
77  return pSentChecksum;
78  }
79 
80  //--------------------------------------------------------------------------
82  //--------------------------------------------------------------------------
83  uint64_t GetReceivedBytes() const
84  {
85  return pReceivedBytes;
86  }
87 
88  //--------------------------------------------------------------------------
90  //--------------------------------------------------------------------------
91  uint32_t GetReceivedChecksum() const
92  {
93  return pReceivedChecksum;
94  }
95 
96 
97  private:
98  uint64_t pSentBytes;
99  uint64_t pReceivedBytes;
100  uint32_t pSentChecksum;
102 };
103 
104 //------------------------------------------------------------------------------
106 //------------------------------------------------------------------------------
108 {
109  public:
110  //--------------------------------------------------------------------------
112  //--------------------------------------------------------------------------
113  virtual ~ClientHandlerFactory() {};
114 
115  //--------------------------------------------------------------------------
117  //--------------------------------------------------------------------------
118  virtual ClientHandler *CreateHandler() = 0;
119 };
120 
121 //------------------------------------------------------------------------------
122 // Forward declaration
123 //------------------------------------------------------------------------------
124 struct ClientHelper;
125 
126 //------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------
129 class Server
130 {
131  public:
132  typedef std::map<std::string, std::pair<uint64_t, uint32_t> > TransferMap;
133 
134  //--------------------------------------------------------------------------
136  //--------------------------------------------------------------------------
137  Server();
138 
139  //--------------------------------------------------------------------------
141  //--------------------------------------------------------------------------
142  ~Server();
143 
144  //--------------------------------------------------------------------------
151  //--------------------------------------------------------------------------
152  bool Setup( int port, int accept, ClientHandlerFactory *factory );
153 
154  //--------------------------------------------------------------------------
156  //--------------------------------------------------------------------------
157  bool Start();
158 
159  //--------------------------------------------------------------------------
162  //--------------------------------------------------------------------------
163  bool Stop();
164 
165  //--------------------------------------------------------------------------
167  //--------------------------------------------------------------------------
168  std::pair<uint64_t, uint32_t> GetSentStats( const std::string host ) const;
169 
170  //--------------------------------------------------------------------------
172  //--------------------------------------------------------------------------
173  std::pair<uint64_t, uint32_t> GetReceivedStats( const std::string host ) const;
174 
175  //--------------------------------------------------------------------------
177  //--------------------------------------------------------------------------
178  int HandleConnections();
179 
180  private:
181 
184  pthread_t pServerThread;
185  std::vector<ClientHelper*> pClients;
188 };
189 
190 }
191 
192 #endif // SERVER_HH