ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TXUnixSocket.cxx
Go to the documentation of this file.
1 // @(#)root/proofx:$Id$
2 // Author: Gerardo Ganis 12/12/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TXUnixSocket
13 \ingroup proofx
14 
15 Implementation of TXSocket using PF_UNIX sockets.
16 Used for the internal connection between coordinator and TXProofServ.
17 
18 */
19 
20 #include "XpdSysPthread.h"
21 
22 #include "TXUnixSocket.h"
23 #include "TEnv.h"
24 #include "TSystem.h"
25 #include "XrdProofPhyConn.h"
26 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Constructor
31 
32 TXUnixSocket::TXUnixSocket(const char *url,
33  Int_t psid, Char_t capver, TXHandler *handler, int fd)
34  : TXSocket(0,'i',psid,capver,0,-1,handler)
35 {
36  // Initialization
37  if (url) {
38 
39  // Create connection
40  fConn = new XrdProofPhyConn(url, psid, capver, this, 0, fd);
41  if (!(fConn->IsValid())) {
42  Error("TXUnixSocket", "severe error occurred while opening a connection"
43  " to server [%s]", fUrl.Data());
44  return;
45  }
46 
47  // Fill some info
48  fUser = fConn->fUser.c_str();
49  fHost = fConn->fHost.c_str();
50  fPort = fConn->fPort;
51  fXrdProofdVersion = fConn->fRemoteProtocol;
52  fRemoteProtocol = fConn->fRemoteProtocol;
53 
54  // Save also updated url
55  TSocket::fUrl = fConn->fUrl.GetUrl().c_str();
56 
57  // This is needed for the reader thread to signal an interrupt
58  fPid = gSystem->GetPid();
59  }
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Try reconnection after failure
64 
66 {
67  if (gDebug > 0) {
68  Info("Reconnect", "%p: %p: %d: trying to reconnect on %s", this,
69  fConn, (fConn ? fConn->IsValid() : 0), fUrl.Data());
70  }
71 
72  Int_t tryreconnect = gEnv->GetValue("TXSocket.Reconnect", 0);
73  if (tryreconnect == 0 || fXrdProofdVersion < 1005) {
74  if (tryreconnect == 0)
75  Info("Reconnect","%p: reconnection attempts explicitly disabled!", this);
76  else
77  Info("Reconnect","%p: server does not support reconnections (protocol: %d < 1005)",
78  this, fXrdProofdVersion);
79  return -1;
80  }
81 
82  if (fConn && !fConn->IsValid()) {
83 
84  // Block any other attempt to use this connection
86 
87  fConn->Close();
88  int maxtry, timewait;
89  XrdProofConn::GetRetryParam(maxtry, timewait);
91  fConn->Connect();
93  }
94 
95  if (gDebug > 0) {
96  Info("Reconnect", "%p: %p: attempt %s", this, fConn,
97  ((fConn && fConn->IsValid()) ? "succeeded!" : "failed"));
98  }
99 
100  // Done
101  return ((fConn && fConn->IsValid()) ? 0 : -1);
102 }
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:711
virtual void Connect(int=-1)
Run the connection attempts: the result is stored in fConnected.
XrdProofConn * fConn
Definition: TXSocket.h:95
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
static void SetRetryParam(int maxtry=5, int timewait=2)
Change values of the retry control parameters, numer of retries and wait time between attempts (in se...
int Int_t
Definition: RtypesCore.h:41
Implementation of TXSocket using PF_UNIX sockets.
Definition: TXUnixSocket.h:31
const char * Data() const
Definition: TString.h:349
TString fUrl
Definition: TSocket.h:102
XrdSysRecMutex * fMutex
Definition: XrdProofConn.h:88
void Error(const char *location, const char *msgfmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
Handler of asynchronous events for XProofD sockets.
Definition: TXHandler.h:30
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
Int_t fXrdProofdVersion
Definition: TXSocket.h:121
High level handler of connections to XProofD.
Definition: TXSocket.h:72
TLine * l
Definition: textangle.C:4
static void GetRetryParam(int &maxtry, int &timewait)
Retrieve current values of the retry control parameters, numer of retries and wait time between attem...
bool IsValid() const
Test validity of this connection.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
virtual void Close(const char *opt="")
Close connection.
char Char_t
Definition: RtypesCore.h:29
Int_t Reconnect()
Try reconnection after failure.
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ClassImp(TXUnixSocket) TXUnixSocket
Constructor.