25 #include "XrdVersion.hh"
26 #include "XrdClient/XrdClientEnv.hh"
28 #include "XrdClient/XrdClientConst.hh"
31 #include "XrdSec/XrdSecInterface.hh"
35 # include <sys/socket.h>
37 #include <sys/types.h>
47 #define URLTAG "["<<fUrl.Host<<":"<<fUrl.Port<<"]"
54 XrdClientAbsUnsolMsgHandler *uh,
bool tcp,
int fd)
65 if (url && !
Init(url, fd)) {
66 TRACE(XERR,
"severe error occurred while"
67 " opening a connection" <<
" to server "<<
URLTAG);
77 XPDLOC(ALL,
"PhyConn::Init")
80 fUrl.TakeUrl(XrdOucString(url));
84 if (
fUser.length() <= 0) {
87 struct passwd *pw = getpwuid(getuid());
91 DWORD
length =
sizeof (lname);
92 ::GetUserName(lname, &length);
99 char *hn = XrdSysDNS::getHostName(((
fUrl.Host.length() > 0) ?
100 fUrl.Host.c_str() :
"localhost"));
112 struct servent *sent = getservbyname(
"proofd",
"tcp");
114 TRACE(XERR,
"service 'proofd' not found by getservbyname" <<
115 ": using default IANA assigned tcp port 1093");
118 fPort = (int)ntohs(sent->s_port);
121 TRACE(XERR,
"getservbyname found tcp port " <<
fPort <<
122 " for service 'proofd'");
139 XPDLOC(ALL,
"PhyConn::Connect")
141 int maxTry = -1, timeWait = -1;
144 maxTry = (maxTry > -1) ? maxTry : EnvGetLong(NAME_FIRSTCONNECTMAXCNT);
145 timeWait = (timeWait > -1) ? timeWait : EnvGetLong(NAME_CONNECTTIMEOUT);
159 TRACE(DBG,
"new logical connection ID: "<<logid);
163 if (
fLastErr == kXR_NotAuthorized) {
167 msg.erase(msg.rfind(
":"));
168 TRACE(XERR,
"authentication failure: " << msg);
177 TRACE(DBG,
"access to server granted.");
183 TRACE(DBG,
"disconnecting");
187 TRACE(DBG,
"connection attempt failed: sleep " << timeWait <<
" secs");
191 Sleep(timeWait * 1000);
202 XPDLOC(ALL,
"PhyConn::TryConnect")
204 const char *ctype[2] = {
"UNIX",
"TCP"};
210 bool isUnix = (
fTcp) ? 0 : 1;
211 #if ROOTXRDVERS <= ROOT_PhyConnNoReuse
213 TRACE(XERR,
"Reusing an existing connection (descriptor "<<fd<<
214 ") not supported by the xroot client version (requires xrootd >= 3.0.3)");
269 fPhyConn->UnsolicitedMsgHandler = uh;
286 XPDLOC(ALL,
"PhyConn::GetAccessToSrv")
304 TRACE(XERR,
"handshake failed with server "<<
URLTAG);
311 TRACE(XERR,
"server at "<<
URLTAG<<
" is unknown : protocol error");
318 TRACE(XERR,
"client already logged-in at "<<
URLTAG<<
" (!): protocol error!");
int WriteRaw(const void *buf, int len, XrdClientPhyConnection *=0)
Low level write call.
void Close(const char *opt="")
Close the connection.
#define TRACE(Flag, Args)
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 SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t=0, void *=0)
Set handler of unsolicited responses.
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
bool Init(const char *url, int fd=-1)
Initialization.
bool GetAccessToSrv(XrdClientPhyConnection *=0)
Gets access to the connected server.
int(* XrdProofConnSender_t)(const char *, int, void *)
bool Login()
This method perform the loggin-in into the server just after the hand-shake.
int ReadRaw(void *buffer, int BufferLength, int substreamid=-1, int *usedsubstreamid=0)
bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix=0)
ERemoteServerType fServerType
Double_t length(const TVector2 &v)
XrdClientMessage * ReadMsg()
Pickup message from the queue.
static void GetRetryParam(int &maxtry, int &timewait)
Retrieve current values of the retry control parameters, numer of retries and wait time between attem...
void Connect(int fd=-1)
Run the connection attempts: the result is stored in fConnected.
int TryConnect(int fd=-1)
Connect to remote server.
XrdClientPhyConnection * fPhyConn
R__EXTERN C unsigned int sleep(unsigned int seconds)
int WriteRaw(const void *buffer, int BufferLength, int substreamid=0)
int ReadRaw(void *buf, int len, XrdClientPhyConnection *=0)
Low level write call.
XrdProofPhyConn(const char *url, int psid=-1, char ver=-1, XrdClientAbsUnsolMsgHandler *uh=0, bool tcp=0, int fd=-1)
Constructor.
XrdClientMessage * ReadMessage(int streamid)
XrdClientAbsUnsolMsgHandler * fUnsolMsgHandler