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