XRootD
XrdNet.hh
Go to the documentation of this file.
1 #ifndef __XRDNET_H__
2 #define __XRDNET_H__
3 /******************************************************************************/
4 /* */
5 /* X r d N e t . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <cstdlib>
33 #include <cstring>
34 #ifndef WIN32
35 #include <strings.h>
36 #include <unistd.h>
37 #include <netinet/in.h>
38 #include <sys/socket.h>
39 #else
40 #include <Winsock2.h>
41 #endif
42 
43 #include "XrdNet/XrdNetOpts.hh"
44 
45 class XrdNetAddr;
46 class XrdNetBufferQ;
47 class XrdNetPeer;
48 class XrdNetSecurity;
49 class XrdSysError;
50 
51 class XrdNet
52 {
53 public:
54 
55 //------------------------------------------------------------------------------
69 //------------------------------------------------------------------------------
70 
71 int Accept(XrdNetAddr &myAddr,
72  int opts=0,
73  int timeout=-1);
74 
75 //------------------------------------------------------------------------------
93 //------------------------------------------------------------------------------
94 
95 int Accept(XrdNetPeer &myPeer,
96  int opts=0,
97  int timeout=-1);
98 
99 //------------------------------------------------------------------------------
107 //------------------------------------------------------------------------------
108 
109 int Bind( int port, // Port number
110  const char *contype="tcp" // "tcp" or "udp"
111  );
112 
113 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 
124 int Bind( char *path, // Unix path < |109|
125  const char *contype="stream" // stream | datagram
126  );
127 
128 //------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------
147 
148 int Connect(XrdNetAddr &myAddr,
149  const char *dest, // Destination host or ip address
150  int port=-1, // Port number
151  int opts=0, // Options
152  int timeout=-1 // Second timeout
153  );
154 
155 //------------------------------------------------------------------------------
175 //------------------------------------------------------------------------------
176 
177 int Connect(XrdNetPeer &myPeer,
178  const char *dest, // Destination host or ip address
179  int port=-1, // Port number
180  int opts=0, // Options
181  int timeout=-1 // Second timeout
182  );
183 
184 //------------------------------------------------------------------------------
189 //------------------------------------------------------------------------------
190 
191 int Port() {return Portnum;}
192 
193 // Relay() creates a UDP socket and optionally decomposes a destination
194 // of the form host:port. Upon success it fills in the Peer object
195 // and return true (1). Upon failure, it returns false (0).
196 //
197 int Relay(XrdNetPeer &Peer, // Peer object to be initialized
198  const char *dest, // Optional destination
199  int opts=0 // Optional options as above
200  );
201 
202 int Relay(const char *dest); // Optional destination
203 
204 //------------------------------------------------------------------------------
210 //------------------------------------------------------------------------------
211 
212 virtual void Secure(XrdNetSecurity *secp);
213 
214 //------------------------------------------------------------------------------
221 //------------------------------------------------------------------------------
222 
223 void setDefaults(int options, int buffsz=0)
224  {netOpts = options; Windowsz = buffsz;}
225 
226 //------------------------------------------------------------------------------
231 //------------------------------------------------------------------------------
232 
233 void setDomain(const char *dname)
234  {if (Domain) free(Domain);
235  Domain = strdup(dname);
236  Domlen = strlen(dname);
237  }
238 
239 //------------------------------------------------------------------------------
243 //------------------------------------------------------------------------------
244 
245 void Trim(char *hname);
246 
247 //------------------------------------------------------------------------------
249 //------------------------------------------------------------------------------
250 
251 void unBind();
252 
253 //------------------------------------------------------------------------------
259 //------------------------------------------------------------------------------
260 
261 int WSize();
262 
263 //------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------
272 
273  XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0);
274 
275 //------------------------------------------------------------------------------
277 //------------------------------------------------------------------------------
278 
279 virtual ~XrdNet();
280 
281 protected:
282 
285 char *Domain;
286 int Domlen;
287 int iofd;
294 
295 private:
296 
297 int do_Accept_TCP(XrdNetAddr &myAddr, int opts);
298 int do_Accept_TCP(XrdNetPeer &myPeer, int opts);
299 int do_Accept_UDP(XrdNetPeer &myPeer, int opts);
300 };
301 #endif
struct myOpts opts
Definition: XrdNet.hh:52
char * Domain
Definition: XrdNet.hh:285
int Windowsz
Definition: XrdNet.hh:290
int Bind(int port, const char *contype="tcp")
Definition: XrdNet.cc:164
XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0)
Definition: XrdNet.cc:60
int iofd
Definition: XrdNet.hh:287
XrdSysError * eDest
Definition: XrdNet.hh:283
XrdNetBufferQ * BuffQ
Definition: XrdNet.hh:293
XrdNetSecurity * Police
Definition: XrdNet.hh:284
int netOpts
Definition: XrdNet.hh:291
void unBind()
Unbind the network from any bound resouces.
Definition: XrdNet.cc:358
int Connect(XrdNetAddr &myAddr, const char *dest, int port=-1, int opts=0, int timeout=-1)
Definition: XrdNet.cc:252
int Relay(XrdNetPeer &Peer, const char *dest, int opts=0)
Definition: XrdNet.cc:310
int Domlen
Definition: XrdNet.hh:286
int Portnum
Definition: XrdNet.hh:288
int BuffSize
Definition: XrdNet.hh:292
int Accept(XrdNetAddr &myAddr, int opts=0, int timeout=-1)
Definition: XrdNet.cc:84
virtual void Secure(XrdNetSecurity *secp)
Definition: XrdNet.cc:329
int WSize()
Definition: XrdNet.cc:368
virtual ~XrdNet()
Destructor.
Definition: XrdNet.cc:74
int Port()
Definition: XrdNet.hh:191
void setDomain(const char *dname)
Definition: XrdNet.hh:233
int PortType
Definition: XrdNet.hh:289
void Trim(char *hname)
Definition: XrdNet.cc:343
void setDefaults(int options, int buffsz=0)
Definition: XrdNet.hh:223