XrdNet.hh

Go to the documentation of this file.
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 XrdNetBufferQ;
00046 class XrdNetPeer;
00047 class XrdNetSecurity;
00048 class XrdSysError;
00049 
00050 class XrdNet
00051 {
00052 public:
00053 
00054 // Accept()   processes incomming connections. When a succesful connection is
00055 //            made, it places the connection informatio in myPeer and returns
00056 //            true (1). If a timeout or permanent error occurs, it returns
00057 //            false (0). The opts are those defined above and timeout is
00058 //            specified as seconds. Use this method to associate specialized
00059 //            versions of XrdNetLink objects with the connection.
00060 //
00061 int             Accept(XrdNetPeer &myPeer,
00062                        int opts=0,
00063                        int timeout=-1);
00064 
00065 // Bind()     binds this object to a communications medium. This may be TCP or
00066 //            UDP network via the given port number or a Unix named socket
00067 //            specified by path (the second form).
00068 //            Bind() returns 0 upon success or -errno upon failure.
00069 //
00070 int             Bind(      int   port,             // Port number
00071                      const char *contype="tcp"     // "tcp" or "udp"
00072                     );
00073 int             Bind(      char *path,             // Unix path < |109|
00074                      const char *contype="stream"  // stream | datagram
00075                     );
00076 
00077 // Connect() Creates a socket and connects to the given host and port. Upon
00078 //           success, it fills in the peer object describing the connection.
00079 //           and returns true (1). Upon failure it returns zero. Opts are as 
00080 //           above. A timeout, in seconds, may be specified. Use this method to
00081 //           associate specialized versions of XrdNetLink with the connection.
00082 //
00083 int             Connect(XrdNetPeer &myPeer,
00084                         const char *host,  // Destination host or ip address
00085                         int   port,        // Port number
00086                         int   opts=0,      // Options
00087                         int   timeout=-1   // Second timeout
00088                        );
00089 
00090 // Relay() creates a UDP socket and optionally decomposes a destination
00091 //         of the form host:port. Upon success it fills in the Peer object
00092 //         and return true (1). Upon failure, it returns false (0).
00093 //
00094 int             Relay(XrdNetPeer &Peer,   // Peer object to be initialized
00095                       const char *dest,   // Optional destination
00096                       int         opts=0  // Optional options as above
00097                      );
00098 
00099 // Port() returns he port number, if any, bound to this network.
00100 //
00101 int             Port() {return Portnum;}
00102 
00103 // Secure() adds the given NetSecurity object to the existing security
00104 //          constraints. The supplied object is ultimately deleted in the
00105 //          process and cannot be referenced.
00106 //
00107 void            Secure(XrdNetSecurity *secp);
00108 
00109 // setDefaults() sets the default socket options, and buffer size for UDP
00110 //               sockets (default is 32k) or window size for TCP sockets
00111 //               (defaults to OS default).
00112 //
00113 void            setDefaults(int options, int buffsz=0)
00114                            {netOpts = options; Windowsz = buffsz;}
00115 
00116 // setDomain() is used to indicate what part of the hostname is so common
00117 //             that it may be trimmed of for incomming hostnames. This is
00118 //             usually the domain in which this object resides/
00119 //
00120 void            setDomain(const char *dname)
00121                          {if (Domain) free(Domain);
00122                           Domain = strdup(dname);
00123                           Domlen = strlen(dname);
00124                          }
00125 
00126 // Trim() trims off the domain name in hname (it's modified).
00127 //
00128 void            Trim(char *hname);
00129 
00130 // unbind()    Destroys the association between this object and whatever
00131 //             communications medium it was previously bound to.
00132 //
00133 void            unBind();
00134 
00135 // WSzize()    Returns the actual RCVBUF window size. A value of zero
00136 //             indicates that an error has occurred.
00137 //
00138 int            WSize();
00139 
00140 // When creating this object, you must specify the error routing object.
00141 // Optionally, specify the security object to screen incomming connections.
00142 // (if zero, no screening is done).
00143 //
00144                 XrdNet(XrdSysError *erp, XrdNetSecurity *secp=0);
00145                ~XrdNet();
00146 
00147 protected:
00148 
00149 XrdSysError       *eDest;
00150 XrdNetSecurity    *Police;
00151 char              *Domain;
00152 int                Domlen;
00153 int                iofd;
00154 int                Portnum;
00155 int                PortType;
00156 int                Windowsz;
00157 int                netOpts;
00158 int                BuffSize;
00159 XrdNetBufferQ     *BuffQ;
00160 
00161 private:
00162 
00163 int                do_Accept_TCP(XrdNetPeer &myPeer, int opts);
00164 int                do_Accept_UDP(XrdNetPeer &myPeer, int opts);
00165 };
00166 #endif

Generated on 27 Jul 2013 for xrootd by  doxygen 1.4.7