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