XrdInet.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                            X r d I n e t . c c                             */
00004 /*                                                                            */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010  
00011 //         $Id: XrdInet.cc 25932 2008-10-23 10:58:11Z ganis $ 
00012 
00013 const char *XrdInetCVSID = "$Id: XrdInet.cc 25932 2008-10-23 10:58:11Z ganis $";
00014 
00015 #include <ctype.h>
00016 #include <errno.h>
00017 #include <netdb.h>
00018 #include <stdio.h>
00019 #include <unistd.h>
00020 #include <sys/types.h>
00021 #include <sys/socket.h>
00022 
00023 #include "XrdSys/XrdSysError.hh"
00024 
00025 #include "Xrd/XrdInet.hh"
00026 #include "Xrd/XrdLink.hh"
00027 #include "Xrd/XrdTrace.hh"
00028 
00029 #include "XrdNet/XrdNetOpts.hh"
00030 #include "XrdNet/XrdNetPeer.hh"
00031   
00032 /******************************************************************************/
00033 /*                               G l o b a l s                                */
00034 /******************************************************************************/
00035   
00036 extern XrdOucTrace  XrdTrace;
00037 
00038        const char *XrdInet::TraceID = "Inet";
00039 
00040 /******************************************************************************/
00041 /*                                A c c e p t                                 */
00042 /******************************************************************************/
00043 
00044 XrdLink *XrdInet::Accept(int opts, int timeout)
00045 {
00046    XrdNetPeer myPeer;
00047    XrdLink   *lp;
00048    int ismyfd, lnkopts = (opts & XRDNET_MULTREAD ? XRDLINK_RDLOCK : 0);
00049 
00050 // Perform regular accept
00051 //
00052    if (!XrdNet::Accept(myPeer, opts | (netOpts & XRDNET_NORLKUP), timeout)) 
00053       return (XrdLink *)0;
00054    if ((ismyfd = (myPeer.fd == iofd))) lnkopts |= XRDLINK_NOCLOSE;
00055 
00056 // Allocate a new network object
00057 //
00058    if (!(lp = XrdLink::Alloc(myPeer, lnkopts)))
00059       {eDest->Emsg("Accept",ENOMEM,"allocate new link for",myPeer.InetName);
00060        if (!ismyfd) close(myPeer.fd);
00061       } else {
00062        myPeer.InetBuff = 0; // Keep buffer after object goes away
00063        TRACE(NET, "Accepted connection from " <<myPeer.fd <<'@' <<myPeer.InetName);
00064       }
00065 
00066 // All done
00067 //
00068    return lp;
00069 }
00070 
00071 /******************************************************************************/
00072 /*                               C o n n e c t                                */
00073 /******************************************************************************/
00074 
00075 XrdLink *XrdInet::Connect(const char *host, int port, int opts, int tmo)
00076 {
00077    XrdNetPeer myPeer;
00078    XrdLink   *lp;
00079    int ismyfd, lnkopts = (opts & XRDNET_MULTREAD ? XRDLINK_RDLOCK : 0);
00080 
00081 // Try to do a connect
00082 //
00083    if (!XrdNet::Connect(myPeer, host, port, opts, tmo)) return (XrdLink *)0;
00084    if ((ismyfd = (myPeer.fd == iofd))) lnkopts |= XRDLINK_NOCLOSE;
00085 
00086 // Return a link object
00087 //
00088    if (!(lp = XrdLink::Alloc(myPeer, lnkopts)))
00089       {eDest->Emsg("Connect",ENOMEM,"allocate new link to",myPeer.InetName);
00090        if (!ismyfd) close(myPeer.fd);
00091       } else {
00092        myPeer.InetBuff = 0; // Keep buffer after object goes away
00093        TRACE(NET, "Connected to " <<myPeer.InetName <<':' <<port);
00094       }
00095 
00096 // All done, return whatever object we have
00097 //
00098    return lp;
00099 }

Generated on Tue Jul 5 14:46:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1