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