Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
27 ClassImp(TXUnixSocket);
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 
65 Int_t TXUnixSocket::Reconnect()
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
85  XrdSysMutexHelper l(fConn->fMutex);
86 
87  fConn->Close();
88  int maxtry, timewait;
89  XrdProofConn::GetRetryParam(maxtry, timewait);
90  XrdProofConn::SetRetryParam(300, 1);
91  fConn->Connect();
92  XrdProofConn::SetRetryParam();
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 }