// @(#)root/proofd:$Id$ // Author: Gerardo Ganis 12/12/2005 /************************************************************************* * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ ////////////////////////////////////////////////////////////////////////// // // // XrdProofPhyConn // // // // Authors: G. Ganis, CERN, 2005 // // // // XrdProofConn implementation using a simple physical connection // // (Unix or Tcp) // ////////////////////////////////////////////////////////////////////////// #include "XrdProofPhyConn.h" #include "XpdSysDNS.h" #include "XrdVersion.hh" #include "XrdClient/XrdClientEnv.hh" #include "XrdClient/XrdClientConnMgr.hh" #include "XrdClient/XrdClientConst.hh" #include "XrdClient/XrdClientLogConnection.hh" #include "XrdClient/XrdClientMessage.hh" #include "XrdSec/XrdSecInterface.hh" #ifndef WIN32 #include #include #include #else #include #endif // Tracing utils #include "XrdProofdTrace.h" #define URLTAG "["<pw_name : ""; #else char lname[256]; DWORD length = sizeof (lname); ::GetUserName(lname, &length); fUser = lname; #endif } // Host and Port if (!fTcp) { fHost = XrdSysDNS::getHostName(((fUrl.Host.length() > 0) ? fUrl.Host.c_str() : "localhost")); fPort = -1; fUrl.Host = ""; fUrl.User = ""; } else { fHost = fUrl.Host.c_str(); fPort = fUrl.Port; // Check port if (fPort <= 0) { struct servent *sent = getservbyname("proofd", "tcp"); if (!sent) { TRACE(XERR, "service 'proofd' not found by getservbyname" << ": using default IANA assigned tcp port 1093"); fPort = 1093; } else { fPort = (int)ntohs(sent->s_port); // Update port in url fUrl.Port = fPort; TRACE(XERR, "getservbyname found tcp port " << fPort << " for service 'proofd'"); } } } // Run the connection attempts: the result is stored in fConnected Connect(fd); // We are done return fConnected; } //_____________________________________________________________________________ void XrdProofPhyConn::Connect(int fd) { // Run the connection attempts: the result is stored in fConnected XPDLOC(ALL, "PhyConn::Connect") int maxTry = -1, timeWait = -1; // Max number of tries and timeout; use current settings, if any XrdProofConn::GetRetryParam(maxTry, timeWait); maxTry = (maxTry > -1) ? maxTry : EnvGetLong(NAME_FIRSTCONNECTMAXCNT); timeWait = (timeWait > -1) ? timeWait : EnvGetLong(NAME_CONNECTTIMEOUT); int logid = -1; int i = 0; for (; (i < maxTry) && (!fConnected); i++) { // Try connection logid = TryConnect(fd); // We are connected to a host. Let's handshake with it. if (fConnected) { // Now the have the logical Connection ID, that we can use as streamid for // communications with the server TRACE(DBG, "new logical connection ID: "< 0) { TRACE(XERR, "Reusing an existing connection (descriptor "<= 3.0.3)"); fLogConnID = -1; fConnected = 0; return -1; } if (!(fPhyConn->Connect(fUrl, isUnix))) { #else if (!(fPhyConn->Connect(fUrl, isUnix, fd))) { #endif TRACE(XERR, "creating "<Disconnect(); // Flag this action fConnected = 0; // We are done return; } //_____________________________________________________________________________ void XrdProofPhyConn::SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t, void *) { // Set handler of unsolicited responses if (fPhyConn) fPhyConn->UnsolicitedMsgHandler = uh; } //_____________________________________________________________________________ XrdClientMessage *XrdProofPhyConn::ReadMsg() { // Pickup message from the queue return (fPhyConn ? fPhyConn->ReadMessage(fStreamid) : (XrdClientMessage *)0); } //_____________________________________________________________________________ bool XrdProofPhyConn::GetAccessToSrv(XrdClientPhyConnection *) { // Gets access to the connected server. // The login and authorization steps are performed here. XPDLOC(ALL, "PhyConn::GetAccessToSrv") // Now we are connected and we ask for the kind of the server { XrdClientPhyConnLocker pcl(fPhyConn); fServerType = DoHandShake(); } switch (fServerType) { case kSTXProofd: TRACE(DBG, "found server at "<StartReader(); fPhyConn->fServerType = kSTBaseXrootd; break; case kSTError: TRACE(XERR, "handshake failed with server "<IsLogged() != kNo) { TRACE(XERR, "client already logged-in at "<WriteRaw(buf, len); // No connection open return -1; } //_____________________________________________________________________________ int XrdProofPhyConn::ReadRaw(void *buf, int len, XrdClientPhyConnection *) { // Low level write call if (fPhyConn) return fPhyConn->ReadRaw(buf, len); // No connection open return -1; }