00001 #ifndef __XRDNET_H__ 00002 #define __XRDNET_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d N e t . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <stdlib.h> 00033 #include <string.h> 00034 #ifndef WIN32 00035 #include <strings.h> 00036 #include <unistd.h> 00037 #include <netinet/in.h> 00038 #include <sys/socket.h> 00039 #else 00040 #include <Winsock2.h> 00041 #endif 00042 00043 #include "XrdNet/XrdNetOpts.hh" 00044 00045 class XrdNetAddr; 00046 class XrdNetBufferQ; 00047 class XrdNetPeer; 00048 class XrdNetSecurity; 00049 class XrdSysError; 00050 00051 class XrdNet 00052 { 00053 public: 00054 00055 //------------------------------------------------------------------------------ 00069 //------------------------------------------------------------------------------ 00070 00071 int Accept(XrdNetAddr &myAddr, 00072 int opts=0, 00073 int timeout=-1); 00074 00075 //------------------------------------------------------------------------------ 00092 //------------------------------------------------------------------------------ 00093 00094 int Accept(XrdNetPeer &myPeer, 00095 int opts=0, 00096 int timeout=-1); 00097 00098 //------------------------------------------------------------------------------ 00106 //------------------------------------------------------------------------------ 00107 00108 int Bind( int port, // Port number 00109 const char *contype="tcp" // "tcp" or "udp" 00110 ); 00111 00112 //------------------------------------------------------------------------------ 00121 //------------------------------------------------------------------------------ 00122 00123 int Bind( char *path, // Unix path < |109| 00124 const char *contype="stream" // stream | datagram 00125 ); 00126 00127 //------------------------------------------------------------------------------ 00145 //------------------------------------------------------------------------------ 00146 00147 int Connect(XrdNetAddr &myAddr, 00148 const char *dest, // Destination host or ip address 00149 int port=-1, // Port number 00150 int opts=0, // Options 00151 int timeout=-1 // Second timeout 00152 ); 00153 00154 //------------------------------------------------------------------------------ 00174 //------------------------------------------------------------------------------ 00175 00176 int Connect(XrdNetPeer &myPeer, 00177 const char *dest, // Destination host or ip address 00178 int port=-1, // Port number 00179 int opts=0, // Options 00180 int timeout=-1 // Second timeout 00181 ); 00182 00183 //------------------------------------------------------------------------------ 00188 //------------------------------------------------------------------------------ 00189 00190 int Port() {return Portnum;} 00191 00192 // Relay() creates a UDP socket and optionally decomposes a destination 00193 // of the form host:port. Upon success it fills in the Peer object 00194 // and return true (1). Upon failure, it returns false (0). 00195 // 00196 int Relay(XrdNetPeer &Peer, // Peer object to be initialized 00197 const char *dest, // Optional destination 00198 int opts=0 // Optional options as above 00199 ); 00200 00201 int Relay(const char *dest); // Optional destination 00202 00203 //------------------------------------------------------------------------------ 00209 //------------------------------------------------------------------------------ 00210 00211 virtual void Secure(XrdNetSecurity *secp); 00212 00213 //------------------------------------------------------------------------------ 00220 //------------------------------------------------------------------------------ 00221 00222 void setDefaults(int options, int buffsz=0) 00223 {netOpts = options; Windowsz = buffsz;} 00224 00225 //------------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------------ 00231 00232 void setDomain(const char *dname) 00233 {if (Domain) free(Domain); 00234 Domain = strdup(dname); 00235 Domlen = strlen(dname); 00236 } 00237 00238 //------------------------------------------------------------------------------ 00242 //------------------------------------------------------------------------------ 00243 00244 void Trim(char *hname); 00245 00246 //------------------------------------------------------------------------------ 00248 //------------------------------------------------------------------------------ 00249 00250 void unBind(); 00251 00252 //------------------------------------------------------------------------------ 00258 //------------------------------------------------------------------------------ 00259 00260 int WSize(); 00261 00262 //------------------------------------------------------------------------------ 00270 //------------------------------------------------------------------------------ 00271 00272 XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0); 00273 00274 //------------------------------------------------------------------------------ 00276 //------------------------------------------------------------------------------ 00277 00278 virtual ~XrdNet(); 00279 00280 protected: 00281 00282 XrdSysError *eDest; 00283 XrdNetSecurity *Police; 00284 char *Domain; 00285 int Domlen; 00286 int iofd; 00287 int Portnum; 00288 int PortType; 00289 int Windowsz; 00290 int netOpts; 00291 int BuffSize; 00292 XrdNetBufferQ *BuffQ; 00293 00294 private: 00295 00296 int do_Accept_TCP(XrdNetAddr &myAddr, int opts); 00297 int do_Accept_TCP(XrdNetPeer &myPeer, int opts); 00298 int do_Accept_UDP(XrdNetPeer &myPeer, int opts); 00299 }; 00300 #endif