Logo ROOT  
Reference Guide
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
15Implementation of TXSocket using PF_UNIX sockets.
16Used 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
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;
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}
char Char_t
Definition: RtypesCore.h:31
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:117
#define ClassImp(name)
Definition: Rtypes.h:361
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
TString fUrl
Definition: TSocket.h:71
Int_t fRemoteProtocol
Definition: TSocket.h:64
const char * Data() const
Definition: TString.h:364
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:705
Handler of asynchronous events for XProofD sockets.
Definition: TXHandler.h:28
High level handler of connections to XProofD.
Definition: TXSocket.h:59
TString fUser
Definition: TXSocket.h:72
friend class TXUnixSocket
Definition: TXSocket.h:66
Int_t fPort
Definition: TXSocket.h:74
Int_t fPid
Definition: TXSocket.h:101
XrdProofConn * fConn
Definition: TXSocket.h:82
Int_t fXrdProofdVersion
Definition: TXSocket.h:108
TString fHost
Definition: TXSocket.h:73
Implementation of TXSocket using PF_UNIX sockets.
Definition: TXUnixSocket.h:29
Int_t Reconnect()
Try reconnection after failure.
XrdOucString GetUrl()
static void GetRetryParam(int &maxtry, int &timewait)
Retrieve current values of the retry control parameters, numer of retries and wait time between attem...
int fRemoteProtocol
Definition: XrdProofConn.h:64
XrdSysRecMutex * fMutex
Definition: XrdProofConn.h:78
bool IsValid() const
Test validity of this connection.
virtual void Close(const char *opt="")
Close connection.
XrdClientUrlInfo fUrl
Definition: XrdProofConn.h:92
XrdOucString fUser
Definition: XrdProofConn.h:69
virtual void Connect(int=-1)
Run the connection attempts: the result is stored in fConnected.
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...
XrdOucString fHost
Definition: XrdProofConn.h:70
auto * l
Definition: textangle.C:4