XRootD
Loading...
Searching...
No Matches
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
45class XrdNetAddr;
46class XrdNetBufferQ;
47class XrdNetPeer;
48class XrdNetSecurity;
49class XrdSysError;
50
51class XrdNet
52{
53public:
54
55//------------------------------------------------------------------------------
69//------------------------------------------------------------------------------
70
71int Accept(XrdNetAddr &myAddr,
72 int opts=0,
73 int timeout=-1);
74
75//------------------------------------------------------------------------------
93//------------------------------------------------------------------------------
94
95int Accept(XrdNetPeer &myPeer,
96 int opts=0,
97 int timeout=-1);
98
99//------------------------------------------------------------------------------
107//------------------------------------------------------------------------------
108
109int Bind( int port, // Port number
110 const char *contype="tcp" // "tcp" or "udp"
111 );
112
113//------------------------------------------------------------------------------
122//------------------------------------------------------------------------------
123
124int Bind( char *path, // Unix path < |109|
125 const char *contype="stream" // stream | datagram
126 );
127
128//------------------------------------------------------------------------------
146//------------------------------------------------------------------------------
147
148int 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
177int 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
191int 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//
197int 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// Relay() V2 only takes an optional dest and return a non-negative file
203// descriptor upon success or -1 upon failure.
204//
205int Relay(const char *dest); // Optional destination
206
207//------------------------------------------------------------------------------
213//------------------------------------------------------------------------------
214
215virtual void Secure(XrdNetSecurity *secp);
216
217//------------------------------------------------------------------------------
224//------------------------------------------------------------------------------
225
226void setDefaults(int options, int buffsz=0)
227 {netOpts = options; Windowsz = buffsz;}
228
229//------------------------------------------------------------------------------
234//------------------------------------------------------------------------------
235
236void setDomain(const char *dname)
237 {if (Domain) free(Domain);
238 Domain = strdup(dname);
239 Domlen = strlen(dname);
240 }
241
242//------------------------------------------------------------------------------
246//------------------------------------------------------------------------------
247
248void Trim(char *hname);
249
250//------------------------------------------------------------------------------
252//------------------------------------------------------------------------------
253
254void unBind();
255
256//------------------------------------------------------------------------------
262//------------------------------------------------------------------------------
263
264int WSize();
265
266//------------------------------------------------------------------------------
274//------------------------------------------------------------------------------
275
276 XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0);
277
278//------------------------------------------------------------------------------
280//------------------------------------------------------------------------------
281
282virtual ~XrdNet();
283
284protected:
285
288char *Domain;
297
298private:
299
300int do_Accept_TCP(XrdNetAddr &myAddr, int opts);
301int do_Accept_TCP(XrdNetPeer &myPeer, int opts);
302int do_Accept_UDP(XrdNetPeer &myPeer, int opts);
303};
304#endif
struct myOpts opts
char * Domain
Definition XrdNet.hh:288
int Windowsz
Definition XrdNet.hh:293
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:290
XrdSysError * eDest
Definition XrdNet.hh:286
XrdNetBufferQ * BuffQ
Definition XrdNet.hh:296
XrdNetSecurity * Police
Definition XrdNet.hh:287
int netOpts
Definition XrdNet.hh:294
void unBind()
Unbind the network from any bound resouces.
Definition XrdNet.cc:361
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:313
int Domlen
Definition XrdNet.hh:289
int Portnum
Definition XrdNet.hh:291
int BuffSize
Definition XrdNet.hh:295
int Accept(XrdNetAddr &myAddr, int opts=0, int timeout=-1)
Definition XrdNet.cc:84
virtual void Secure(XrdNetSecurity *secp)
Definition XrdNet.cc:332
int WSize()
Definition XrdNet.cc:371
virtual ~XrdNet()
Destructor.
Definition XrdNet.cc:74
int Port()
Definition XrdNet.hh:191
void setDomain(const char *dname)
Definition XrdNet.hh:236
int PortType
Definition XrdNet.hh:292
void Trim(char *hname)
Definition XrdNet.cc:346
void setDefaults(int options, int buffsz=0)
Definition XrdNet.hh:226