Logo ROOT   6.10/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 #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 
39 class XrdClientMessage;
41 class XrdSysRecMutex;
42 class XrdSecProtocol;
43 class XrdSysPlugin;
44 
45 // Generic sender
46 typedef int (*XrdProofConnSender_t)(const char *, int, void *);
47 
49 
50 friend class TXSocket;
51 friend class TXUnixSocket;
52 friend class XrdProofPhyConn;
53 
54 public:
55 
57 
58 private:
59 
60  char fMode; // Type of client
61  bool fConnected;
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 
123 public:
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
virtual bool GetAccessToSrv(XrdClientPhyConnection *p=0)
Gets access to the connected server.
virtual ~XrdProofConn()
Destructor.
kXR_unt16 fStreamid
Definition: XrdProofConn.h:63
int GetServType() const
Definition: XrdProofConn.h:133
virtual XrdClientMessage * ReadMsg()
Pickup message from the queue.
int GetLogConnID() const
Definition: XrdProofConn.h:130
virtual void Connect(int=-1)
Run the connection attempts: the result is stored in fConnected.
static int fgTimeWait
Definition: XrdProofConn.h:97
#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:76
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:73
ESrvType DoHandShake(XrdClientPhyConnection *p=0)
Performs initial hand-shake with the server in order to understand which kind of server is there at t...
int GetOpenError() const
Definition: XrdProofConn.h:132
void SetInterrupt()
Interrupt the underlying socket.
Implementation of TXSocket using PF_UNIX sockets.
Definition: TXUnixSocket.h:29
short fSessionID
Definition: XrdProofConn.h:68
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.
static XrdClientConnectionMgr * fgConnMgr
Definition: XrdProofConn.h:94
const char * GetLastErr()
Definition: XrdProofConn.h:136
XrdSysRecMutex * fMutex
Definition: XrdProofConn.h:78
int(* XrdProofConnSender_t)(const char *, int, void *)
Definition: XrdProofConn.h:46
int fRemoteProtocol
Definition: XrdProofConn.h:64
bool Login()
This method perform the loggin-in into the server just after the hand-shake.
XrdProofConnSender_t fSender
Definition: XrdProofConn.h:89
virtual int TryConnect(int=-1)
Connect to remote server.
XrdSecProtocol * Authenticate(char *plist, int lsiz)
Negotiate authentication with the remote server.
XrdSysRecMutex * fConnectInterruptMtx
Definition: XrdProofConn.h:80
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:99
static int fgMaxTry
Definition: XrdProofConn.h:96
High level handler of connections to XProofD.
Definition: TXSocket.h:59
#define XrdSysPlugin
Definition: XpdSysPlugin.h:8
TMarker * m
Definition: textangle.C:8
bool fConnectInterrupt
Definition: XrdProofConn.h:81
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:69
XrdClientUrlInfo fUrl
Definition: XrdProofConn.h:92
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.
XrdProofConn(const char *url, char mode='M', int psid=-1, char ver=-1, XrdClientAbsUnsolMsgHandler *uh=0, const char *logbuf=0)
Constructor.
XrdOucString fHost
Definition: XrdProofConn.h:70
const char * GetUrl()
Definition: XrdProofConn.h:135
virtual void Close(const char *opt="")
Close connection.
XrdClientPhyConnection * fPhyConn
Definition: XrdProofConn.h:83
XrdOucString fLastErrMsg
Definition: XrdProofConn.h:72
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:90
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:134
bool IsValid() const
Test validity of this connection.
ESrvType fServerType
Definition: XrdProofConn.h:66
static void * fgSecGetProtocol
Definition: XrdProofConn.h:100
virtual int ReadRaw(void *buf, int len, XrdClientPhyConnection *p=0)
Low level receive call.
XrdClientAbsUnsolMsgHandler * fUnsolMsgHandler
Definition: XrdProofConn.h:87
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...