xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdNet
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
/* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9
/* Produced by Andrew Hanushevsky for Stanford University under contract */
10
/* DE-AC03-76-SFO0515 with the Department of Energy */
11
/******************************************************************************/
12
13
// $Id$
14
15
#include <stdlib.h>
16
#include <string.h>
17
#ifndef WIN32
18
#include <strings.h>
19
#include <unistd.h>
20
#include <netinet/in.h>
21
#include <sys/socket.h>
22
#else
23
#include <Winsock2.h>
24
#endif
25
26
#include "
XrdNet/XrdNetBuffer.hh
"
27
#include "
XrdNet/XrdNetOpts.hh
"
28
29
class
XrdNetPeer
;
30
class
XrdNetSecurity
;
31
class
XrdSysError
;
32
33
class
XrdNet
34
{
35
public
:
36
37
// Accept() processes incomming connections. When a succesful connection is
38
// made, it places the connection informatio in myPeer and returns
39
// true (1). If a timeout or permanent error occurs, it returns
40
// false (0). The opts are those defined above and timeout is
41
// specified as seconds. Use this method to associate specialized
42
// versions of XrdNetLink objects with the connection.
43
//
44
int
Accept
(
XrdNetPeer
&myPeer,
45
int
opts
=0,
46
int
timeout=-1);
47
48
// Bind() binds this object to a communications medium. This may be TCP or
49
// UDP network via the given port number or a Unix named socket
50
// specified by path (the second form).
51
// Bind() returns 0 upon success or -errno upon failure.
52
//
53
int
Bind
(
int
port
,
// Port number
54
const
char
*contype=
"tcp"
// "tcp" or "udp"
55
);
56
int
Bind
(
char
*path,
// Unix path < |109|
57
const
char
*contype=
"stream"
// stream | datagram
58
);
59
60
// Connect() Creates a socket and connects to the given host and port. Upon
61
// success, it fills in the peer object describing the connection.
62
// and returns true (1). Upon failure it returns zero. Opts are as
63
// above. A timeout, in seconds, may be specified. Use this method to
64
// associate specialized versions of XrdNetLink with the connection.
65
//
66
int
Connect
(
XrdNetPeer
&myPeer,
67
const
char
*host,
// Destination host or ip address
68
int
port,
// Port number
69
int
opts
=0,
// Options
70
int
timeout=-1
// Second timeout
71
);
72
73
// Relay() creates a UDP socket and optionally decomposes a destination
74
// of the form host:port. Upon success it fills in the Peer object
75
// and return true (1). Upon failure, it returns false (0).
76
//
77
int
Relay
(
XrdNetPeer
&Peer,
// Peer object to be initialized
78
const
char
*dest,
// Optional destination
79
int
opts
=0
// Optional options as above
80
);
81
82
// Port() returns he port number, if any, bound to this network.
83
//
84
int
Port
() {
return
Portnum
;}
85
86
// Secure() adds the given NetSecurity object to the existing security
87
// constraints. The supplied object is ultimately deleted in the
88
// process and cannot be referenced.
89
//
90
void
Secure
(
XrdNetSecurity
*secp);
91
92
// setDefaults() sets the default socket options, and buffer size for UDP
93
// sockets (default is 32k) or window size for TCP sockets
94
// (defaults to OS default).
95
//
96
void
setDefaults
(
int
options,
int
buffsz=0)
97
{
netOpts
= options;
Windowsz
= buffsz;}
98
99
// setDomain() is used to indicate what part of the hostname is so common
100
// that it may be trimmed of for incomming hostnames. This is
101
// usually the domain in which this object resides/
102
//
103
void
setDomain
(
const
char
*dname)
104
{
if
(
Domain
) free(
Domain
);
105
Domain
= strdup(dname);
106
Domlen
= strlen(dname);
107
}
108
109
// Trim() trims off the domain name in hname (it's modified).
110
//
111
void
Trim
(
char
*hname);
112
113
// unbind() Destroys the association between this object and whatever
114
// communications medium it was previously bound to.
115
//
116
void
unBind
();
117
118
// WSzize() Returns the actual RCVBUF window size. A value of zero
119
// indicates that an error has occurred.
120
//
121
int
WSize
();
122
123
// When creating this object, you must specify the error routing object.
124
// Optionally, specify the security object to screen incomming connections.
125
// (if zero, no screening is done).
126
//
127
XrdNet
(
XrdSysError
*erp,
XrdNetSecurity
*secp=0);
128
~XrdNet
();
129
130
protected
:
131
132
XrdSysError
*
eDest
;
133
XrdNetSecurity
*
Police
;
134
char
*
Domain
;
135
int
Domlen
;
136
int
iofd
;
137
int
Portnum
;
138
int
PortType
;
139
int
Windowsz
;
140
int
netOpts
;
141
int
BuffSize
;
142
XrdNetBufferQ
*
BuffQ
;
143
144
private
:
145
146
int
do_Accept_TCP
(
XrdNetPeer
&myPeer,
int
opts
);
147
int
do_Accept_UDP
(
XrdNetPeer
&myPeer,
int
opts
);
148
};
149
#endif
Generated by
1.8.1.2