forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TXUnixSocket.cxx
102 lines (81 loc) · 3.18 KB
/
TXUnixSocket.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @(#)root/proofx:$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. *
*************************************************************************/
/** \class TXUnixSocket
\ingroup proofx
Implementation of TXSocket using PF_UNIX sockets.
Used for the internal connection between coordinator and TXProofServ.
*/
#include "XpdSysPthread.h"
#include "TXUnixSocket.h"
#include "TEnv.h"
#include "TSystem.h"
#include "XrdProofPhyConn.h"
ClassImp(TXUnixSocket)
////////////////////////////////////////////////////////////////////////////////
/// Constructor
TXUnixSocket::TXUnixSocket(const char *url,
Int_t psid, Char_t capver, TXHandler *handler, int fd)
: TXSocket(0,'i',psid,capver,0,-1,handler)
{
// Initialization
if (url) {
// Create connection
fConn = new XrdProofPhyConn(url, psid, capver, this, 0, fd);
if (!(fConn->IsValid())) {
Error("TXUnixSocket", "severe error occurred while opening a connection"
" to server [%s]", fUrl.Data());
return;
}
// Fill some info
fUser = fConn->fUser.c_str();
fHost = fConn->fHost.c_str();
fPort = fConn->fPort;
fXrdProofdVersion = fConn->fRemoteProtocol;
fRemoteProtocol = fConn->fRemoteProtocol;
// Save also updated url
TSocket::fUrl = fConn->fUrl.GetUrl().c_str();
// This is needed for the reader thread to signal an interrupt
fPid = gSystem->GetPid();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Try reconnection after failure
Int_t TXUnixSocket::Reconnect()
{
if (gDebug > 0) {
Info("Reconnect", "%p: %p: %d: trying to reconnect on %s", this,
fConn, (fConn ? fConn->IsValid() : 0), fUrl.Data());
}
Int_t tryreconnect = gEnv->GetValue("TXSocket.Reconnect", 0);
if (tryreconnect == 0 || fXrdProofdVersion < 1005) {
if (tryreconnect == 0)
Info("Reconnect","%p: reconnection attempts explicitly disabled!", this);
else
Info("Reconnect","%p: server does not support reconnections (protocol: %d < 1005)",
this, fXrdProofdVersion);
return -1;
}
if (fConn && !fConn->IsValid()) {
// Block any other attempt to use this connection
XrdSysMutexHelper l(fConn->fMutex);
fConn->Close();
int maxtry, timewait;
XrdProofConn::GetRetryParam(maxtry, timewait);
XrdProofConn::SetRetryParam(300, 1);
fConn->Connect();
XrdProofConn::SetRetryParam();
}
if (gDebug > 0) {
Info("Reconnect", "%p: %p: attempt %s", this, fConn,
((fConn && fConn->IsValid()) ? "succeeded!" : "failed"));
}
// Done
return ((fConn && fConn->IsValid()) ? 0 : -1);
}