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: LEGACY: 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
78 : TNamed(addr.GetHostName(), service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
79{
82
84 fSecContext = 0;
87 if (fService.Contains("root"))
89 fAddress = addr;
91 fBytesSent = 0;
92 fBytesRecv = 0;
94 fUUIDs = 0;
95 fLastUsageMtx = 0;
97
98 if (fAddress.GetPort() != -1) {
101
102 if (fSocket != kInvalid) {
103 gROOT->GetListOfSockets()->Add(this);
104 }
105 } else
107
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Create a socket. Connect to the specified port # at address addr.
112/// Use tcpwindowsize to specify the size of the receive buffer, it has
113/// to be specified here to make sure the window scale option is set (for
114/// tcpwindowsize > 65KB and for platforms supporting window scaling).
115/// Returns when connection has been accepted by remote side. Use IsValid()
116/// to check the validity of the socket. Every socket is added to the TROOT
117/// sockets list which will make sure that any open sockets are properly
118/// closed on program termination.
119
121 : TNamed(addr.GetHostName(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
122{
125
127 fSecContext = 0;
128 fRemoteProtocol= -1;
130 if (fService.Contains("root"))
132 fAddress = addr;
133 fAddress.fPort = port;
135 fBytesSent = 0;
136 fBytesRecv = 0;
138 fUUIDs = 0;
139 fLastUsageMtx = 0;
141
144 if (fSocket == kInvalid)
145 fAddress.fPort = -1;
146 else {
147 gROOT->GetListOfSockets()->Add(this);
148 }
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Create a socket. Connect to named service on the remote host.
153/// Use tcpwindowsize to specify the size of the receive buffer, it has
154/// to be specified here to make sure the window scale option is set (for
155/// tcpwindowsize > 65KB and for platforms supporting window scaling).
156/// Returns when connection has been accepted by remote side. Use IsValid()
157/// to check the validity of the socket. Every socket is added to the TROOT
158/// sockets list which will make sure that any open sockets are properly
159/// closed on program termination.
160
161TSocket::TSocket(const char *host, const char *service, Int_t tcpwindowsize)
162 : TNamed(host, service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
163{
166
168 fSecContext = 0;
169 fRemoteProtocol= -1;
171 if (fService.Contains("root"))
176 fBytesSent = 0;
177 fBytesRecv = 0;
179 fUUIDs = 0;
180 fLastUsageMtx = 0;
182
183 if (fAddress.GetPort() != -1) {
185 if (fSocket != kInvalid) {
186 gROOT->GetListOfSockets()->Add(this);
187 }
188 } else
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Create a socket; see CreateAuthSocket for the form of url.
194/// Connect to the specified port # on the remote host.
195/// If user is specified in url, try authentication as user.
196/// Use tcpwindowsize to specify the size of the receive buffer, it has
197/// to be specified here to make sure the window scale option is set (for
198/// tcpwindowsize > 65KB and for platforms supporting window scaling).
199/// Returns when connection has been accepted by remote side. Use IsValid()
200/// to check the validity of the socket. Every socket is added to the TROOT
201/// sockets list which will make sure that any open sockets are properly
202/// closed on program termination.
203
205 : TNamed(TUrl(url).GetHost(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
206{
209
210 fUrl = TString(url);
211 TString host(TUrl(fUrl).GetHost());
212
214 fSecContext = 0;
215 fRemoteProtocol= -1;
217 if (fUrl.Contains("root"))
220 fAddress.fPort = port;
223 fBytesSent = 0;
224 fBytesRecv = 0;
226 fUUIDs = 0;
227 fLastUsageMtx = 0;
229
231 if (fSocket == kInvalid) {
233 } else {
234 gROOT->GetListOfSockets()->Add(this);
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Create a socket in the Unix domain on 'sockpath'.
240/// Returns when connection has been accepted by the server. Use IsValid()
241/// to check the validity of the socket. Every socket is added to the TROOT
242/// sockets list which will make sure that any open sockets are properly
243/// closed on program termination.
244
246 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
247{
250
251 fUrl = sockpath;
252
253 fService = "unix";
254 fSecContext = 0;
255 fRemoteProtocol= -1;
257 fAddress.fPort = -1;
258 fName.Form("unix:%s", sockpath);
260 fBytesSent = 0;
261 fBytesRecv = 0;
262 fTcpWindowSize = -1;
263 fUUIDs = 0;
264 fLastUsageMtx = 0;
266
268 if (fSocket > 0) {
269 gROOT->GetListOfSockets()->Add(this);
270 }
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Create a socket. The socket will adopt previously opened TCP socket with
275/// descriptor desc.
276
277TSocket::TSocket(Int_t desc) : TNamed("", ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
278{
281
282 fSecContext = 0;
283 fRemoteProtocol = 0;
284 fService = (char *)kSOCKD;
286 fBytesSent = 0;
287 fBytesRecv = 0;
288 fTcpWindowSize = -1;
289 fUUIDs = 0;
290 fLastUsageMtx = 0;
292
293 if (desc >= 0) {
294 fSocket = desc;
296 gROOT->GetListOfSockets()->Add(this);
297 } else
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Create a socket. The socket will adopt previously opened Unix socket with
303/// descriptor desc. The sockpath arg is for info purposes only. Use
304/// this method to adopt e.g. a socket created via socketpair().
305
307 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
308{
311
312 fUrl = sockpath;
313
314 fService = "unix";
315 fSecContext = 0;
316 fRemoteProtocol= -1;
318 fAddress.fPort = -1;
319 fName.Form("unix:%s", sockpath);
321 fBytesSent = 0;
322 fBytesRecv = 0;
323 fTcpWindowSize = -1;
324 fUUIDs = 0;
325 fLastUsageMtx = 0;
327
328 if (desc >= 0) {
329 fSocket = desc;
330 gROOT->GetListOfSockets()->Add(this);
331 } else
333}
334
335
336////////////////////////////////////////////////////////////////////////////////
337/// TSocket copy ctor.
338
340{
341 fSocket = s.fSocket;
342 fService = s.fService;
343 fAddress = s.fAddress;
352 fUUIDs = 0;
353 fLastUsageMtx = 0;
355
356 if (fSocket != kInvalid) {
357 gROOT->GetListOfSockets()->Add(this);
358 }
359}
360////////////////////////////////////////////////////////////////////////////////
361/// Close the socket and mark as due to a broken connection.
362
374
375////////////////////////////////////////////////////////////////////////////////
376/// Close the socket. If option is "force", calls shutdown(id,2) to
377/// shut down the connection. This will close the connection also
378/// for the parent of this process. Also called via the dtor (without
379/// option "force", call explicitly Close("force") if this is desired).
380
382{
383 Bool_t force = option ? (!strcmp(option, "force") ? kTRUE : kFALSE) : kFALSE;
384
385 if (fSocket != kInvalid) {
386 if (IsValid()) { // Filter out kInvalidStillInList case (disconnected but not removed from list)
388 }
389 gROOT->GetListOfSockets()->Remove(this);
390 }
392
395}
396
397////////////////////////////////////////////////////////////////////////////////
398/// Return internet address of local host to which the socket is bound.
399/// In case of error TInetAddress::IsValid() returns kFALSE.
400
402{
403 if (IsValid()) {
404 if (fLocalAddress.GetPort() == -1)
406 return fLocalAddress;
407 }
408 return TInetAddress();
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Return the local port # to which the socket is bound.
413/// In case of error return -1.
414
416{
417 if (IsValid()) {
418 if (fLocalAddress.GetPort() == -1)
420 return fLocalAddress.GetPort();
421 }
422 return -1;
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Waits for this socket to change status. If interest=kRead,
427/// the socket will be watched to see if characters become available for
428/// reading; if interest=kWrite the socket will be watched to
429/// see if a write will not block.
430/// The argument 'timeout' specifies a maximum time to wait in millisec.
431/// Default no timeout.
432/// Returns 1 if a change of status of interest has been detected within
433/// timeout; 0 in case of timeout; < 0 if an error occured.
434
436{
437 Int_t rc = 1;
438
439 // Associate a TFileHandler to this socket
441
442 // Wait for an event now
443 rc = gSystem->Select(&fh, timeout);
444
445 return rc;
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Send a single message opcode. Use kind (opcode) to set the
450/// TMessage "what" field. Returns the number of bytes that were sent
451/// (always sizeof(Int_t)) and -1 in case of error. In case the kind has
452/// been or'ed with kMESS_ACK, the call will only return after having
453/// received an acknowledgement, making the sending process synchronous.
454
456{
457 TMessage mess(kind);
458
459 Int_t nsent;
460 if ((nsent = Send(mess)) < 0)
461 return -1;
462
463 return nsent;
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// Send a status and a single message opcode. Use kind (opcode) to set the
468/// TMessage "what" field. Returns the number of bytes that were sent
469/// (always 2*sizeof(Int_t)) and -1 in case of error. In case the kind has
470/// been or'ed with kMESS_ACK, the call will only return after having
471/// received an acknowledgement, making the sending process synchronous.
472
474{
475 TMessage mess(kind);
476 mess << status;
477
478 Int_t nsent;
479 if ((nsent = Send(mess)) < 0)
480 return -1;
481
482 return nsent;
483}
484
485////////////////////////////////////////////////////////////////////////////////
486/// Send a character string buffer. Use kind to set the TMessage "what" field.
487/// Returns the number of bytes in the string str that were sent and -1 in
488/// case of error. In case the kind has been or'ed with kMESS_ACK, the call
489/// will only return after having received an acknowledgement, making the
490/// sending process synchronous.
491
492Int_t TSocket::Send(const char *str, Int_t kind)
493{
494 TMessage mess(kind);
495 if (str) mess.WriteString(str);
496
497 Int_t nsent;
498 if ((nsent = Send(mess)) < 0)
499 return -1;
500
501 return nsent - sizeof(Int_t); // - TMessage::What()
502}
503
504////////////////////////////////////////////////////////////////////////////////
505/// Send a TMessage object. Returns the number of bytes in the TMessage
506/// that were sent and -1 in case of error. In case the TMessage::What
507/// has been or'ed with kMESS_ACK, the call will only return after having
508/// received an acknowledgement, making the sending process synchronous.
509/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
510/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
511/// support for streaming TStreamerInfo added by Rene Brun May 2008
512/// support for streaming TProcessID added by Rene Brun June 2008
513
515{
517
518 if (fSocket < 0) return -1;
519
520 if (mess.IsReading()) {
521 Error("Send", "cannot send a message used for reading");
522 return -1;
523 }
524
525 // send streamer infos in case schema evolution is enabled in the TMessage
527
528 // send the process id's so TRefs work
530
531 mess.SetLength(); //write length in first word of buffer
532
533 if (GetCompressionLevel() > 0 && mess.GetCompressionLevel() == 0)
535
536 if (mess.GetCompressionLevel() > 0)
537 const_cast<TMessage&>(mess).Compress();
538
539 char *mbuf = mess.Buffer();
540 Int_t mlen = mess.Length();
541 if (mess.CompBuffer()) {
542 mbuf = mess.CompBuffer();
543 mlen = mess.CompLength();
544 }
545
547 Int_t nsent;
548 if ((nsent = gSystem->SendRaw(fSocket, mbuf, mlen, 0)) <= 0) {
549 if (nsent == -5) {
550 // Connection reset by peer or broken
552 }
553 return nsent;
554 }
555
556 fBytesSent += nsent;
558
559 // If acknowledgement is desired, wait for it
560 if (mess.What() & kMESS_ACK) {
563 char buf[2];
564 Int_t n = 0;
565 if ((n = gSystem->RecvRaw(fSocket, buf, sizeof(buf), 0)) < 0) {
566 if (n == -5) {
567 // Connection reset by peer or broken
569 } else
570 n = -1;
571 return n;
572 }
573 if (strncmp(buf, "ok", 2)) {
574 Error("Send", "bad acknowledgement");
575 return -1;
576 }
577 fBytesRecv += 2;
578 fgBytesRecv += 2;
579 }
580
581 Touch(); // update usage timestamp
582
583 return nsent - sizeof(UInt_t); //length - length header
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Send an object. Returns the number of bytes sent and -1 in case of error.
588/// In case the "kind" has been or'ed with kMESS_ACK, the call will only
589/// return after having received an acknowledgement, making the sending
590/// synchronous.
591
593{
594 //stream object to message buffer
595 TMessage mess(kind);
596 mess.WriteObject(obj);
597
598 //now sending the object itself
599 Int_t nsent;
600 if ((nsent = Send(mess)) < 0)
601 return -1;
602
603 return nsent;
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Send a raw buffer of specified length. Using option kOob one can send
608/// OOB data. Returns the number of bytes sent or -1 in case of error.
609/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
610/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
611
613{
615
616 if (!IsValid()) return -1;
617
619 Int_t nsent;
620 if ((nsent = gSystem->SendRaw(fSocket, buffer, length, (int) opt)) <= 0) {
621 if (nsent == -5) {
622 // Connection reset or broken: close
624 }
625 return nsent;
626 }
627
628 fBytesSent += nsent;
630
631 Touch(); // update usage timestamp
632
633 return nsent;
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Check if TStreamerInfo must be sent. The list of TStreamerInfo of classes
638/// in the object in the message is in the fInfos list of the message.
639/// We send only the TStreamerInfos not yet sent on this socket.
640
642{
643 if (mess.fInfos && mess.fInfos->GetEntries()) {
644 TIter next(mess.fInfos);
646 TList *minilist = 0;
647 while ((info = (TStreamerInfo*)next())) {
648 Int_t uid = info->GetNumber();
649 if (fBitsInfo.TestBitNumber(uid))
650 continue; //TStreamerInfo had already been sent
652 if (!minilist)
653 minilist = new TList();
654 if (gDebug > 0)
655 Info("SendStreamerInfos", "sending TStreamerInfo: %s, version = %d",
656 info->GetName(),info->GetClassVersion());
657 minilist->Add(info);
658 }
659 if (minilist) {
661 messinfo.WriteObject(minilist);
662 delete minilist;
663 if (messinfo.fInfos)
664 messinfo.fInfos->Clear();
665 if (Send(messinfo) < 0)
666 Warning("SendStreamerInfos", "problems sending TStreamerInfo's ...");
667 }
668 }
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Check if TProcessIDs must be sent. The list of TProcessIDs
673/// in the object in the message is found by looking in the TMessage bits.
674/// We send only the TProcessIDs not yet send on this socket.
675
677{
678 if (mess.TestBitNumber(0)) {
680 Int_t npids = pids->GetEntries();
681 TProcessID *pid;
682 TList *minilist = 0;
683 for (Int_t ipid = 0; ipid < npids; ipid++) {
684 pid = (TProcessID*)pids->At(ipid);
685 if (!pid || !mess.TestBitNumber(pid->GetUniqueID()+1))
686 continue;
687 //check if a pid with this title has already been sent through the socket
688 //if not add it to the fUUIDs list
689 if (!fUUIDs) {
690 fUUIDs = new TList();
692 } else {
693 if (fUUIDs->FindObject(pid->GetTitle()))
694 continue;
695 }
696 fUUIDs->Add(new TObjString(pid->GetTitle()));
697 if (!minilist)
698 minilist = new TList();
699 if (gDebug > 0)
700 Info("SendProcessIDs", "sending TProcessID: %s", pid->GetTitle());
701 minilist->Add(pid);
702 }
703 if (minilist) {
705 messpid.WriteObject(minilist);
706 delete minilist;
707 if (Send(messpid) < 0)
708 Warning("SendProcessIDs", "problems sending TProcessID's ...");
709 }
710 }
711}
712
713////////////////////////////////////////////////////////////////////////////////
714/// Receive a character string message of maximum max length. The expected
715/// message must be of type kMESS_STRING. Returns length of received string
716/// (can be 0 if otherside of connection is closed) or -1 in case of error
717/// or -4 in case a non-blocking socket would block (i.e. there is nothing
718/// to be read).
719
720Int_t TSocket::Recv(char *str, Int_t max)
721{
722 Int_t n, kind;
723
725 if ((n = Recv(str, max, kind)) <= 0) {
726 if (n == -5) {
728 n = -1;
729 }
730 return n;
731 }
732
733 if (kind != kMESS_STRING) {
734 Error("Recv", "got message of wrong kind (expected %d, got %d)",
735 kMESS_STRING, kind);
736 return -1;
737 }
738
739 return n;
740}
741
742////////////////////////////////////////////////////////////////////////////////
743/// Receive a character string message of maximum max length. Returns in
744/// kind the message type. Returns length of received string+4 (can be 0 if
745/// other side of connection is closed) or -1 in case of error or -4 in
746/// case a non-blocking socket would block (i.e. there is nothing to be read).
747
748Int_t TSocket::Recv(char *str, Int_t max, Int_t &kind)
749{
750 Int_t n;
751 TMessage *mess;
752
754 if ((n = Recv(mess)) <= 0) {
755 if (n == -5) {
757 n = -1;
758 }
759 return n;
760 }
761
762 kind = mess->What();
763 if (str) {
764 if (mess->BufferSize() > (Int_t)sizeof(Int_t)) // if mess contains more than kind
765 mess->ReadString(str, max);
766 else
767 str[0] = 0;
768 }
769
770 delete mess;
771
772 return n; // number of bytes read (len of str + sizeof(kind)
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// Receives a status and a message type. Returns length of received
777/// integers, 2*sizeof(Int_t) (can be 0 if other side of connection
778/// is closed) or -1 in case of error or -4 in case a non-blocking
779/// socket would block (i.e. there is nothing to be read).
780
782{
783 Int_t n;
784 TMessage *mess;
785
787 if ((n = Recv(mess)) <= 0) {
788 if (n == -5) {
790 n = -1;
791 }
792 return n;
793 }
794
795 kind = mess->What();
796 (*mess) >> status;
797
798 delete mess;
799
800 return n; // number of bytes read (2 * sizeof(Int_t)
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Receive a TMessage object. The user must delete the TMessage object.
805/// Returns length of message in bytes (can be 0 if other side of connection
806/// is closed) or -1 in case of error or -4 in case a non-blocking socket
807/// would block (i.e. there is nothing to be read) or -5 if pipe broken
808/// or reset by peer (EPIPE || ECONNRESET). In those case mess == 0.
809
811{
813
814 if (!IsValid()) {
815 mess = 0;
816 return -1;
817 }
818
821 Int_t n;
822 UInt_t len;
823 if ((n = gSystem->RecvRaw(fSocket, &len, sizeof(UInt_t), 0)) <= 0) {
824 if (n == 0 || n == -5) {
825 // Connection closed, reset or broken
827 }
828 mess = 0;
829 return n;
830 }
831 len = net2host(len); //from network to host byte order
832
834 char *buf = new char[len+sizeof(UInt_t)];
835 if ((n = gSystem->RecvRaw(fSocket, buf+sizeof(UInt_t), len, 0)) <= 0) {
836 if (n == 0 || n == -5) {
837 // Connection closed, reset or broken
839 }
840 delete [] buf;
841 mess = 0;
842 return n;
843 }
844
845 fBytesRecv += n + sizeof(UInt_t);
846 fgBytesRecv += n + sizeof(UInt_t);
847
848 mess = new TMessage(buf, len+sizeof(UInt_t));
849
850 // receive any streamer infos
852 goto oncemore;
853
854 // receive any process ids
855 if (RecvProcessIDs(mess))
856 goto oncemore;
857
858 if (mess->What() & kMESS_ACK) {
860 char ok[2] = { 'o', 'k' };
861 Int_t n2 = 0;
862 if ((n2 = gSystem->SendRaw(fSocket, ok, sizeof(ok), 0)) < 0) {
863 if (n2 == -5) {
864 // Connection reset or broken
866 }
867 delete mess;
868 mess = 0;
869 return n2;
870 }
871 mess->SetWhat(mess->What() & ~kMESS_ACK);
872
873 fBytesSent += 2;
874 fgBytesSent += 2;
875 }
876
877 Touch(); // update usage timestamp
878
879 return n;
880}
881
882////////////////////////////////////////////////////////////////////////////////
883/// Receive a raw buffer of specified length bytes. Using option kPeek
884/// one can peek at incoming data. Returns number of received bytes.
885/// Returns -1 in case of error. In case of opt == kOob: -2 means
886/// EWOULDBLOCK and -3 EINVAL. In case of non-blocking mode (kNoBlock)
887/// -4 means EWOULDBLOCK. Returns -5 if pipe broken or reset by
888/// peer (EPIPE || ECONNRESET).
889
891{
893
894 if (!IsValid()) return -1;
895 if (length == 0) return 0;
896
898 Int_t n;
899 if ((n = gSystem->RecvRaw(fSocket, buffer, length, (int) opt)) <= 0) {
900 if (n == 0 || n == -5) {
901 // Connection closed, reset or broken
903 }
904 return n;
905 }
906
907 fBytesRecv += n;
908 fgBytesRecv += n;
909
910 Touch(); // update usage timestamp
911
912 return n;
913}
914
915////////////////////////////////////////////////////////////////////////////////
916/// Receive a message containing streamer infos. In case the message contains
917/// streamer infos they are imported, the message will be deleted and the
918/// method returns kTRUE.
919
921{
922 if (mess->What() == kMESS_STREAMERINFO) {
923 TList *list = (TList*)mess->ReadObject(TList::Class());
924 TIter next(list);
926 TObjLink *lnk = list->FirstLink();
927 // First call BuildCheck for regular class
928 while (lnk) {
929 info = (TStreamerInfo*)lnk->GetObject();
930 TObject *element = info->GetElements()->UncheckedAt(0);
931 Bool_t isstl = element && strcmp("This",element->GetName())==0;
932 if (!isstl) {
933 info->BuildCheck();
934 if (gDebug > 0)
935 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
936 info->GetName(), info->GetClassVersion());
937 }
938 lnk = lnk->Next();
939 }
940 // Then call BuildCheck for stl class
941 lnk = list->FirstLink();
942 while (lnk) {
943 info = (TStreamerInfo*)lnk->GetObject();
944 TObject *element = info->GetElements()->UncheckedAt(0);
945 Bool_t isstl = element && strcmp("This",element->GetName())==0;
946 if (isstl) {
947 info->BuildCheck();
948 if (gDebug > 0)
949 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
950 info->GetName(), info->GetClassVersion());
951 }
952 lnk = lnk->Next();
953 }
954 delete list;
955 delete mess;
956
957 return kTRUE;
958 }
959 return kFALSE;
960}
961
962////////////////////////////////////////////////////////////////////////////////
963/// Receive a message containing process ids. In case the message contains
964/// process ids they are imported, the message will be deleted and the
965/// method returns kTRUE.
966
968{
969 if (mess->What() == kMESS_PROCESSID) {
970 TList *list = (TList*)mess->ReadObject(TList::Class());
971 TIter next(list);
972 TProcessID *pid;
973 while ((pid = (TProcessID*)next())) {
974 // check that a similar pid is not already registered in fgPIDs
977 TProcessID *p;
978 while ((p = (TProcessID*)nextpid())) {
979 if (!strcmp(p->GetTitle(), pid->GetTitle())) {
980 delete pid;
981 pid = 0;
982 break;
983 }
984 }
985 if (pid) {
986 if (gDebug > 0)
987 Info("RecvProcessIDs", "importing TProcessID: %s", pid->GetTitle());
988 pid->IncrementCount();
989 pidslist->Add(pid);
990 Int_t ind = pidslist->IndexOf(pid);
991 pid->SetUniqueID((UInt_t)ind);
992 }
993 }
994 delete list;
995 delete mess;
996
997 return kTRUE;
998 }
999 return kFALSE;
1000}
1001
1002////////////////////////////////////////////////////////////////////////////////
1003/// Set socket options.
1004
1006{
1007 if (!IsValid()) return -1;
1008
1009 return gSystem->SetSockOpt(fSocket, opt, val);
1010}
1011
1012////////////////////////////////////////////////////////////////////////////////
1013/// Get socket options. Returns -1 in case of error.
1014
1016{
1017 if (!IsValid()) return -1;
1018
1019 return gSystem->GetSockOpt(fSocket, opt, &val);
1020}
1021
1022////////////////////////////////////////////////////////////////////////////////
1023/// Returns error code. Meaning depends on context where it is called.
1024/// If no error condition returns 0 else a value < 0.
1025/// For example see TServerSocket ctor.
1026
1028{
1029 if (!IsValid())
1030 return fSocket;
1031
1032 return 0;
1033}
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// See comments for function SetCompressionSettings
1037
1048
1049////////////////////////////////////////////////////////////////////////////////
1050/// See comments for function SetCompressionSettings
1051
1053{
1054 if (level < 0) level = 0;
1055 if (level > 99) level = 99;
1056 if (fCompress < 0) {
1057 // if the algorithm is not defined yet use 0 as a default
1058 fCompress = level;
1059 } else {
1060 int algorithm = fCompress / 100;
1062 fCompress = 100 * algorithm + level;
1063 }
1064}
1065
1066////////////////////////////////////////////////////////////////////////////////
1067/// Used to specify the compression level and algorithm:
1068/// settings = 100 * algorithm + level
1069///
1070/// level = 0, objects written to this file will not be compressed.
1071/// level = 1, minimal compression level but fast.
1072/// ....
1073/// level = 9, maximal compression level but slower and might use more memory.
1074/// (For the currently supported algorithms, the maximum level is 9)
1075/// If compress is negative it indicates the compression level is not set yet.
1076///
1077/// The enumeration ROOT::RCompressionSetting::EAlgorithm associates each
1078/// algorithm with a number. There is a utility function to help
1079/// to set the value of the argument. For example,
1080/// ROOT::CompressionSettings(ROOT::kLZMA, 1)
1081/// will build an integer which will set the compression to use
1082/// the LZMA algorithm and compression level 1. These are defined
1083/// in the header file Compression.h.
1084///
1085/// Note that the compression settings may be changed at any time.
1086/// The new compression settings will only apply to branches created
1087/// or attached after the setting is changed and other objects written
1088/// after the setting is changed.
1089
1094
1095////////////////////////////////////////////////////////////////////////////////
1096/// Authenticated the socket with specified user.
1097
1099{
1100 Bool_t rc = kFALSE;
1101
1102 // Parse protocol name
1104 if (sproto.Contains("sockd")) {
1105 fServType = kSOCKD;
1106 } else if (sproto.Contains("rootd")) {
1107 fServType = kROOTD;
1108 }
1109 if (gDebug > 2)
1110 Info("Authenticate","Local protocol: %s",sproto.Data());
1111
1112 // Get server protocol level
1113 Int_t kind = kROOTD_PROTOCOL;
1114 // Warning: for backward compatibility reasons here we have to
1115 // send exactly 4 bytes: for fgClientClientProtocol > 99
1116 // the space in the format must be dropped
1117 if (fRemoteProtocol == -1) {
1118 if (Send(Form(" %d", fgClientProtocol), kROOTD_PROTOCOL) < 0) {
1119 return rc;
1120 }
1121 if (Recv(fRemoteProtocol, kind) < 0) {
1122 return rc;
1123 }
1124 //
1125 // If we are talking to an old rootd server we get a fatal
1126 // error here and we need to reopen the connection,
1127 // communicating first the size of the parallel socket
1128 if (kind == kROOTD_ERR) {
1129 fRemoteProtocol = 9;
1130 return kFALSE;
1131 }
1132 }
1133
1134 // Find out whether authentication is required
1136 if (fRemoteProtocol > 1000) {
1137 // Authentication not required by the remote server
1138 runauth = kFALSE;
1139 fRemoteProtocol %= 1000;
1140 }
1141
1142 // If authentication is required, we need to find out which library
1143 // has to be loaded (preparation for near future, 9/7/05)
1145 if (runauth) {
1146
1147 // Default (future)
1148 TString alib = "Xrd";
1149 if (fRemoteProtocol < 100) {
1150 // Standard Authentication lib
1151 alib = "Root";
1152 }
1153
1154 // Load the plugin
1155 TPluginHandler *h =
1156 gROOT->GetPluginManager()->FindHandler("TVirtualAuth", alib);
1157 if (!h || h->LoadPlugin() != 0) {
1158 Error("Authenticate",
1159 "could not load properly %s authentication plugin", alib.Data());
1160 return rc;
1161 }
1162
1163 // Get an instance of the interface class
1164 TVirtualAuth *auth = (TVirtualAuth *)(h->ExecPlugin(0));
1165 if (!auth) {
1166 Error("Authenticate", "could not instantiate the interface class");
1167 return rc;
1168 }
1169 if (gDebug > 1)
1170 Info("Authenticate", "class for '%s' authentication loaded", alib.Data());
1171
1172 Option_t *opts = "";
1173 if (!(auth->Authenticate(this, host, user, opts))) {
1174 Error("Authenticate",
1175 "authentication attempt failed for %s@%s", user, host.Data());
1176 } else {
1177 rc = kTRUE;
1178 }
1179 } else {
1180
1181 // Communicate who we are and our target user
1183 if (u) {
1184 if (Send(Form("%s %s", u->fUser.Data(), user), kROOTD_USER) < 0)
1185 Warning("Authenticate", "problem sending kROOTD_USER (%s,%s)", u->fUser.Data(), user);
1186 delete u;
1187 } else
1188 if (Send(Form("-1 %s", user), kROOTD_USER) < 0)
1189 Warning("Authenticate", "problem sending kROOTD_USER (-1,%s)", user);
1190
1191 rc = kFALSE;
1192
1193 // Receive confirmation that everything went well
1194 Int_t stat;
1195 if (Recv(stat, kind) > 0) {
1196
1197 if (kind == kROOTD_ERR) {
1198 if (gDebug > 0)
1199 TSocket::NetError("TSocket::Authenticate", stat);
1200 } else if (kind == kROOTD_AUTH) {
1201
1202 // Authentication was not required: create inactive
1203 // security context for consistency
1204 fSecContext = new TSecContext(user, host, 0, -4, 0, 0);
1205 if (gDebug > 3)
1206 Info("Authenticate", "no authentication required remotely");
1207
1208 // Set return flag;
1209 rc = 1;
1210 } else {
1211 if (gDebug > 0)
1212 Info("Authenticate", "expected message type %d, received %d",
1213 kROOTD_AUTH, kind);
1214 }
1215 } else {
1216 if (gDebug > 0)
1217 Info("Authenticate", "error receiving message");
1218 }
1219
1220 }
1221
1222 return rc;
1223}
1224
1225////////////////////////////////////////////////////////////////////////////////
1226/// Creates a socket or a parallel socket and authenticates to the
1227/// remote server.
1228///
1229/// url: [[proto][p][auth]://][user@]host[:port][/service]
1230///
1231/// where proto = "sockd", "rootd"
1232/// indicates the type of remote server;
1233/// if missing "sockd" is assumed ("sockd" indicates
1234/// any remote server session using TServerSocket)
1235/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1236/// [port] = is the remote port number
1237/// [service] = service name used to determine the port
1238/// (for backward compatibility, specification of
1239/// port as priority)
1240///
1241/// An already opened connection can be used by passing its socket
1242/// in opensock.
1243///
1244/// If 'err' is defined, '*err' on return from a failed call contains an error
1245/// code (see NetErrors.h).
1246///
1247/// Example:
1248///
1249/// TSocket::CreateAuthSocket("pk://qwerty@machine.fq.dn:5052",3)
1250///
1251/// creates an authenticated parallel socket of size 3 to a sockd
1252/// server running on remote machine machine.fq.dn on port 5052;
1253/// authentication will attempt protocol Kerberos first.
1254///
1255/// NB: may hang if the remote server is not of the correct type;
1256/// at present TSocket has no way to find out the type of the
1257/// remote server automatically
1258///
1259/// Returns pointer to an authenticated socket or 0 if creation or
1260/// authentication is unsuccessful.
1261
1263 TSocket *opensock, Int_t *err)
1264{
1266
1267 // Url to be passed to chosen constructor
1268 TString eurl(url);
1269
1270 // Parse protocol, if any
1272 TString proto(TUrl(url).GetProtocol());
1274
1275 // Get rid of authentication suffix
1276 TString asfx = "";
1277 if (proto.EndsWith("up") || proto.EndsWith("ug")) {
1278 asfx = proto;
1279 asfx.Remove(0,proto.Length()-2);
1280 proto.Resize(proto.Length()-2);
1281 } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
1282 proto.EndsWith("g") || proto.EndsWith("h")) {
1283 asfx = proto;
1284 asfx.Remove(0,proto.Length()-1);
1285 proto.Resize(proto.Length()-1);
1286 }
1287
1288 // Find out if parallel (force if rootd)
1289 if ((proto.EndsWith("p") || size > 1) ||
1290 proto.BeginsWith("root") ) {
1291 parallel = kTRUE;
1292 if (proto.EndsWith("p"))
1293 proto.Resize(proto.Length()-1);
1294 }
1295
1296 // Force "sockd" if the rest is not recognized
1297 if (!proto.BeginsWith("sock") &&
1298 !proto.BeginsWith("root"))
1299 proto = "sockd";
1300
1301 // Substitute this for original proto in eurl
1302 protosave += "://";
1303 proto += asfx;
1304 proto += "://";
1305 eurl.ReplaceAll(protosave,proto);
1306
1307 // Create the socket now
1308
1309 TSocket *sock = 0;
1310 if (!parallel) {
1311
1312 // Simple socket
1313 if (opensock && opensock->IsValid())
1314 sock = opensock;
1315 else
1316 sock = new TSocket(eurl, TUrl(url).GetPort(), tcpwindowsize);
1317
1318 // Authenticate now
1319 if (sock && sock->IsValid()) {
1320 if (!sock->Authenticate(TUrl(url).GetUser())) {
1321 // Nothing to do except setting the error code (if required) and sock to NULL
1322 if (err) {
1323 *err = (Int_t)kErrAuthNotOK;
1325 }
1326 sock->Close();
1327 delete sock;
1328 sock = 0;
1329 }
1330 }
1331
1332 } else {
1333
1334 // Tell TPSocket that we want authentication, which has to
1335 // be done using the original socket before creation of set
1336 // of parallel sockets
1337 if (eurl.Contains("?"))
1338 eurl.Resize(eurl.Index("?"));
1339 eurl += "?A";
1340
1341 // Parallel socket
1342 if (opensock && opensock->IsValid())
1343 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, opensock);
1344 else
1345 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, tcpwindowsize);
1346
1347 // Cleanup if failure ...
1348 if (sock && !sock->IsAuthenticated()) {
1349 // Nothing to do except setting the error code (if required) and sock to NULL
1350 if (err) {
1351 *err = (Int_t)kErrAuthNotOK;
1353 }
1354 if (sock->IsValid())
1355 // And except when the sock is valid; this typically
1356 // happens when talking to a old server, because the
1357 // the parallel socket system is open before authentication
1358 delete sock;
1359 sock = 0;
1360 }
1361 }
1362
1363 return sock;
1364}
1365
1366////////////////////////////////////////////////////////////////////////////////
1367/// Creates a socket or a parallel socket and authenticates to the
1368/// remote server specified in 'url' on remote 'port' as 'user'.
1369///
1370/// url: [[proto][auth]://]host
1371///
1372/// where proto = "sockd", "rootd"
1373/// indicates the type of remote server
1374/// if missing "sockd" is assumed ("sockd" indicates
1375/// any remote server session using TServerSocket)
1376/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1377///
1378/// An already opened connection can be used by passing its socket
1379/// in opensock.
1380///
1381/// If 'err' is defined, '*err' on return from a failed call contains an error
1382/// code (see NetErrors.h).
1383///
1384/// Example:
1385///
1386/// TSocket::CreateAuthSocket("qwerty","pk://machine.fq.dn:5052",3)
1387///
1388/// creates an authenticated parallel socket of size 3 to a sockd
1389/// server running on remote machine machine.fq.dn on port 5052;
1390/// authentication will attempt protocol Kerberos first.
1391///
1392/// NB: may hang if the remote server is not of the correct type;
1393/// at present TSocket has no way to find out the type of the
1394/// remote server automatically
1395///
1396/// Returns pointer to an authenticated socket or 0 if creation or
1397/// authentication is unsuccessful.
1398
1399TSocket *TSocket::CreateAuthSocket(const char *user, const char *url,
1401 TSocket *opensock, Int_t *err)
1402{
1404
1405 // Extended url to be passed to base call
1406 TString eurl;
1407
1408 // Add protocol, if any
1409 if (TString(TUrl(url).GetProtocol()).Length() > 0) {
1410 eurl += TString(TUrl(url).GetProtocol());
1411 eurl += TString("://");
1412 }
1413 // Add user, if any
1414 if (!user || strlen(user) > 0) {
1415 eurl += TString(user);
1416 eurl += TString("@");
1417 }
1418 // Add host
1419 eurl += TString(TUrl(url).GetHost());
1420 // Add port
1421 eurl += TString(":");
1422 eurl += (port > 0 ? port : 0);
1423 // Add options, if any
1424 if (TString(TUrl(url).GetOptions()).Length() > 0) {
1425 eurl += TString("/?");
1426 eurl += TString(TUrl(url).GetOptions());
1427 }
1428
1429 // Create the socket and return it
1431}
1432
1433////////////////////////////////////////////////////////////////////////////////
1434/// Static method returning supported client protocol.
1435
1440
1441////////////////////////////////////////////////////////////////////////////////
1442/// Print error string depending on error code.
1443
1444void TSocket::NetError(const char *where, Int_t err)
1445{
1446 // Make sure it is in range
1447 err = (err < kErrError) ? ((err > -1) ? err : 0) : kErrError;
1448
1449 if (gDebug > 0)
1450 ::Error(where, "%s", gRootdErrStr[err]);
1451}
1452
1453////////////////////////////////////////////////////////////////////////////////
1454/// Get total number of bytes sent via all sockets.
1455
1460
1461////////////////////////////////////////////////////////////////////////////////
1462/// Get total number of bytes received via all sockets.
1463
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:533
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:376
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
#define gROOT
Definition TROOT.h:411
TVirtualMutex * gSocketAuthMutex
Definition TSocket.cxx:63
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
ESockOptions
Definition TSystem.h:229
ESendRecvOptions
Definition TSystem.h:242
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD2(mutex)
const char * proto
Definition civetweb.c:18822
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition TBits.h:222
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition TBits.h:206
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()
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:81
Int_t Compress()
Compress the message.
Definition TMessage.cxx:319
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:174
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fName
Definition TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
An array of TObjects.
Definition TObjArray.h:31
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:476
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1058
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:865
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1072
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:876
void ResetBit(UInt_t f)
Definition TObject.h:201
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1046
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:57
Int_t fCompress
Definition TSocket.h:60
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
Definition TSocket.cxx:1005
Int_t fSocket
Definition TSocket.h:67
Int_t GetErrorCode() const
Returns error code.
Definition TSocket.cxx:1027
TVirtualMutex * fLastUsageMtx
Definition TSocket.h:73
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1052
void SendStreamerInfos(const TMessage &mess)
Check if TStreamerInfo must be sent.
Definition TSocket.cxx:641
@ kInvalidStillInList
Definition TSocket.h:55
@ kInvalid
Definition TSocket.h:54
TString fUrl
Definition TSocket.h:69
void SetCompressionAlgorithm(Int_t algorithm=ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1038
TSocket()
Definition TSocket.h:81
static ULong64_t GetSocketBytesSent()
Get total number of bytes sent via all sockets.
Definition TSocket.cxx:1456
TString fService
Definition TSocket.h:65
Bool_t RecvStreamerInfos(TMessage *mess)
Receive a message containing streamer infos.
Definition TSocket.cxx:920
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:810
TList * fUUIDs
Definition TSocket.h:71
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition TSocket.cxx:1436
TBits fBitsInfo
Definition TSocket.h:70
Bool_t Authenticate(const char *user)
Authenticated the socket with specified user.
Definition TSocket.cxx:1098
TInetAddress fLocalAddress
Definition TSocket.h:61
static ULong64_t fgBytesRecv
Definition TSocket.h:76
@ kBrokenConn
Definition TSocket.h:47
virtual void Close(Option_t *opt="")
Close the socket.
Definition TSocket.cxx:381
void MarkBrokenConnection()
Close the socket and mark as due to a broken connection.
Definition TSocket.cxx:363
void Touch()
Definition TSocket.h:155
Bool_t RecvProcessIDs(TMessage *mess)
Receive a message containing process ids.
Definition TSocket.cxx:967
TInetAddress GetInetAddress() const
Definition TSocket.h:111
Int_t GetCompressionLevel() const
Definition TSocket.h:179
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition TSocket.cxx:890
static ULong64_t fgBytesSent
Definition TSocket.h:77
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition TSocket.cxx:612
void SendProcessIDs(const TMessage &mess)
Check if TProcessIDs must be sent.
Definition TSocket.cxx:676
static Int_t fgClientProtocol
Definition TSocket.h:79
virtual TInetAddress GetLocalInetAddress()
Return internet address of local host to which the socket is bound.
Definition TSocket.cxx:401
TSecContext * fSecContext
Definition TSocket.h:63
virtual Int_t Select(Int_t interest=kRead, Long_t timeout=-1)
Waits for this socket to change status.
Definition TSocket.cxx:435
virtual Int_t GetLocalPort()
Return the local port # to which the socket is bound.
Definition TSocket.cxx:415
Int_t fTcpWindowSize
Definition TSocket.h:68
Option_t * GetOption() const override
Definition TSocket.h:96
@ kSOCKD
Definition TSocket.h:50
@ kROOTD
Definition TSocket.h:50
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:1399
static void NetError(const char *where, Int_t error)
Print error string depending on error code.
Definition TSocket.cxx:1444
Int_t GetPort() const
Definition TSocket.h:113
EServiceType fServType
Definition TSocket.h:66
virtual Int_t SendObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Send an object.
Definition TSocket.cxx:592
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Used to specify the compression level and algorithm: settings = 100 * algorithm + level.
Definition TSocket.cxx:1090
UInt_t fBytesSent
Definition TSocket.h:59
Int_t fRemoteProtocol
Definition TSocket.h:62
UInt_t fBytesRecv
Definition TSocket.h:58
virtual Bool_t IsValid() const
Definition TSocket.h:130
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:514
virtual Bool_t IsAuthenticated() const
Definition TSocket.h:129
static ULong64_t GetSocketBytesRecv()
Get total number of bytes received via all sockets.
Definition TSocket.cxx:1464
Describes a persistent version of a class.
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
virtual int GetServiceByName(const char *service)
Get port # of internet service.
Definition TSystem.cxx:2331
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition TSystem.cxx:2322
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:284
virtual char * GetServiceByPort(int port)
Get name of internet service.
Definition TSystem.cxx:2340
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition TSystem.cxx:2449
virtual TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
Definition TSystem.cxx:2313
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition TSystem.cxx:2349
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition TSystem.cxx:2458
virtual int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Definition TSystem.cxx:2412
virtual Int_t Select(TList *active, Long_t timeout)
Select on active file descriptors (called by TMonitor).
Definition TSystem.cxx:445
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition TSystem.cxx:2304
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition TSystem.cxx:2422
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition TSystem.cxx:2403
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition TSystem.cxx:1614
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
This class implements a mutex interface.
const Int_t n
Definition legend1.C:16
Namespace for new ROOT classes and functions.
@ 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:72