Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSocket.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Fons Rademakers 18/12/96
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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//////////////////////////////////////////////////////////////////////////
13// //
14// TSocket //
15// //
16// This class implements client sockets. A socket is an endpoint for //
17// communication between two machines. //
18// The actual work is done via the TSystem class (either TUnixSystem //
19// or TWinNTSystem). //
20// //
21//////////////////////////////////////////////////////////////////////////
22
23#include "Bytes.h"
24#include "Compression.h"
25#include "NetErrors.h"
26#include "TError.h"
27#include "TMessage.h"
28#include "TObjString.h"
29#include "TPSocket.h"
30#include "TPluginManager.h"
31#include "TROOT.h"
32#include "TString.h"
33#include "TSystem.h"
34#include "TUrl.h"
35#include "TVirtualAuth.h"
36#include "TStreamerInfo.h"
37#include "TProcessID.h"
38
39
42
43//
44// Client "protocol changes"
45//
46// This was in TNetFile and TAuthenticate before, but after the introduction
47// of TSocket::CreateAuthSocket the common place for all the clients is TSocket,
48// so this seems to be the right place for a version number
49//
50// 7: added support for ReOpen(), kROOTD_BYE and kROOTD_PROTOCOL2
51// 8: added support for update being a create (open stat = 2 and not 1)
52// 9: added new authentication features (see README.AUTH)
53// 10: added support for authenticated socket via TSocket::CreateAuthSocket(...)
54// 11: modified SSH protocol + support for server 'no authentication' mode
55// 12: add random tags to avoid reply attacks (password+token)
56// 13: authentication re-organization; cleanup in PROOF
57// 14: support for SSH authentication via SSH tunnel
58// 15: cope with fixes in TUrl::GetFile
59// 16: add env setup message exchange
60//
61Int_t TSocket::fgClientProtocol = 17; // increase when client protocol changes
62
64
66
67////////////////////////////////////////////////////////////////////////////////
68/// Create a socket. Connect to the named service at address addr.
69/// Use tcpwindowsize to specify the size of the receive buffer, it has
70/// to be specified here to make sure the window scale option is set (for
71/// tcpwindowsize > 65KB and for platforms supporting window scaling).
72/// Returns when connection has been accepted by remote side. Use IsValid()
73/// to check the validity of the socket. Every socket is added to the TROOT
74/// sockets list which will make sure that any open sockets are properly
75/// closed on program termination.
76
77TSocket::TSocket(TInetAddress addr, const char *service, Int_t tcpwindowsize)
78 : TNamed(addr.GetHostName(), service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
79{
82
83 fService = service;
84 fSecContext = 0;
87 if (fService.Contains("root"))
89 if (fService.Contains("proof"))
91 fAddress = addr;
93 fBytesSent = 0;
94 fBytesRecv = 0;
95 fTcpWindowSize = tcpwindowsize;
96 fUUIDs = 0;
97 fLastUsageMtx = 0;
99
100 if (fAddress.GetPort() != -1) {
102 tcpwindowsize);
103
104 if (fSocket != kInvalid) {
105 gROOT->GetListOfSockets()->Add(this);
106 }
107 } else
109
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Create a socket. Connect to the specified port # at address addr.
114/// Use tcpwindowsize to specify the size of the receive buffer, it has
115/// to be specified here to make sure the window scale option is set (for
116/// tcpwindowsize > 65KB and for platforms supporting window scaling).
117/// Returns when connection has been accepted by remote side. Use IsValid()
118/// to check the validity of the socket. Every socket is added to the TROOT
119/// sockets list which will make sure that any open sockets are properly
120/// closed on program termination.
121
122TSocket::TSocket(TInetAddress addr, Int_t port, Int_t tcpwindowsize)
123 : TNamed(addr.GetHostName(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
124{
127
129 fSecContext = 0;
130 fRemoteProtocol= -1;
132 if (fService.Contains("root"))
134 if (fService.Contains("proof"))
136 fAddress = addr;
137 fAddress.fPort = port;
139 fBytesSent = 0;
140 fBytesRecv = 0;
141 fTcpWindowSize = tcpwindowsize;
142 fUUIDs = 0;
143 fLastUsageMtx = 0;
145
147 tcpwindowsize);
148 if (fSocket == kInvalid)
149 fAddress.fPort = -1;
150 else {
151 gROOT->GetListOfSockets()->Add(this);
152 }
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Create a socket. Connect to named service on the remote host.
157/// Use tcpwindowsize to specify the size of the receive buffer, it has
158/// to be specified here to make sure the window scale option is set (for
159/// tcpwindowsize > 65KB and for platforms supporting window scaling).
160/// Returns when connection has been accepted by remote side. Use IsValid()
161/// to check the validity of the socket. Every socket is added to the TROOT
162/// sockets list which will make sure that any open sockets are properly
163/// closed on program termination.
164
165TSocket::TSocket(const char *host, const char *service, Int_t tcpwindowsize)
166 : TNamed(host, service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
167{
170
171 fService = service;
172 fSecContext = 0;
173 fRemoteProtocol= -1;
175 if (fService.Contains("root"))
177 if (fService.Contains("proof"))
182 fBytesSent = 0;
183 fBytesRecv = 0;
184 fTcpWindowSize = tcpwindowsize;
185 fUUIDs = 0;
186 fLastUsageMtx = 0;
188
189 if (fAddress.GetPort() != -1) {
190 fSocket = gSystem->OpenConnection(host, fAddress.GetPort(), tcpwindowsize);
191 if (fSocket != kInvalid) {
192 gROOT->GetListOfSockets()->Add(this);
193 }
194 } else
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Create a socket; see CreateAuthSocket for the form of url.
200/// Connect to the specified port # on the remote host.
201/// If user is specified in url, try authentication as user.
202/// Use tcpwindowsize to specify the size of the receive buffer, it has
203/// to be specified here to make sure the window scale option is set (for
204/// tcpwindowsize > 65KB and for platforms supporting window scaling).
205/// Returns when connection has been accepted by remote side. Use IsValid()
206/// to check the validity of the socket. Every socket is added to the TROOT
207/// sockets list which will make sure that any open sockets are properly
208/// closed on program termination.
209
210TSocket::TSocket(const char *url, Int_t port, Int_t tcpwindowsize)
211 : TNamed(TUrl(url).GetHost(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
212{
215
216 fUrl = TString(url);
217 TString host(TUrl(fUrl).GetHost());
218
220 fSecContext = 0;
221 fRemoteProtocol= -1;
223 if (fUrl.Contains("root"))
225 if (fUrl.Contains("proof"))
228 fAddress.fPort = port;
231 fBytesSent = 0;
232 fBytesRecv = 0;
233 fTcpWindowSize = tcpwindowsize;
234 fUUIDs = 0;
235 fLastUsageMtx = 0;
237
238 fSocket = gSystem->OpenConnection(host, fAddress.GetPort(), tcpwindowsize);
239 if (fSocket == kInvalid) {
241 } else {
242 gROOT->GetListOfSockets()->Add(this);
243 }
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Create a socket in the Unix domain on 'sockpath'.
248/// Returns when connection has been accepted by the server. Use IsValid()
249/// to check the validity of the socket. Every socket is added to the TROOT
250/// sockets list which will make sure that any open sockets are properly
251/// closed on program termination.
252
253TSocket::TSocket(const char *sockpath) : TNamed(sockpath, ""),
254 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
255{
258
259 fUrl = sockpath;
260
261 fService = "unix";
262 fSecContext = 0;
263 fRemoteProtocol= -1;
265 fAddress.fPort = -1;
266 fName.Form("unix:%s", sockpath);
268 fBytesSent = 0;
269 fBytesRecv = 0;
270 fTcpWindowSize = -1;
271 fUUIDs = 0;
272 fLastUsageMtx = 0;
274
275 fSocket = gSystem->OpenConnection(sockpath, -1, -1);
276 if (fSocket > 0) {
277 gROOT->GetListOfSockets()->Add(this);
278 }
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Create a socket. The socket will adopt previously opened TCP socket with
283/// descriptor desc.
284
285TSocket::TSocket(Int_t desc) : TNamed("", ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
286{
289
290 fSecContext = 0;
291 fRemoteProtocol = 0;
292 fService = (char *)kSOCKD;
294 fBytesSent = 0;
295 fBytesRecv = 0;
296 fTcpWindowSize = -1;
297 fUUIDs = 0;
298 fLastUsageMtx = 0;
300
301 if (desc >= 0) {
302 fSocket = desc;
304 gROOT->GetListOfSockets()->Add(this);
305 } else
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Create a socket. The socket will adopt previously opened Unix socket with
311/// descriptor desc. The sockpath arg is for info purposes only. Use
312/// this method to adopt e.g. a socket created via socketpair().
313
314TSocket::TSocket(Int_t desc, const char *sockpath) : TNamed(sockpath, ""),
315 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
316{
319
320 fUrl = sockpath;
321
322 fService = "unix";
323 fSecContext = 0;
324 fRemoteProtocol= -1;
326 fAddress.fPort = -1;
327 fName.Form("unix:%s", sockpath);
329 fBytesSent = 0;
330 fBytesRecv = 0;
331 fTcpWindowSize = -1;
332 fUUIDs = 0;
333 fLastUsageMtx = 0;
335
336 if (desc >= 0) {
337 fSocket = desc;
338 gROOT->GetListOfSockets()->Add(this);
339 } else
341}
342
343
344////////////////////////////////////////////////////////////////////////////////
345/// TSocket copy ctor.
346
348{
349 fSocket = s.fSocket;
350 fService = s.fService;
351 fAddress = s.fAddress;
360 fUUIDs = 0;
361 fLastUsageMtx = 0;
363
364 if (fSocket != kInvalid) {
365 gROOT->GetListOfSockets()->Add(this);
366 }
367}
368////////////////////////////////////////////////////////////////////////////////
369/// Close the socket and mark as due to a broken connection.
370
372{
374 if (IsValid()) {
377 }
378
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Close the socket. If option is "force", calls shutdown(id,2) to
385/// shut down the connection. This will close the connection also
386/// for the parent of this process. Also called via the dtor (without
387/// option "force", call explicitly Close("force") if this is desired).
388
390{
391 Bool_t force = option ? (!strcmp(option, "force") ? kTRUE : kFALSE) : kFALSE;
392
393 if (fSocket != kInvalid) {
394 if (IsValid()) { // Filter out kInvalidStillInList case (disconnected but not removed from list)
396 }
397 gROOT->GetListOfSockets()->Remove(this);
398 }
400
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// Return internet address of local host to which the socket is bound.
407/// In case of error TInetAddress::IsValid() returns kFALSE.
408
410{
411 if (IsValid()) {
412 if (fLocalAddress.GetPort() == -1)
414 return fLocalAddress;
415 }
416 return TInetAddress();
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Return the local port # to which the socket is bound.
421/// In case of error return -1.
422
424{
425 if (IsValid()) {
426 if (fLocalAddress.GetPort() == -1)
428 return fLocalAddress.GetPort();
429 }
430 return -1;
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// Waits for this socket to change status. If interest=kRead,
435/// the socket will be watched to see if characters become available for
436/// reading; if interest=kWrite the socket will be watched to
437/// see if a write will not block.
438/// The argument 'timeout' specifies a maximum time to wait in millisec.
439/// Default no timeout.
440/// Returns 1 if a change of status of interest has been detected within
441/// timeout; 0 in case of timeout; < 0 if an error occured.
442
444{
445 Int_t rc = 1;
446
447 // Associate a TFileHandler to this socket
448 TFileHandler fh(fSocket, interest);
449
450 // Wait for an event now
451 rc = gSystem->Select(&fh, timeout);
452
453 return rc;
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Send a single message opcode. Use kind (opcode) to set the
458/// TMessage "what" field. Returns the number of bytes that were sent
459/// (always sizeof(Int_t)) and -1 in case of error. In case the kind has
460/// been or'ed with kMESS_ACK, the call will only return after having
461/// received an acknowledgement, making the sending process synchronous.
462
464{
465 TMessage mess(kind);
466
467 Int_t nsent;
468 if ((nsent = Send(mess)) < 0)
469 return -1;
470
471 return nsent;
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Send a status and a single message opcode. Use kind (opcode) to set the
476/// TMessage "what" field. Returns the number of bytes that were sent
477/// (always 2*sizeof(Int_t)) and -1 in case of error. In case the kind has
478/// been or'ed with kMESS_ACK, the call will only return after having
479/// received an acknowledgement, making the sending process synchronous.
480
482{
483 TMessage mess(kind);
484 mess << status;
485
486 Int_t nsent;
487 if ((nsent = Send(mess)) < 0)
488 return -1;
489
490 return nsent;
491}
492
493////////////////////////////////////////////////////////////////////////////////
494/// Send a character string buffer. Use kind to set the TMessage "what" field.
495/// Returns the number of bytes in the string str that were sent and -1 in
496/// case of error. In case the kind has been or'ed with kMESS_ACK, the call
497/// will only return after having received an acknowledgement, making the
498/// sending process synchronous.
499
500Int_t TSocket::Send(const char *str, Int_t kind)
501{
502 TMessage mess(kind);
503 if (str) mess.WriteString(str);
504
505 Int_t nsent;
506 if ((nsent = Send(mess)) < 0)
507 return -1;
508
509 return nsent - sizeof(Int_t); // - TMessage::What()
510}
511
512////////////////////////////////////////////////////////////////////////////////
513/// Send a TMessage object. Returns the number of bytes in the TMessage
514/// that were sent and -1 in case of error. In case the TMessage::What
515/// has been or'ed with kMESS_ACK, the call will only return after having
516/// received an acknowledgement, making the sending process synchronous.
517/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
518/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
519/// support for streaming TStreamerInfo added by Rene Brun May 2008
520/// support for streaming TProcessID added by Rene Brun June 2008
521
523{
525
526 if (fSocket < 0) return -1;
527
528 if (mess.IsReading()) {
529 Error("Send", "cannot send a message used for reading");
530 return -1;
531 }
532
533 // send streamer infos in case schema evolution is enabled in the TMessage
534 SendStreamerInfos(mess);
535
536 // send the process id's so TRefs work
537 SendProcessIDs(mess);
538
539 mess.SetLength(); //write length in first word of buffer
540
541 if (GetCompressionLevel() > 0 && mess.GetCompressionLevel() == 0)
542 const_cast<TMessage&>(mess).SetCompressionSettings(fCompress);
543
544 if (mess.GetCompressionLevel() > 0)
545 const_cast<TMessage&>(mess).Compress();
546
547 char *mbuf = mess.Buffer();
548 Int_t mlen = mess.Length();
549 if (mess.CompBuffer()) {
550 mbuf = mess.CompBuffer();
551 mlen = mess.CompLength();
552 }
553
555 Int_t nsent;
556 if ((nsent = gSystem->SendRaw(fSocket, mbuf, mlen, 0)) <= 0) {
557 if (nsent == -5) {
558 // Connection reset by peer or broken
560 }
561 return nsent;
562 }
563
564 fBytesSent += nsent;
565 fgBytesSent += nsent;
566
567 // If acknowledgement is desired, wait for it
568 if (mess.What() & kMESS_ACK) {
571 char buf[2];
572 Int_t n = 0;
573 if ((n = gSystem->RecvRaw(fSocket, buf, sizeof(buf), 0)) < 0) {
574 if (n == -5) {
575 // Connection reset by peer or broken
577 } else
578 n = -1;
579 return n;
580 }
581 if (strncmp(buf, "ok", 2)) {
582 Error("Send", "bad acknowledgement");
583 return -1;
584 }
585 fBytesRecv += 2;
586 fgBytesRecv += 2;
587 }
588
589 Touch(); // update usage timestamp
590
591 return nsent - sizeof(UInt_t); //length - length header
592}
593
594////////////////////////////////////////////////////////////////////////////////
595/// Send an object. Returns the number of bytes sent and -1 in case of error.
596/// In case the "kind" has been or'ed with kMESS_ACK, the call will only
597/// return after having received an acknowledgement, making the sending
598/// synchronous.
599
601{
602 //stream object to message buffer
603 TMessage mess(kind);
604 mess.WriteObject(obj);
605
606 //now sending the object itself
607 Int_t nsent;
608 if ((nsent = Send(mess)) < 0)
609 return -1;
610
611 return nsent;
612}
613
614////////////////////////////////////////////////////////////////////////////////
615/// Send a raw buffer of specified length. Using option kOob one can send
616/// OOB data. Returns the number of bytes sent or -1 in case of error.
617/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
618/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
619
621{
623
624 if (!IsValid()) return -1;
625
627 Int_t nsent;
628 if ((nsent = gSystem->SendRaw(fSocket, buffer, length, (int) opt)) <= 0) {
629 if (nsent == -5) {
630 // Connection reset or broken: close
632 }
633 return nsent;
634 }
635
636 fBytesSent += nsent;
637 fgBytesSent += nsent;
638
639 Touch(); // update usage timestamp
640
641 return nsent;
642}
643
644////////////////////////////////////////////////////////////////////////////////
645/// Check if TStreamerInfo must be sent. The list of TStreamerInfo of classes
646/// in the object in the message is in the fInfos list of the message.
647/// We send only the TStreamerInfos not yet sent on this socket.
648
650{
651 if (mess.fInfos && mess.fInfos->GetEntries()) {
652 TIter next(mess.fInfos);
653 TStreamerInfo *info;
654 TList *minilist = 0;
655 while ((info = (TStreamerInfo*)next())) {
656 Int_t uid = info->GetNumber();
657 if (fBitsInfo.TestBitNumber(uid))
658 continue; //TStreamerInfo had already been sent
660 if (!minilist)
661 minilist = new TList();
662 if (gDebug > 0)
663 Info("SendStreamerInfos", "sending TStreamerInfo: %s, version = %d",
664 info->GetName(),info->GetClassVersion());
665 minilist->Add(info);
666 }
667 if (minilist) {
669 messinfo.WriteObject(minilist);
670 delete minilist;
671 if (messinfo.fInfos)
672 messinfo.fInfos->Clear();
673 if (Send(messinfo) < 0)
674 Warning("SendStreamerInfos", "problems sending TStreamerInfo's ...");
675 }
676 }
677}
678
679////////////////////////////////////////////////////////////////////////////////
680/// Check if TProcessIDs must be sent. The list of TProcessIDs
681/// in the object in the message is found by looking in the TMessage bits.
682/// We send only the TProcessIDs not yet send on this socket.
683
685{
686 if (mess.TestBitNumber(0)) {
688 Int_t npids = pids->GetEntries();
689 TProcessID *pid;
690 TList *minilist = 0;
691 for (Int_t ipid = 0; ipid < npids; ipid++) {
692 pid = (TProcessID*)pids->At(ipid);
693 if (!pid || !mess.TestBitNumber(pid->GetUniqueID()+1))
694 continue;
695 //check if a pid with this title has already been sent through the socket
696 //if not add it to the fUUIDs list
697 if (!fUUIDs) {
698 fUUIDs = new TList();
700 } else {
701 if (fUUIDs->FindObject(pid->GetTitle()))
702 continue;
703 }
704 fUUIDs->Add(new TObjString(pid->GetTitle()));
705 if (!minilist)
706 minilist = new TList();
707 if (gDebug > 0)
708 Info("SendProcessIDs", "sending TProcessID: %s", pid->GetTitle());
709 minilist->Add(pid);
710 }
711 if (minilist) {
712 TMessage messpid(kMESS_PROCESSID);
713 messpid.WriteObject(minilist);
714 delete minilist;
715 if (Send(messpid) < 0)
716 Warning("SendProcessIDs", "problems sending TProcessID's ...");
717 }
718 }
719}
720
721////////////////////////////////////////////////////////////////////////////////
722/// Receive a character string message of maximum max length. The expected
723/// message must be of type kMESS_STRING. Returns length of received string
724/// (can be 0 if otherside of connection is closed) or -1 in case of error
725/// or -4 in case a non-blocking socket would block (i.e. there is nothing
726/// to be read).
727
728Int_t TSocket::Recv(char *str, Int_t max)
729{
730 Int_t n, kind;
731
733 if ((n = Recv(str, max, kind)) <= 0) {
734 if (n == -5) {
736 n = -1;
737 }
738 return n;
739 }
740
741 if (kind != kMESS_STRING) {
742 Error("Recv", "got message of wrong kind (expected %d, got %d)",
743 kMESS_STRING, kind);
744 return -1;
745 }
746
747 return n;
748}
749
750////////////////////////////////////////////////////////////////////////////////
751/// Receive a character string message of maximum max length. Returns in
752/// kind the message type. Returns length of received string+4 (can be 0 if
753/// other side of connection is closed) or -1 in case of error or -4 in
754/// case a non-blocking socket would block (i.e. there is nothing to be read).
755
756Int_t TSocket::Recv(char *str, Int_t max, Int_t &kind)
757{
758 Int_t n;
759 TMessage *mess;
760
762 if ((n = Recv(mess)) <= 0) {
763 if (n == -5) {
765 n = -1;
766 }
767 return n;
768 }
769
770 kind = mess->What();
771 if (str) {
772 if (mess->BufferSize() > (Int_t)sizeof(Int_t)) // if mess contains more than kind
773 mess->ReadString(str, max);
774 else
775 str[0] = 0;
776 }
777
778 delete mess;
779
780 return n; // number of bytes read (len of str + sizeof(kind)
781}
782
783////////////////////////////////////////////////////////////////////////////////
784/// Receives a status and a message type. Returns length of received
785/// integers, 2*sizeof(Int_t) (can be 0 if other side of connection
786/// is closed) or -1 in case of error or -4 in case a non-blocking
787/// socket would block (i.e. there is nothing to be read).
788
790{
791 Int_t n;
792 TMessage *mess;
793
795 if ((n = Recv(mess)) <= 0) {
796 if (n == -5) {
798 n = -1;
799 }
800 return n;
801 }
802
803 kind = mess->What();
804 (*mess) >> status;
805
806 delete mess;
807
808 return n; // number of bytes read (2 * sizeof(Int_t)
809}
810
811////////////////////////////////////////////////////////////////////////////////
812/// Receive a TMessage object. The user must delete the TMessage object.
813/// Returns length of message in bytes (can be 0 if other side of connection
814/// is closed) or -1 in case of error or -4 in case a non-blocking socket
815/// would block (i.e. there is nothing to be read) or -5 if pipe broken
816/// or reset by peer (EPIPE || ECONNRESET). In those case mess == 0.
817
819{
821
822 if (!IsValid()) {
823 mess = 0;
824 return -1;
825 }
826
827oncemore:
829 Int_t n;
830 UInt_t len;
831 if ((n = gSystem->RecvRaw(fSocket, &len, sizeof(UInt_t), 0)) <= 0) {
832 if (n == 0 || n == -5) {
833 // Connection closed, reset or broken
835 }
836 mess = 0;
837 return n;
838 }
839 len = net2host(len); //from network to host byte order
840
842 char *buf = new char[len+sizeof(UInt_t)];
843 if ((n = gSystem->RecvRaw(fSocket, buf+sizeof(UInt_t), len, 0)) <= 0) {
844 if (n == 0 || n == -5) {
845 // Connection closed, reset or broken
847 }
848 delete [] buf;
849 mess = 0;
850 return n;
851 }
852
853 fBytesRecv += n + sizeof(UInt_t);
854 fgBytesRecv += n + sizeof(UInt_t);
855
856 mess = new TMessage(buf, len+sizeof(UInt_t));
857
858 // receive any streamer infos
859 if (RecvStreamerInfos(mess))
860 goto oncemore;
861
862 // receive any process ids
863 if (RecvProcessIDs(mess))
864 goto oncemore;
865
866 if (mess->What() & kMESS_ACK) {
868 char ok[2] = { 'o', 'k' };
869 Int_t n2 = 0;
870 if ((n2 = gSystem->SendRaw(fSocket, ok, sizeof(ok), 0)) < 0) {
871 if (n2 == -5) {
872 // Connection reset or broken
874 }
875 delete mess;
876 mess = 0;
877 return n2;
878 }
879 mess->SetWhat(mess->What() & ~kMESS_ACK);
880
881 fBytesSent += 2;
882 fgBytesSent += 2;
883 }
884
885 Touch(); // update usage timestamp
886
887 return n;
888}
889
890////////////////////////////////////////////////////////////////////////////////
891/// Receive a raw buffer of specified length bytes. Using option kPeek
892/// one can peek at incoming data. Returns number of received bytes.
893/// Returns -1 in case of error. In case of opt == kOob: -2 means
894/// EWOULDBLOCK and -3 EINVAL. In case of non-blocking mode (kNoBlock)
895/// -4 means EWOULDBLOCK. Returns -5 if pipe broken or reset by
896/// peer (EPIPE || ECONNRESET).
897
899{
901
902 if (!IsValid()) return -1;
903 if (length == 0) return 0;
904
906 Int_t n;
907 if ((n = gSystem->RecvRaw(fSocket, buffer, length, (int) opt)) <= 0) {
908 if (n == 0 || n == -5) {
909 // Connection closed, reset or broken
911 }
912 return n;
913 }
914
915 fBytesRecv += n;
916 fgBytesRecv += n;
917
918 Touch(); // update usage timestamp
919
920 return n;
921}
922
923////////////////////////////////////////////////////////////////////////////////
924/// Receive a message containing streamer infos. In case the message contains
925/// streamer infos they are imported, the message will be deleted and the
926/// method returns kTRUE.
927
929{
930 if (mess->What() == kMESS_STREAMERINFO) {
931 TList *list = (TList*)mess->ReadObject(TList::Class());
932 TIter next(list);
933 TStreamerInfo *info;
934 TObjLink *lnk = list->FirstLink();
935 // First call BuildCheck for regular class
936 while (lnk) {
937 info = (TStreamerInfo*)lnk->GetObject();
938 TObject *element = info->GetElements()->UncheckedAt(0);
939 Bool_t isstl = element && strcmp("This",element->GetName())==0;
940 if (!isstl) {
941 info->BuildCheck();
942 if (gDebug > 0)
943 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
944 info->GetName(), info->GetClassVersion());
945 }
946 lnk = lnk->Next();
947 }
948 // Then call BuildCheck for stl class
949 lnk = list->FirstLink();
950 while (lnk) {
951 info = (TStreamerInfo*)lnk->GetObject();
952 TObject *element = info->GetElements()->UncheckedAt(0);
953 Bool_t isstl = element && strcmp("This",element->GetName())==0;
954 if (isstl) {
955 info->BuildCheck();
956 if (gDebug > 0)
957 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
958 info->GetName(), info->GetClassVersion());
959 }
960 lnk = lnk->Next();
961 }
962 delete list;
963 delete mess;
964
965 return kTRUE;
966 }
967 return kFALSE;
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Receive a message containing process ids. In case the message contains
972/// process ids they are imported, the message will be deleted and the
973/// method returns kTRUE.
974
976{
977 if (mess->What() == kMESS_PROCESSID) {
978 TList *list = (TList*)mess->ReadObject(TList::Class());
979 TIter next(list);
980 TProcessID *pid;
981 while ((pid = (TProcessID*)next())) {
982 // check that a similar pid is not already registered in fgPIDs
983 TObjArray *pidslist = TProcessID::GetPIDs();
984 TIter nextpid(pidslist);
985 TProcessID *p;
986 while ((p = (TProcessID*)nextpid())) {
987 if (!strcmp(p->GetTitle(), pid->GetTitle())) {
988 delete pid;
989 pid = 0;
990 break;
991 }
992 }
993 if (pid) {
994 if (gDebug > 0)
995 Info("RecvProcessIDs", "importing TProcessID: %s", pid->GetTitle());
996 pid->IncrementCount();
997 pidslist->Add(pid);
998 Int_t ind = pidslist->IndexOf(pid);
999 pid->SetUniqueID((UInt_t)ind);
1000 }
1001 }
1002 delete list;
1003 delete mess;
1004
1005 return kTRUE;
1006 }
1007 return kFALSE;
1008}
1009
1010////////////////////////////////////////////////////////////////////////////////
1011/// Set socket options.
1012
1014{
1015 if (!IsValid()) return -1;
1016
1017 return gSystem->SetSockOpt(fSocket, opt, val);
1018}
1019
1020////////////////////////////////////////////////////////////////////////////////
1021/// Get socket options. Returns -1 in case of error.
1022
1024{
1025 if (!IsValid()) return -1;
1026
1027 return gSystem->GetSockOpt(fSocket, opt, &val);
1028}
1029
1030////////////////////////////////////////////////////////////////////////////////
1031/// Returns error code. Meaning depends on context where it is called.
1032/// If no error condition returns 0 else a value < 0.
1033/// For example see TServerSocket ctor.
1034
1036{
1037 if (!IsValid())
1038 return fSocket;
1039
1040 return 0;
1041}
1042
1043////////////////////////////////////////////////////////////////////////////////
1044/// See comments for function SetCompressionSettings
1045
1047{
1048 if (algorithm < 0 || algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
1049 if (fCompress < 0) {
1051 } else {
1052 int level = fCompress % 100;
1053 fCompress = 100 * algorithm + level;
1054 }
1055}
1056
1057////////////////////////////////////////////////////////////////////////////////
1058/// See comments for function SetCompressionSettings
1059
1061{
1062 if (level < 0) level = 0;
1063 if (level > 99) level = 99;
1064 if (fCompress < 0) {
1065 // if the algorithm is not defined yet use 0 as a default
1066 fCompress = level;
1067 } else {
1068 int algorithm = fCompress / 100;
1069 if (algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
1070 fCompress = 100 * algorithm + level;
1071 }
1072}
1073
1074////////////////////////////////////////////////////////////////////////////////
1075/// Used to specify the compression level and algorithm:
1076/// settings = 100 * algorithm + level
1077///
1078/// level = 0, objects written to this file will not be compressed.
1079/// level = 1, minimal compression level but fast.
1080/// ....
1081/// level = 9, maximal compression level but slower and might use more memory.
1082/// (For the currently supported algorithms, the maximum level is 9)
1083/// If compress is negative it indicates the compression level is not set yet.
1084///
1085/// The enumeration ROOT::RCompressionSetting::EAlgorithm associates each
1086/// algorithm with a number. There is a utility function to help
1087/// to set the value of the argument. For example,
1088/// ROOT::CompressionSettings(ROOT::kLZMA, 1)
1089/// will build an integer which will set the compression to use
1090/// the LZMA algorithm and compression level 1. These are defined
1091/// in the header file Compression.h.
1092///
1093/// Note that the compression settings may be changed at any time.
1094/// The new compression settings will only apply to branches created
1095/// or attached after the setting is changed and other objects written
1096/// after the setting is changed.
1097
1099{
1100 fCompress = settings;
1101}
1102
1103////////////////////////////////////////////////////////////////////////////////
1104/// Authenticated the socket with specified user.
1105
1107{
1108 Bool_t rc = kFALSE;
1109
1110 // Parse protocol name, for PROOF, send message with server role
1111 TString sproto = TUrl(fUrl).GetProtocol();
1112 if (sproto.Contains("sockd")) {
1113 fServType = kSOCKD;
1114 } else if (sproto.Contains("rootd")) {
1115 fServType = kROOTD;
1116 } else if (sproto.Contains("proofd")) {
1118 // Parse options
1119 TString opt(TUrl(fUrl).GetOptions());
1120 //First letter in Opt describes type of proofserv to invoke
1121 if (!strncasecmp(opt, "S", 1)) {
1122 if (Send("slave") < 0) return rc;
1123 } else if (!strncasecmp(opt, "M", 1)) {
1124 if (Send("master") < 0) return rc;
1125 } else {
1126 Warning("Authenticate",
1127 "called by TSlave: unknown option '%c' %s",
1128 opt[0], " - assuming Slave");
1129 if (Send("slave") < 0) return rc;
1130 }
1131 }
1132 if (gDebug > 2)
1133 Info("Authenticate","Local protocol: %s",sproto.Data());
1134
1135 // Get server protocol level
1136 Int_t kind = kROOTD_PROTOCOL;
1137 // Warning: for backward compatibility reasons here we have to
1138 // send exactly 4 bytes: for fgClientClientProtocol > 99
1139 // the space in the format must be dropped
1140 if (fRemoteProtocol == -1) {
1141 if (Send(Form(" %d", fgClientProtocol), kROOTD_PROTOCOL) < 0) {
1142 return rc;
1143 }
1144 if (Recv(fRemoteProtocol, kind) < 0) {
1145 return rc;
1146 }
1147 //
1148 // If we are talking to an old rootd server we get a fatal
1149 // error here and we need to reopen the connection,
1150 // communicating first the size of the parallel socket
1151 if (kind == kROOTD_ERR) {
1152 fRemoteProtocol = 9;
1153 return kFALSE;
1154 }
1155 }
1156
1157 // Find out whether authentication is required
1158 Bool_t runauth = kTRUE;
1159 if (fRemoteProtocol > 1000) {
1160 // Authentication not required by the remote server
1161 runauth = kFALSE;
1162 fRemoteProtocol %= 1000;
1163 }
1164
1165 // If authentication is required, we need to find out which library
1166 // has to be loaded (preparation for near future, 9/7/05)
1168 if (runauth) {
1169
1170 // Default (future)
1171 TString alib = "Xrd";
1172 if (fRemoteProtocol < 100) {
1173 // Standard Authentication lib
1174 alib = "Root";
1175 }
1176
1177 // Load the plugin
1178 TPluginHandler *h =
1179 gROOT->GetPluginManager()->FindHandler("TVirtualAuth", alib);
1180 if (!h || h->LoadPlugin() != 0) {
1181 Error("Authenticate",
1182 "could not load properly %s authentication plugin", alib.Data());
1183 return rc;
1184 }
1185
1186 // Get an instance of the interface class
1187 TVirtualAuth *auth = (TVirtualAuth *)(h->ExecPlugin(0));
1188 if (!auth) {
1189 Error("Authenticate", "could not instantiate the interface class");
1190 return rc;
1191 }
1192 if (gDebug > 1)
1193 Info("Authenticate", "class for '%s' authentication loaded", alib.Data());
1194
1195 Option_t *opts = (gROOT->IsProofServ()) ? "P" : "";
1196 if (!(auth->Authenticate(this, host, user, opts))) {
1197 Error("Authenticate",
1198 "authentication attempt failed for %s@%s", user, host.Data());
1199 } else {
1200 rc = kTRUE;
1201 }
1202 } else {
1203
1204 // Communicate who we are and our target user
1206 if (u) {
1207 if (Send(Form("%s %s", u->fUser.Data(), user), kROOTD_USER) < 0)
1208 Warning("Authenticate", "problem sending kROOTD_USER (%s,%s)", u->fUser.Data(), user);
1209 delete u;
1210 } else
1211 if (Send(Form("-1 %s", user), kROOTD_USER) < 0)
1212 Warning("Authenticate", "problem sending kROOTD_USER (-1,%s)", user);
1213
1214 rc = kFALSE;
1215
1216 // Receive confirmation that everything went well
1217 Int_t stat;
1218 if (Recv(stat, kind) > 0) {
1219
1220 if (kind == kROOTD_ERR) {
1221 if (gDebug > 0)
1222 TSocket::NetError("TSocket::Authenticate", stat);
1223 } else if (kind == kROOTD_AUTH) {
1224
1225 // Authentication was not required: create inactive
1226 // security context for consistency
1227 fSecContext = new TSecContext(user, host, 0, -4, 0, 0);
1228 if (gDebug > 3)
1229 Info("Authenticate", "no authentication required remotely");
1230
1231 // Set return flag;
1232 rc = 1;
1233 } else {
1234 if (gDebug > 0)
1235 Info("Authenticate", "expected message type %d, received %d",
1236 kROOTD_AUTH, kind);
1237 }
1238 } else {
1239 if (gDebug > 0)
1240 Info("Authenticate", "error receiving message");
1241 }
1242
1243 }
1244
1245 return rc;
1246}
1247
1248////////////////////////////////////////////////////////////////////////////////
1249/// Creates a socket or a parallel socket and authenticates to the
1250/// remote server.
1251///
1252/// url: [[proto][p][auth]://][user@]host[:port][/service][?options]
1253///
1254/// where proto = "sockd", "rootd", "proofd"
1255/// indicates the type of remote server;
1256/// if missing "sockd" is assumed ("sockd" indicates
1257/// any remote server session using TServerSocket)
1258/// [p] = for parallel sockets (forced internally for
1259/// rootd; ignored for proofd)
1260/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1261/// [port] = is the remote port number
1262/// [service] = service name used to determine the port
1263/// (for backward compatibility, specification of
1264/// port as priority)
1265/// options = "m" or "s", when proto=proofd indicates whether
1266/// we are master or slave (used internally by
1267/// TSlave)
1268///
1269/// An already opened connection can be used by passing its socket
1270/// in opensock.
1271///
1272/// If 'err' is defined, '*err' on return from a failed call contains an error
1273/// code (see NetErrors.h).
1274///
1275/// Example:
1276///
1277/// TSocket::CreateAuthSocket("pk://qwerty@machine.fq.dn:5052",3)
1278///
1279/// creates an authenticated parallel socket of size 3 to a sockd
1280/// server running on remote machine machine.fq.dn on port 5052;
1281/// authentication will attempt protocol Kerberos first.
1282///
1283/// NB: may hang if the remote server is not of the correct type;
1284/// at present TSocket has no way to find out the type of the
1285/// remote server automatically
1286///
1287/// Returns pointer to an authenticated socket or 0 if creation or
1288/// authentication is unsuccessful.
1289
1290TSocket *TSocket::CreateAuthSocket(const char *url, Int_t size, Int_t tcpwindowsize,
1291 TSocket *opensock, Int_t *err)
1292{
1294
1295 // Url to be passed to chosen constructor
1296 TString eurl(url);
1297
1298 // Parse protocol, if any
1299 Bool_t parallel = kFALSE;
1300 TString proto(TUrl(url).GetProtocol());
1301 TString protosave = proto;
1302
1303 // Get rid of authentication suffix
1304 TString asfx = "";
1305 if (proto.EndsWith("up") || proto.EndsWith("ug")) {
1306 asfx = proto;
1307 asfx.Remove(0,proto.Length()-2);
1308 proto.Resize(proto.Length()-2);
1309 } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
1310 proto.EndsWith("g") || proto.EndsWith("h")) {
1311 asfx = proto;
1312 asfx.Remove(0,proto.Length()-1);
1313 proto.Resize(proto.Length()-1);
1314 }
1315
1316 // Find out if parallel (ignore if proofd, force if rootd)
1317 if (((proto.EndsWith("p") || size > 1) &&
1318 !proto.BeginsWith("proof")) ||
1319 proto.BeginsWith("root") ) {
1320 parallel = kTRUE;
1321 if (proto.EndsWith("p"))
1322 proto.Resize(proto.Length()-1);
1323 }
1324
1325 // Force "sockd" if the rest is not recognized
1326 if (!proto.BeginsWith("sock") && !proto.BeginsWith("proof") &&
1327 !proto.BeginsWith("root"))
1328 proto = "sockd";
1329
1330 // Substitute this for original proto in eurl
1331 protosave += "://";
1332 proto += asfx;
1333 proto += "://";
1334 eurl.ReplaceAll(protosave,proto);
1335
1336 // Create the socket now
1337
1338 TSocket *sock = 0;
1339 if (!parallel) {
1340
1341 // Simple socket
1342 if (opensock && opensock->IsValid())
1343 sock = opensock;
1344 else
1345 sock = new TSocket(eurl, TUrl(url).GetPort(), tcpwindowsize);
1346
1347 // Authenticate now
1348 if (sock && sock->IsValid()) {
1349 if (!sock->Authenticate(TUrl(url).GetUser())) {
1350 // Nothing to do except setting the error code (if required) and sock to NULL
1351 if (err) {
1352 *err = (Int_t)kErrAuthNotOK;
1354 }
1355 sock->Close();
1356 delete sock;
1357 sock = 0;
1358 }
1359 }
1360
1361 } else {
1362
1363 // Tell TPSocket that we want authentication, which has to
1364 // be done using the original socket before creation of set
1365 // of parallel sockets
1366 if (eurl.Contains("?"))
1367 eurl.Resize(eurl.Index("?"));
1368 eurl += "?A";
1369
1370 // Parallel socket
1371 if (opensock && opensock->IsValid())
1372 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, opensock);
1373 else
1374 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, tcpwindowsize);
1375
1376 // Cleanup if failure ...
1377 if (sock && !sock->IsAuthenticated()) {
1378 // Nothing to do except setting the error code (if required) and sock to NULL
1379 if (err) {
1380 *err = (Int_t)kErrAuthNotOK;
1382 }
1383 if (sock->IsValid())
1384 // And except when the sock is valid; this typically
1385 // happens when talking to a old server, because the
1386 // the parallel socket system is open before authentication
1387 delete sock;
1388 sock = 0;
1389 }
1390 }
1391
1392 return sock;
1393}
1394
1395////////////////////////////////////////////////////////////////////////////////
1396/// Creates a socket or a parallel socket and authenticates to the
1397/// remote server specified in 'url' on remote 'port' as 'user'.
1398///
1399/// url: [[proto][p][auth]://]host[/?options]
1400///
1401/// where proto = "sockd", "rootd", "proofd"
1402/// indicates the type of remote server
1403/// if missing "sockd" is assumed ("sockd" indicates
1404/// any remote server session using TServerSocket)
1405/// [p] = for parallel sockets (forced internally for
1406/// rootd)
1407/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1408/// [options] = "m" or "s", when proto=proofd indicates whether
1409/// we are master or slave (used internally by TSlave)
1410///
1411/// An already opened connection can be used by passing its socket
1412/// in opensock.
1413///
1414/// If 'err' is defined, '*err' on return from a failed call contains an error
1415/// code (see NetErrors.h).
1416///
1417/// Example:
1418///
1419/// TSocket::CreateAuthSocket("qwerty","pk://machine.fq.dn:5052",3)
1420///
1421/// creates an authenticated parallel socket of size 3 to a sockd
1422/// server running on remote machine machine.fq.dn on port 5052;
1423/// authentication will attempt protocol Kerberos first.
1424///
1425/// NB: may hang if the remote server is not of the correct type;
1426/// at present TSocket has no way to find out the type of the
1427/// remote server automatically
1428///
1429/// Returns pointer to an authenticated socket or 0 if creation or
1430/// authentication is unsuccessful.
1431
1432TSocket *TSocket::CreateAuthSocket(const char *user, const char *url,
1433 Int_t port, Int_t size, Int_t tcpwindowsize,
1434 TSocket *opensock, Int_t *err)
1435{
1437
1438 // Extended url to be passed to base call
1439 TString eurl;
1440
1441 // Add protocol, if any
1442 if (TString(TUrl(url).GetProtocol()).Length() > 0) {
1443 eurl += TString(TUrl(url).GetProtocol());
1444 eurl += TString("://");
1445 }
1446 // Add user, if any
1447 if (!user || strlen(user) > 0) {
1448 eurl += TString(user);
1449 eurl += TString("@");
1450 }
1451 // Add host
1452 eurl += TString(TUrl(url).GetHost());
1453 // Add port
1454 eurl += TString(":");
1455 eurl += (port > 0 ? port : 0);
1456 // Add options, if any
1457 if (TString(TUrl(url).GetOptions()).Length() > 0) {
1458 eurl += TString("/?");
1459 eurl += TString(TUrl(url).GetOptions());
1460 }
1461
1462 // Create the socket and return it
1463 return TSocket::CreateAuthSocket(eurl,size,tcpwindowsize,opensock,err);
1464}
1465
1466////////////////////////////////////////////////////////////////////////////////
1467/// Static method returning supported client protocol.
1468
1470{
1471 return fgClientProtocol;
1472}
1473
1474////////////////////////////////////////////////////////////////////////////////
1475/// Print error string depending on error code.
1476
1477void TSocket::NetError(const char *where, Int_t err)
1478{
1479 // Make sure it is in range
1480 err = (err < kErrError) ? ((err > -1) ? err : 0) : kErrError;
1481
1482 if (gDebug > 0)
1483 ::Error(where, "%s", gRootdErrStr[err]);
1484}
1485
1486////////////////////////////////////////////////////////////////////////////////
1487/// Get total number of bytes sent via all sockets.
1488
1490{
1491 return fgBytesSent;
1492}
1493
1494////////////////////////////////////////////////////////////////////////////////
1495/// Get total number of bytes received via all sockets.
1496
1498{
1499 return fgBytesRecv;
1500}
UShort_t net2host(UShort_t x)
Definition Bytes.h:575
@ kMESS_STRING
@ kROOTD_USER
@ kMESS_ACK
@ kROOTD_PROTOCOL
@ kROOTD_AUTH
@ kMESS_PROCESSID
@ kROOTD_ERR
@ kMESS_STREAMERINFO
R__EXTERN const char * gRootdErrStr[]
Definition NetErrors.h:72
@ kErrAuthNotOK
Definition NetErrors.h:51
@ kErrConnectionRefused
Definition NetErrors.h:50
@ kErrError
Definition NetErrors.h:69
#define SafeDelete(p)
Definition RConfig.hxx:525
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
#define R__ASSERT(e)
Definition TError.h:118
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:407
TVirtualMutex * gSocketAuthMutex
Definition TSocket.cxx:63
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
ESockOptions
Definition TSystem.h:215
ESendRecvOptions
Definition TSystem.h:228
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
#define R__LOCKGUARD2(mutex)
const char * proto
Definition civetweb.c:17536
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition TBits.h:222
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition TBits.h:206
TObject * ReadObject(const TClass *cl) override
Read object from I/O buffer.
void WriteString(const char *s) override
Write string to I/O buffer.
char * ReadString(char *s, Int_t max) override
Read string from I/O buffer.
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Int_t BufferSize() const
Definition TBuffer.h:98
Bool_t IsReading() const
Definition TBuffer.h:86
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
This class represents an Internet Protocol (IP) address.
Int_t GetPort() const
const char * GetHostName() const
A doubly linked list.
Definition TList.h:38
static TClass * Class()
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:402
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:578
void Add(TObject *obj) override
Definition TList.h:81
virtual TObjLink * FirstLink() const
Definition TList.h:102
UInt_t What() const
Definition TMessage.h:75
void SetLength() const
Set the message length at the beginning of the message buffer.
Definition TMessage.cxx:202
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition TMessage.h:59
char * CompBuffer() const
Definition TMessage.h:89
Int_t Compress()
Compress the message.
Definition TMessage.cxx:306
Int_t GetCompressionLevel() const
Definition TMessage.h:106
TList * fInfos
Definition TMessage.h:42
Int_t CompLength() const
Definition TMessage.h:90
void SetWhat(UInt_t what)
Using this method one can change the message type a-posteriori In case you OR "what" with kMESS_ACK,...
Definition TMessage.cxx:222
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fName
Definition TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
An array of TObjects.
Definition TObjArray.h:31
Int_t IndexOf(const TObject *obj) const override
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
void Add(TObject *obj) override
Definition TObjArray.h:68
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:457
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:791
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
void ResetBit(UInt_t f)
Definition TObject.h:198
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition TProcessID.h:74
Int_t IncrementCount()
Increase the reference count to this object.
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
TInetAddress fAddress
Definition TSocket.h:59
Int_t fCompress
Definition TSocket.h:62
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
Definition TSocket.cxx:1013
Int_t fSocket
Definition TSocket.h:69
Int_t GetErrorCode() const
Returns error code.
Definition TSocket.cxx:1035
TVirtualMutex * fLastUsageMtx
Definition TSocket.h:75
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1060
void SendStreamerInfos(const TMessage &mess)
Check if TStreamerInfo must be sent.
Definition TSocket.cxx:649
@ kInvalidStillInList
Definition TSocket.h:57
@ kInvalid
Definition TSocket.h:56
TString fUrl
Definition TSocket.h:71
void SetCompressionAlgorithm(Int_t algorithm=ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1046
TSocket()
Definition TSocket.h:83
static ULong64_t GetSocketBytesSent()
Get total number of bytes sent via all sockets.
Definition TSocket.cxx:1489
TString fService
Definition TSocket.h:67
Bool_t RecvStreamerInfos(TMessage *mess)
Receive a message containing streamer infos.
Definition TSocket.cxx:928
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:818
TList * fUUIDs
Definition TSocket.h:73
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition TSocket.cxx:1469
TBits fBitsInfo
Definition TSocket.h:72
Bool_t Authenticate(const char *user)
Authenticated the socket with specified user.
Definition TSocket.cxx:1106
TInetAddress fLocalAddress
Definition TSocket.h:63
static ULong64_t fgBytesRecv
Definition TSocket.h:78
@ kBrokenConn
Definition TSocket.h:49
virtual void Close(Option_t *opt="")
Close the socket.
Definition TSocket.cxx:389
void MarkBrokenConnection()
Close the socket and mark as due to a broken connection.
Definition TSocket.cxx:371
void Touch()
Definition TSocket.h:157
Bool_t RecvProcessIDs(TMessage *mess)
Receive a message containing process ids.
Definition TSocket.cxx:975
TInetAddress GetInetAddress() const
Definition TSocket.h:113
Int_t GetCompressionLevel() const
Definition TSocket.h:181
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition TSocket.cxx:898
static ULong64_t fgBytesSent
Definition TSocket.h:79
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition TSocket.cxx:620
void SendProcessIDs(const TMessage &mess)
Check if TProcessIDs must be sent.
Definition TSocket.cxx:684
static Int_t fgClientProtocol
Definition TSocket.h:81
virtual TInetAddress GetLocalInetAddress()
Return internet address of local host to which the socket is bound.
Definition TSocket.cxx:409
TSecContext * fSecContext
Definition TSocket.h:65
virtual Int_t Select(Int_t interest=kRead, Long_t timeout=-1)
Waits for this socket to change status.
Definition TSocket.cxx:443
virtual Int_t GetLocalPort()
Return the local port # to which the socket is bound.
Definition TSocket.cxx:423
Int_t fTcpWindowSize
Definition TSocket.h:70
Option_t * GetOption() const override
Definition TSocket.h:98
@ kSOCKD
Definition TSocket.h:52
@ kROOTD
Definition TSocket.h:52
@ kPROOFD
Definition TSocket.h:52
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=nullptr, Int_t *err=nullptr)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
Definition TSocket.cxx:1432
static void NetError(const char *where, Int_t error)
Print error string depending on error code.
Definition TSocket.cxx:1477
Int_t GetPort() const
Definition TSocket.h:115
EServiceType fServType
Definition TSocket.h:68
virtual Int_t SendObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Send an object.
Definition TSocket.cxx:600
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Used to specify the compression level and algorithm: settings = 100 * algorithm + level.
Definition TSocket.cxx:1098
UInt_t fBytesSent
Definition TSocket.h:61
Int_t fRemoteProtocol
Definition TSocket.h:64
UInt_t fBytesRecv
Definition TSocket.h:60
virtual Bool_t IsValid() const
Definition TSocket.h:132
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:522
virtual Bool_t IsAuthenticated() const
Definition TSocket.h:131
static ULong64_t GetSocketBytesRecv()
Get total number of bytes received via all sockets.
Definition TSocket.cxx:1497
Describes a persistent version of a class.
Int_t GetClassVersion() const override
Int_t GetNumber() const override
TObjArray * GetElements() const override
void BuildCheck(TFile *file=nullptr, Bool_t load=kTRUE) override
Check if built and consistent with the class dictionary.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
const char * Data() const
Definition TString.h:380
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1140
TString & Remove(Ssiz_t pos)
Definition TString.h:685
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2334
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
virtual int GetServiceByName(const char *service)
Get port # of internet service.
Definition TSystem.cxx:2303
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition TSystem.cxx:2294
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:271
virtual char * GetServiceByPort(int port)
Get name of internet service.
Definition TSystem.cxx:2312
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition TSystem.cxx:2421
virtual TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
Definition TSystem.cxx:2285
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition TSystem.cxx:2321
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition TSystem.cxx:2430
virtual int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Definition TSystem.cxx:2384
virtual Int_t Select(TList *active, Long_t timeout)
Select on active file descriptors (called by TMonitor).
Definition TSystem.cxx:432
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition TSystem.cxx:2276
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition TSystem.cxx:2394
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition TSystem.cxx:2375
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition TSystem.cxx:1586
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetProtocol() const
Definition TUrl.h:64
Int_t GetPort() const
Definition TUrl.h:78
virtual TSecContext * Authenticate(TSocket *, const char *host, const char *user, Option_t *options)=0
This class implements a mutex interface.
const Int_t n
Definition legend1.C:16
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
@ kUndefined
Undefined compression algorithm (must be kept the last of the list in case a new algorithm is added).
@ kUseMin
Compression level reserved when we are not sure what to use (1 is for the fastest compression)
Definition Compression.h:70
TString fUser
Definition TSystem.h:141