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 <stdlib.h>
33#include <string.h>
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//------------------------------------------------------------------------------
92//------------------------------------------------------------------------------
93
94int Accept(XrdNetPeer &myPeer,
95 int opts=0,
96 int timeout=-1);
97
98//------------------------------------------------------------------------------
106//------------------------------------------------------------------------------
107
108int Bind( int port, // Port number
109 const char *contype="tcp" // "tcp" or "udp"
110 );
111
112//------------------------------------------------------------------------------
121//------------------------------------------------------------------------------
122
123int Bind( char *path, // Unix path < |109|
124 const char *contype="stream" // stream | datagram
125 );
126
127//------------------------------------------------------------------------------
145//------------------------------------------------------------------------------
146
147int Connect(XrdNetAddr &myAddr,
148 const char *dest, // Destination host or ip address
149 int port=-1, // Port number
150 int opts=0, // Options
151 int timeout=-1 // Second timeout
152 );
153
154//------------------------------------------------------------------------------
174//------------------------------------------------------------------------------
175
176int Connect(XrdNetPeer &myPeer,
177 const char *dest, // Destination host or ip address
178 int port=-1, // Port number
179 int opts=0, // Options
180 int timeout=-1 // Second timeout
181 );
182
183//------------------------------------------------------------------------------
188//------------------------------------------------------------------------------
189
190int Port() {return Portnum;}
191
192// Relay() creates a UDP socket and optionally decomposes a destination
193// of the form host:port. Upon success it fills in the Peer object
194// and return true (1). Upon failure, it returns false (0).
195//
196int Relay(XrdNetPeer &Peer, // Peer object to be initialized
197 const char *dest, // Optional destination
198 int opts=0 // Optional options as above
199 );
200
201int Relay(const char *dest); // Optional destination
202
203//------------------------------------------------------------------------------
209//------------------------------------------------------------------------------
210
211virtual void Secure(XrdNetSecurity *secp);
212
213//------------------------------------------------------------------------------
220//------------------------------------------------------------------------------
221
222void setDefaults(int options, int buffsz=0)
223 {netOpts = options; Windowsz = buffsz;}
224
225//------------------------------------------------------------------------------
230//------------------------------------------------------------------------------
231
232void setDomain(const char *dname)
233 {if (Domain) free(Domain);
234 Domain = strdup(dname);
235 Domlen = strlen(dname);
236 }
237
238//------------------------------------------------------------------------------
242//------------------------------------------------------------------------------
243
244void Trim(char *hname);
245
246//------------------------------------------------------------------------------
248//------------------------------------------------------------------------------
249
250void unBind();
251
252//------------------------------------------------------------------------------
258//------------------------------------------------------------------------------
259
260int WSize();
261
262//------------------------------------------------------------------------------
270//------------------------------------------------------------------------------
271
273
274//------------------------------------------------------------------------------
276//------------------------------------------------------------------------------
277
278virtual ~XrdNet();
279
280protected:
281
284char *Domain;
293
294private:
295
296int do_Accept_TCP(XrdNetAddr &myAddr, int opts);
297int do_Accept_TCP(XrdNetPeer &myPeer, int opts);
298int do_Accept_UDP(XrdNetPeer &myPeer, int opts);
299};
300#endif
Definition: XrdNetAddr.hh:42
Definition: XrdNetBuffer.hh:45
Definition: XrdNetPeer.hh:39
Definition: XrdNetSecurity.hh:44
Definition: XrdNet.hh:52
char * Domain
Definition: XrdNet.hh:284
int Windowsz
Definition: XrdNet.hh:289
int Bind(int port, const char *contype="tcp")
int Relay(const char *dest)
int Connect(XrdNetPeer &myPeer, const char *dest, int port=-1, int opts=0, int timeout=-1)
XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0)
int iofd
Definition: XrdNet.hh:286
XrdSysError * eDest
Definition: XrdNet.hh:282
XrdNetBufferQ * BuffQ
Definition: XrdNet.hh:292
int Accept(XrdNetPeer &myPeer, int opts=0, int timeout=-1)
XrdNetSecurity * Police
Definition: XrdNet.hh:283
int netOpts
Definition: XrdNet.hh:290
void unBind()
Unbind the network from any bound resouces.
int do_Accept_UDP(XrdNetPeer &myPeer, int opts)
int Connect(XrdNetAddr &myAddr, const char *dest, int port=-1, int opts=0, int timeout=-1)
int Relay(XrdNetPeer &Peer, const char *dest, int opts=0)
int do_Accept_TCP(XrdNetAddr &myAddr, int opts)
int Domlen
Definition: XrdNet.hh:285
int do_Accept_TCP(XrdNetPeer &myPeer, int opts)
int Portnum
Definition: XrdNet.hh:287
virtual void Secure(XrdNetSecurity *secp)
int BuffSize
Definition: XrdNet.hh:291
int Accept(XrdNetAddr &myAddr, int opts=0, int timeout=-1)
int WSize()
virtual ~XrdNet()
Destructor.
int Bind(char *path, const char *contype="stream")
int Port()
Definition: XrdNet.hh:190
void setDomain(const char *dname)
Definition: XrdNet.hh:232
int PortType
Definition: XrdNet.hh:288
void Trim(char *hname)
void setDefaults(int options, int buffsz=0)
Definition: XrdNet.hh:222
Definition: XrdSysError.hh:90