Logo ROOT  
Reference Guide
XrdProofConn.h
Go to the documentation of this file.
1// @(#)root/proofd:$Id$
2// Author: G. Ganis June 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#ifndef ROOT_XrdProofConn
13#define ROOT_XrdProofConn
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// XrdProofConn //
18// //
19// Authors: G. Ganis, CERN, 2005 //
20// //
21// Low level handler of connections to xproofd. //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#define DFLT_CONNECTMAXTRY 10
26
27#include "XrdSysToOuc.h"
28#include "XProofProtocol.h"
29#include "XProofProtUtils.h"
32#ifndef __OUC_STRING_H__
33#include "XrdOuc/XrdOucString.hh"
34#endif
35
36#include <list>
37
41class XrdSysRecMutex;
42class XrdSecProtocol;
43class XrdSysPlugin;
44
45// Generic sender
46typedef int (*XrdProofConnSender_t)(const char *, int, void *);
47
49
50friend class TXSocket;
51friend class TXUnixSocket;
52friend class XrdProofPhyConn;
53
54public:
55
57
58private:
59
60 char fMode; // Type of client
62 int fLogConnID; // Logical connection ID of current object
63 kXR_unt16 fStreamid; // Streamid used for normal communications
64 int fRemoteProtocol; // Protocol of remote daemon
65 int fServerProto; // The server protocol
66 ESrvType fServerType; // Server type as returned by DoHandShake()
67 // (see enum ServerType)
68 short fSessionID; // proofsrv: remote ID of connected session
69 XrdOucString fUser; // Username used for login
70 XrdOucString fHost; // Remote host
71 int fPort; // Remote port
72 XrdOucString fLastErrMsg; // Msg describing last error
73 XErrorCode fLastErr; // Last error code
74 char fCapVer; // a version number (e.g. a protocol num)
75
76 XrdOucString fLoginBuffer; // Buffer to be sent over at login
77
78 XrdSysRecMutex *fMutex; // Lock SendRecv actions
79
80 XrdSysRecMutex *fConnectInterruptMtx; // Protect access to fConnectInterrupt
82
83 XrdClientPhyConnection *fPhyConn; // underlying physical connection
84
85 int fOpenSockFD; // Underlying socket descriptor
86
87 XrdClientAbsUnsolMsgHandler *fUnsolMsgHandler; // Handler of unsolicited responses
88
89 XrdProofConnSender_t fSender; // Generic message forwarder
90 void *fSenderArg; // Optional rgument for the message forwarder
91
92 XrdClientUrlInfo fUrl; // Connection URL info object with
93
94 static XrdClientConnectionMgr *fgConnMgr; //Connection Manager
95
96 static int fgMaxTry; //max number of connection attempts
97 static int fgTimeWait; //Wait time between an attempt and the other
98
99 static XrdSysPlugin *fgSecPlugin; // Sec library plugin
100 static void *fgSecGetProtocol; // Sec protocol getter
101
102 XrdSecProtocol *Authenticate(char *plist, int lsiz);
103 bool CheckErrorStatus(XrdClientMessage *, int &, const char *, bool);
104 bool CheckResp(struct ServerResponseHeader *resp,
105 const char *met, bool);
106 virtual void Connect(int = -1);
107 void ReConnect();
108 virtual int TryConnect(int = -1);
109
111 virtual bool GetAccessToSrv(XrdClientPhyConnection *p = 0);
112 virtual bool Init(const char *url = 0, int = -1);
113 bool Login();
114 bool MatchStreamID(struct ServerResponseHeader *resp);
116 const void *reqData, char **answData);
117
118 void SetInterrupt();
119
120 void SetConnectInterrupt();
121 bool ConnectInterrupt();
122
123public:
124 XrdProofConn(const char *url, char mode = 'M', int psid = -1, char ver = -1,
125 XrdClientAbsUnsolMsgHandler * uh = 0, const char *logbuf = 0);
126 virtual ~XrdProofConn();
127
128 virtual void Close(const char *opt = "");
129
130 int GetLogConnID() const { return fLogConnID; }
131 int GetLowSocket();
132 int GetOpenError() const { return (int)fLastErr; }
133 int GetServType() const { return (int)fServerType; }
134 short GetSessionID() const { return fSessionID; }
135 const char *GetUrl() { return (const char *) fUrl.GetUrl().c_str(); }
136 const char *GetLastErr() { return fLastErrMsg.c_str(); }
137
138 bool IsValid() const;
139
140 XReqErrorType LowWrite(XPClientRequest *, const void *, int);
141
142 // Send, Recv interfaces
143 virtual int ReadRaw(void *buf, int len, XrdClientPhyConnection *p = 0);
144 virtual XrdClientMessage *ReadMsg();
145 XrdClientMessage *SendReq(XPClientRequest *req, const void *reqData,
146 char **answData, const char *CmdName,
147 bool notifyerr = 1);
148 virtual void SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t = 0, void * = 0);
149 void SetSID(kXR_char *sid);
150 virtual int WriteRaw(const void *buf, int len, XrdClientPhyConnection *p = 0);
151
152 static void GetRetryParam(int &maxtry, int &timewait);
153 static void SetRetryParam(int maxtry = 5, int timewait = 2);
154
157};
158
159#endif
#define XrdSysPlugin
Definition: XpdSysPlugin.h:8
UnsolRespProcResult
int(* XrdProofConnSender_t)(const char *, int, void *)
Definition: XrdProofConn.h:46
#define XrdSysRecMutex
Definition: XrdSysToOuc.h:18
High level handler of connections to XProofD.
Definition: TXSocket.h:59
Implementation of TXSocket using PF_UNIX sockets.
Definition: TXUnixSocket.h:29
XrdOucString GetUrl()
ESrvType DoHandShake(XrdClientPhyConnection *p=0)
Performs initial hand-shake with the server in order to understand which kind of server is there at t...
virtual int TryConnect(int=-1)
Connect to remote server.
static void GetRetryParam(int &maxtry, int &timewait)
Retrieve current values of the retry control parameters, numer of retries and wait time between attem...
static int fgTimeWait
Definition: XrdProofConn.h:97
XrdClientPhyConnection * fPhyConn
Definition: XrdProofConn.h:83
XrdClientMessage * SendReq(XPClientRequest *req, const void *reqData, char **answData, const char *CmdName, bool notifyerr=1)
SendReq tries to send a single command for a number of times.
ESrvType fServerType
Definition: XrdProofConn.h:66
static void * fgSecGetProtocol
Definition: XrdProofConn.h:100
virtual bool Init(const char *url=0, int=-1)
Initialization.
int fRemoteProtocol
Definition: XrdProofConn.h:64
static int fgMaxTry
Definition: XrdProofConn.h:96
XrdSecProtocol * Authenticate(char *plist, int lsiz)
Negotiate authentication with the remote server.
bool ConnectInterrupt()
Check if interrupted during connect.
bool CheckErrorStatus(XrdClientMessage *, int &, const char *, bool)
Check error status.
virtual void SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t=0, void *=0)
Set handler of unsolicited responses.
XrdProofConnSender_t fSender
Definition: XrdProofConn.h:89
virtual bool GetAccessToSrv(XrdClientPhyConnection *p=0)
Gets access to the connected server.
bool MatchStreamID(struct ServerResponseHeader *resp)
Check stream ID matching.
int GetLogConnID() const
Definition: XrdProofConn.h:130
short fSessionID
Definition: XrdProofConn.h:68
XrdClientAbsUnsolMsgHandler * fUnsolMsgHandler
Definition: XrdProofConn.h:87
XErrorCode fLastErr
Definition: XrdProofConn.h:73
virtual UnsolRespProcResult ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *s, XrdClientMessage *m)
We are here if an unsolicited response comes from a logical conn The response comes in the form of an...
XrdSysRecMutex * fMutex
Definition: XrdProofConn.h:78
bool IsValid() const
Test validity of this connection.
virtual int WriteRaw(const void *buf, int len, XrdClientPhyConnection *p=0)
Low level write call.
bool CheckResp(struct ServerResponseHeader *resp, const char *met, bool)
Checks if the server's response is ours.
virtual void Close(const char *opt="")
Close connection.
XrdClientMessage * SendRecv(XPClientRequest *req, const void *reqData, char **answData)
SendRecv sends a command to the server and to get a response.
static XrdClientConnectionMgr * fgConnMgr
Definition: XrdProofConn.h:94
XrdClientUrlInfo fUrl
Definition: XrdProofConn.h:92
kXR_unt16 fStreamid
Definition: XrdProofConn.h:63
virtual ~XrdProofConn()
Destructor.
short GetSessionID() const
Definition: XrdProofConn.h:134
virtual XrdClientMessage * ReadMsg()
Pickup message from the queue.
void SetSID(kXR_char *sid)
Set our stream id, to match against that one in the server's response.
XrdOucString fUser
Definition: XrdProofConn.h:69
XrdOucString fLastErrMsg
Definition: XrdProofConn.h:72
XReqErrorType LowWrite(XPClientRequest *, const void *, int)
Send request to server (NB: req is marshalled at this point, so we need also the plain reqDataLen)
const char * GetLastErr()
Definition: XrdProofConn.h:136
void * fSenderArg
Definition: XrdProofConn.h:90
virtual void Connect(int=-1)
Run the connection attempts: the result is stored in fConnected.
XrdOucString fLoginBuffer
Definition: XrdProofConn.h:76
static XrdSysPlugin * fgSecPlugin
Definition: XrdProofConn.h:99
XrdSysRecMutex * fConnectInterruptMtx
Definition: XrdProofConn.h:80
int GetLowSocket()
Return the socket descriptor of the underlying connection.
XrdProofConn(const char *url, char mode='M', int psid=-1, char ver=-1, XrdClientAbsUnsolMsgHandler *uh=0, const char *logbuf=0)
Constructor.
bool Login()
This method perform the loggin-in into the server just after the hand-shake.
void ReConnect()
Perform a reconnection attempt when a connection is not valid any more.
int GetOpenError() const
Definition: XrdProofConn.h:132
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...
const char * GetUrl()
Definition: XrdProofConn.h:135
virtual int ReadRaw(void *buf, int len, XrdClientPhyConnection *p=0)
Low level receive call.
int GetServType() const
Definition: XrdProofConn.h:133
bool fConnectInterrupt
Definition: XrdProofConn.h:81
XrdOucString fHost
Definition: XrdProofConn.h:70
void SetInterrupt()
Interrupt the underlying socket.
void SetConnectInterrupt()
Interrupt connection attempts.
static constexpr double s
auto * m
Definition: textangle.C:8