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 occured.
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 == 0.
808
810{
812
813 if (!IsValid()) {
814 mess = 0;
815 return -1;
816 }
817
820 Int_t n;
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 = 0;
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 = 0;
841 return n;
842 }
843
844 fBytesRecv += n + sizeof(UInt_t);
845 fgBytesRecv += n + sizeof(UInt_t);
846
847 mess = new TMessage(buf, len+sizeof(UInt_t));
848
849 // receive any streamer infos
851 goto oncemore;
852
853 // receive any process ids
854 if (RecvProcessIDs(mess))
855 goto oncemore;
856
857 if (mess->What() & kMESS_ACK) {
859 char ok[2] = { 'o', 'k' };
860 Int_t n2 = 0;
861 if ((n2 = gSystem->SendRaw(fSocket, ok, sizeof(ok), 0)) < 0) {
862 if (n2 == -5) {
863 // Connection reset or broken
865 }
866 delete mess;
867 mess = 0;
868 return n2;
869 }
870 mess->SetWhat(mess->What() & ~kMESS_ACK);
871
872 fBytesSent += 2;
873 fgBytesSent += 2;
874 }
875
876 Touch(); // update usage timestamp
877
878 return n;
879}
880
881////////////////////////////////////////////////////////////////////////////////
882/// Receive a raw buffer of specified length bytes. Using option kPeek
883/// one can peek at incoming data. Returns number of received bytes.
884/// Returns -1 in case of error. In case of opt == kOob: -2 means
885/// EWOULDBLOCK and -3 EINVAL. In case of non-blocking mode (kNoBlock)
886/// -4 means EWOULDBLOCK. Returns -5 if pipe broken or reset by
887/// peer (EPIPE || ECONNRESET).
888
890{
892
893 if (!IsValid()) return -1;
894 if (length == 0) return 0;
895
897 Int_t n;
898 if ((n = gSystem->RecvRaw(fSocket, buffer, length, (int) opt)) <= 0) {
899 if (n == 0 || n == -5) {
900 // Connection closed, reset or broken
902 }
903 return n;
904 }
905
906 fBytesRecv += n;
907 fgBytesRecv += n;
908
909 Touch(); // update usage timestamp
910
911 return n;
912}
913
914////////////////////////////////////////////////////////////////////////////////
915/// Receive a message containing streamer infos. In case the message contains
916/// streamer infos they are imported, the message will be deleted and the
917/// method returns kTRUE.
918
920{
921 if (mess->What() == kMESS_STREAMERINFO) {
922 TList *list = (TList*)mess->ReadObject(TList::Class());
923 TIter next(list);
925 TObjLink *lnk = list->FirstLink();
926 // First call BuildCheck for regular class
927 while (lnk) {
928 info = (TStreamerInfo*)lnk->GetObject();
929 TObject *element = info->GetElements()->UncheckedAt(0);
930 Bool_t isstl = element && strcmp("This",element->GetName())==0;
931 if (!isstl) {
932 info->BuildCheck();
933 if (gDebug > 0)
934 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
935 info->GetName(), info->GetClassVersion());
936 }
937 lnk = lnk->Next();
938 }
939 // Then call BuildCheck for stl class
940 lnk = list->FirstLink();
941 while (lnk) {
942 info = (TStreamerInfo*)lnk->GetObject();
943 TObject *element = info->GetElements()->UncheckedAt(0);
944 Bool_t isstl = element && strcmp("This",element->GetName())==0;
945 if (isstl) {
946 info->BuildCheck();
947 if (gDebug > 0)
948 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
949 info->GetName(), info->GetClassVersion());
950 }
951 lnk = lnk->Next();
952 }
953 delete list;
954 delete mess;
955
956 return kTRUE;
957 }
958 return kFALSE;
959}
960
961////////////////////////////////////////////////////////////////////////////////
962/// Receive a message containing process ids. In case the message contains
963/// process ids they are imported, the message will be deleted and the
964/// method returns kTRUE.
965
967{
968 if (mess->What() == kMESS_PROCESSID) {
969 TList *list = (TList*)mess->ReadObject(TList::Class());
970 TIter next(list);
971 TProcessID *pid;
972 while ((pid = (TProcessID*)next())) {
973 // check that a similar pid is not already registered in fgPIDs
976 TProcessID *p;
977 while ((p = (TProcessID*)nextpid())) {
978 if (!strcmp(p->GetTitle(), pid->GetTitle())) {
979 delete pid;
980 pid = 0;
981 break;
982 }
983 }
984 if (pid) {
985 if (gDebug > 0)
986 Info("RecvProcessIDs", "importing TProcessID: %s", pid->GetTitle());
987 pid->IncrementCount();
988 pidslist->Add(pid);
989 Int_t ind = pidslist->IndexOf(pid);
990 pid->SetUniqueID((UInt_t)ind);
991 }
992 }
993 delete list;
994 delete mess;
995
996 return kTRUE;
997 }
998 return kFALSE;
999}
1000
1001////////////////////////////////////////////////////////////////////////////////
1002/// Set socket options.
1003
1005{
1006 if (!IsValid()) return -1;
1007
1008 return gSystem->SetSockOpt(fSocket, opt, val);
1009}
1010
1011////////////////////////////////////////////////////////////////////////////////
1012/// Get socket options. Returns -1 in case of error.
1013
1015{
1016 if (!IsValid()) return -1;
1017
1018 return gSystem->GetSockOpt(fSocket, opt, &val);
1019}
1020
1021////////////////////////////////////////////////////////////////////////////////
1022/// Returns error code. Meaning depends on context where it is called.
1023/// If no error condition returns 0 else a value < 0.
1024/// For example see TServerSocket ctor.
1025
1027{
1028 if (!IsValid())
1029 return fSocket;
1030
1031 return 0;
1032}
1033
1034////////////////////////////////////////////////////////////////////////////////
1035/// See comments for function SetCompressionSettings
1036
1047
1048////////////////////////////////////////////////////////////////////////////////
1049/// See comments for function SetCompressionSettings
1050
1052{
1053 if (level < 0) level = 0;
1054 if (level > 99) level = 99;
1055 if (fCompress < 0) {
1056 // if the algorithm is not defined yet use 0 as a default
1057 fCompress = level;
1058 } else {
1059 int algorithm = fCompress / 100;
1061 fCompress = 100 * algorithm + level;
1062 }
1063}
1064
1065////////////////////////////////////////////////////////////////////////////////
1066/// Used to specify the compression level and algorithm:
1067/// settings = 100 * algorithm + level
1068///
1069/// level = 0, objects written to this file will not be compressed.
1070/// level = 1, minimal compression level but fast.
1071/// ....
1072/// level = 9, maximal compression level but slower and might use more memory.
1073/// (For the currently supported algorithms, the maximum level is 9)
1074/// If compress is negative it indicates the compression level is not set yet.
1075///
1076/// The enumeration ROOT::RCompressionSetting::EAlgorithm associates each
1077/// algorithm with a number. There is a utility function to help
1078/// to set the value of the argument. For example,
1079/// ROOT::CompressionSettings(ROOT::kLZMA, 1)
1080/// will build an integer which will set the compression to use
1081/// the LZMA algorithm and compression level 1. These are defined
1082/// in the header file Compression.h.
1083///
1084/// Note that the compression settings may be changed at any time.
1085/// The new compression settings will only apply to branches created
1086/// or attached after the setting is changed and other objects written
1087/// after the setting is changed.
1088
1093
1094////////////////////////////////////////////////////////////////////////////////
1095/// Authenticated the socket with specified user.
1096
1098{
1099 Bool_t rc = kFALSE;
1100
1101 // Parse protocol name
1103 if (sproto.Contains("sockd")) {
1104 fServType = kSOCKD;
1105 } else if (sproto.Contains("rootd")) {
1106 fServType = kROOTD;
1107 }
1108 if (gDebug > 2)
1109 Info("Authenticate","Local protocol: %s",sproto.Data());
1110
1111 // Get server protocol level
1112 Int_t kind = kROOTD_PROTOCOL;
1113 // Warning: for backward compatibility reasons here we have to
1114 // send exactly 4 bytes: for fgClientClientProtocol > 99
1115 // the space in the format must be dropped
1116 if (fRemoteProtocol == -1) {
1117 if (Send(Form(" %d", fgClientProtocol), kROOTD_PROTOCOL) < 0) {
1118 return rc;
1119 }
1120 if (Recv(fRemoteProtocol, kind) < 0) {
1121 return rc;
1122 }
1123 //
1124 // If we are talking to an old rootd server we get a fatal
1125 // error here and we need to reopen the connection,
1126 // communicating first the size of the parallel socket
1127 if (kind == kROOTD_ERR) {
1128 fRemoteProtocol = 9;
1129 return kFALSE;
1130 }
1131 }
1132
1133 // Find out whether authentication is required
1135 if (fRemoteProtocol > 1000) {
1136 // Authentication not required by the remote server
1137 runauth = kFALSE;
1138 fRemoteProtocol %= 1000;
1139 }
1140
1141 // If authentication is required, we need to find out which library
1142 // has to be loaded (preparation for near future, 9/7/05)
1144 if (runauth) {
1145
1146 // Default (future)
1147 TString alib = "Xrd";
1148 if (fRemoteProtocol < 100) {
1149 // Standard Authentication lib
1150 alib = "Root";
1151 }
1152
1153 // Load the plugin
1154 TPluginHandler *h =
1155 gROOT->GetPluginManager()->FindHandler("TVirtualAuth", alib);
1156 if (!h || h->LoadPlugin() != 0) {
1157 Error("Authenticate",
1158 "could not load properly %s authentication plugin", alib.Data());
1159 return rc;
1160 }
1161
1162 // Get an instance of the interface class
1163 TVirtualAuth *auth = (TVirtualAuth *)(h->ExecPlugin(0));
1164 if (!auth) {
1165 Error("Authenticate", "could not instantiate the interface class");
1166 return rc;
1167 }
1168 if (gDebug > 1)
1169 Info("Authenticate", "class for '%s' authentication loaded", alib.Data());
1170
1171 Option_t *opts = "";
1172 if (!(auth->Authenticate(this, host, user, opts))) {
1173 Error("Authenticate",
1174 "authentication attempt failed for %s@%s", user, host.Data());
1175 } else {
1176 rc = kTRUE;
1177 }
1178 } else {
1179
1180 // Communicate who we are and our target user
1182 if (u) {
1183 if (Send(Form("%s %s", u->fUser.Data(), user), kROOTD_USER) < 0)
1184 Warning("Authenticate", "problem sending kROOTD_USER (%s,%s)", u->fUser.Data(), user);
1185 delete u;
1186 } else
1187 if (Send(Form("-1 %s", user), kROOTD_USER) < 0)
1188 Warning("Authenticate", "problem sending kROOTD_USER (-1,%s)", user);
1189
1190 rc = kFALSE;
1191
1192 // Receive confirmation that everything went well
1193 Int_t stat;
1194 if (Recv(stat, kind) > 0) {
1195
1196 if (kind == kROOTD_ERR) {
1197 if (gDebug > 0)
1198 TSocket::NetError("TSocket::Authenticate", stat);
1199 } else if (kind == kROOTD_AUTH) {
1200
1201 // Authentication was not required: create inactive
1202 // security context for consistency
1203 fSecContext = new TSecContext(user, host, 0, -4, 0, 0);
1204 if (gDebug > 3)
1205 Info("Authenticate", "no authentication required remotely");
1206
1207 // Set return flag;
1208 rc = 1;
1209 } else {
1210 if (gDebug > 0)
1211 Info("Authenticate", "expected message type %d, received %d",
1212 kROOTD_AUTH, kind);
1213 }
1214 } else {
1215 if (gDebug > 0)
1216 Info("Authenticate", "error receiving message");
1217 }
1218
1219 }
1220
1221 return rc;
1222}
1223
1224////////////////////////////////////////////////////////////////////////////////
1225/// Creates a socket or a parallel socket and authenticates to the
1226/// remote server.
1227///
1228/// url: [[proto][p][auth]://][user@]host[:port][/service]
1229///
1230/// where proto = "sockd", "rootd"
1231/// indicates the type of remote server;
1232/// if missing "sockd" is assumed ("sockd" indicates
1233/// any remote server session using TServerSocket)
1234/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1235/// [port] = is the remote port number
1236/// [service] = service name used to determine the port
1237/// (for backward compatibility, specification of
1238/// port as priority)
1239///
1240/// An already opened connection can be used by passing its socket
1241/// in opensock.
1242///
1243/// If 'err' is defined, '*err' on return from a failed call contains an error
1244/// code (see NetErrors.h).
1245///
1246/// Example:
1247///
1248/// TSocket::CreateAuthSocket("pk://qwerty@machine.fq.dn:5052",3)
1249///
1250/// creates an authenticated parallel socket of size 3 to a sockd
1251/// server running on remote machine machine.fq.dn on port 5052;
1252/// authentication will attempt protocol Kerberos first.
1253///
1254/// NB: may hang if the remote server is not of the correct type;
1255/// at present TSocket has no way to find out the type of the
1256/// remote server automatically
1257///
1258/// Returns pointer to an authenticated socket or 0 if creation or
1259/// authentication is unsuccessful.
1260
1262 TSocket *opensock, Int_t *err)
1263{
1265
1266 // Url to be passed to chosen constructor
1267 TString eurl(url);
1268
1269 // Parse protocol, if any
1271 TString proto(TUrl(url).GetProtocol());
1273
1274 // Get rid of authentication suffix
1275 TString asfx = "";
1276 if (proto.EndsWith("up") || proto.EndsWith("ug")) {
1277 asfx = proto;
1278 asfx.Remove(0,proto.Length()-2);
1279 proto.Resize(proto.Length()-2);
1280 } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
1281 proto.EndsWith("g") || proto.EndsWith("h")) {
1282 asfx = proto;
1283 asfx.Remove(0,proto.Length()-1);
1284 proto.Resize(proto.Length()-1);
1285 }
1286
1287 // Find out if parallel (force if rootd)
1288 if ((proto.EndsWith("p") || size > 1) ||
1289 proto.BeginsWith("root") ) {
1290 parallel = kTRUE;
1291 if (proto.EndsWith("p"))
1292 proto.Resize(proto.Length()-1);
1293 }
1294
1295 // Force "sockd" if the rest is not recognized
1296 if (!proto.BeginsWith("sock") &&
1297 !proto.BeginsWith("root"))
1298 proto = "sockd";
1299
1300 // Substitute this for original proto in eurl
1301 protosave += "://";
1302 proto += asfx;
1303 proto += "://";
1304 eurl.ReplaceAll(protosave,proto);
1305
1306 // Create the socket now
1307
1308 TSocket *sock = 0;
1309 if (!parallel) {
1310
1311 // Simple socket
1312 if (opensock && opensock->IsValid())
1313 sock = opensock;
1314 else
1315 sock = new TSocket(eurl, TUrl(url).GetPort(), tcpwindowsize);
1316
1317 // Authenticate now
1318 if (sock && sock->IsValid()) {
1319 if (!sock->Authenticate(TUrl(url).GetUser())) {
1320 // Nothing to do except setting the error code (if required) and sock to NULL
1321 if (err) {
1322 *err = (Int_t)kErrAuthNotOK;
1324 }
1325 sock->Close();
1326 delete sock;
1327 sock = 0;
1328 }
1329 }
1330
1331 } else {
1332
1333 // Tell TPSocket that we want authentication, which has to
1334 // be done using the original socket before creation of set
1335 // of parallel sockets
1336 if (eurl.Contains("?"))
1337 eurl.Resize(eurl.Index("?"));
1338 eurl += "?A";
1339
1340 // Parallel socket
1341 if (opensock && opensock->IsValid())
1342 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, opensock);
1343 else
1344 sock = new TPSocket(eurl, TUrl(url).GetPort(), size, tcpwindowsize);
1345
1346 // Cleanup if failure ...
1347 if (sock && !sock->IsAuthenticated()) {
1348 // Nothing to do except setting the error code (if required) and sock to NULL
1349 if (err) {
1350 *err = (Int_t)kErrAuthNotOK;
1352 }
1353 if (sock->IsValid())
1354 // And except when the sock is valid; this typically
1355 // happens when talking to a old server, because the
1356 // the parallel socket system is open before authentication
1357 delete sock;
1358 sock = 0;
1359 }
1360 }
1361
1362 return sock;
1363}
1364
1365////////////////////////////////////////////////////////////////////////////////
1366/// Creates a socket or a parallel socket and authenticates to the
1367/// remote server specified in 'url' on remote 'port' as 'user'.
1368///
1369/// url: [[proto][auth]://]host
1370///
1371/// where proto = "sockd", "rootd"
1372/// indicates the type of remote server
1373/// if missing "sockd" is assumed ("sockd" indicates
1374/// any remote server session using TServerSocket)
1375/// [auth] = "up" or "k" to force UsrPwd or Krb5 authentication
1376///
1377/// An already opened connection can be used by passing its socket
1378/// in opensock.
1379///
1380/// If 'err' is defined, '*err' on return from a failed call contains an error
1381/// code (see NetErrors.h).
1382///
1383/// Example:
1384///
1385/// TSocket::CreateAuthSocket("qwerty","pk://machine.fq.dn:5052",3)
1386///
1387/// creates an authenticated parallel socket of size 3 to a sockd
1388/// server running on remote machine machine.fq.dn on port 5052;
1389/// authentication will attempt protocol Kerberos first.
1390///
1391/// NB: may hang if the remote server is not of the correct type;
1392/// at present TSocket has no way to find out the type of the
1393/// remote server automatically
1394///
1395/// Returns pointer to an authenticated socket or 0 if creation or
1396/// authentication is unsuccessful.
1397
1398TSocket *TSocket::CreateAuthSocket(const char *user, const char *url,
1400 TSocket *opensock, Int_t *err)
1401{
1403
1404 // Extended url to be passed to base call
1405 TString eurl;
1406
1407 // Add protocol, if any
1408 if (TString(TUrl(url).GetProtocol()).Length() > 0) {
1409 eurl += TString(TUrl(url).GetProtocol());
1410 eurl += TString("://");
1411 }
1412 // Add user, if any
1413 if (!user || strlen(user) > 0) {
1414 eurl += TString(user);
1415 eurl += TString("@");
1416 }
1417 // Add host
1418 eurl += TString(TUrl(url).GetHost());
1419 // Add port
1420 eurl += TString(":");
1421 eurl += (port > 0 ? port : 0);
1422 // Add options, if any
1423 if (TString(TUrl(url).GetOptions()).Length() > 0) {
1424 eurl += TString("/?");
1425 eurl += TString(TUrl(url).GetOptions());
1426 }
1427
1428 // Create the socket and return it
1430}
1431
1432////////////////////////////////////////////////////////////////////////////////
1433/// Static method returning supported client protocol.
1434
1439
1440////////////////////////////////////////////////////////////////////////////////
1441/// Print error string depending on error code.
1442
1443void TSocket::NetError(const char *where, Int_t err)
1444{
1445 // Make sure it is in range
1446 err = (err < kErrError) ? ((err > -1) ? err : 0) : kErrError;
1447
1448 if (gDebug > 0)
1449 ::Error(where, "%s", gRootdErrStr[err]);
1450}
1451
1452////////////////////////////////////////////////////////////////////////////////
1453/// Get total number of bytes sent via all sockets.
1454
1459
1460////////////////////////////////////////////////////////////////////////////////
1461/// Get total number of bytes received via all sockets.
1462
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
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:2495
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:575
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: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:475
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:875
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:1045
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:1004
Int_t fSocket
Definition TSocket.h:67
Int_t GetErrorCode() const
Returns error code.
Definition TSocket.cxx:1026
TVirtualMutex * fLastUsageMtx
Definition TSocket.h:73
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1051
void SendStreamerInfos(const TMessage &mess)
Check if TStreamerInfo must be sent.
Definition TSocket.cxx:640
@ 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:1037
TSocket()
Definition TSocket.h:81
static ULong64_t GetSocketBytesSent()
Get total number of bytes sent via all sockets.
Definition TSocket.cxx:1455
TString fService
Definition TSocket.h:65
Bool_t RecvStreamerInfos(TMessage *mess)
Receive a message containing streamer infos.
Definition TSocket.cxx:919
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:809
TList * fUUIDs
Definition TSocket.h:71
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition TSocket.cxx:1435
TBits fBitsInfo
Definition TSocket.h:70
Bool_t Authenticate(const char *user)
Authenticated the socket with specified user.
Definition TSocket.cxx:1097
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:380
void MarkBrokenConnection()
Close the socket and mark as due to a broken connection.
Definition TSocket.cxx:362
void Touch()
Definition TSocket.h:155
Bool_t RecvProcessIDs(TMessage *mess)
Receive a message containing process ids.
Definition TSocket.cxx:966
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:889
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:611
void SendProcessIDs(const TMessage &mess)
Check if TProcessIDs must be sent.
Definition TSocket.cxx:675
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:400
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: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: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:1398
static void NetError(const char *where, Int_t error)
Print error string depending on error code.
Definition TSocket.cxx:1443
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: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:1089
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:513
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:1463
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:640
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