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