Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TUDPSocket.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Marcelo Sousa 26/10/2011
3
4/*************************************************************************
5 * Copyright (C) 1995-2011, 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 TUDPSocket.cxx
14\class TUDPSocket
15\brief This class implements UDP 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#include "Bytes.h"
24#include "Compression.h"
25#define ROOT_NetErrors_cxx
26#include "NetErrors.h"
27#include "TError.h"
28#include "TMessage.h"
29#include "TUDPSocket.h"
30#include "TObjString.h"
31#include "TPluginManager.h"
32#include "TROOT.h"
33#include "TString.h"
34#include "TSystem.h"
35#include "TUrl.h"
36#include "TStreamerInfo.h"
37#include "TProcessID.h"
38
39#include <limits>
40
43
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Create a socket. Connect to the named service at address addr.
48/// Use tcpwindowsize to specify the size of the receive buffer, it has
49/// to be specified here to make sure the window scale option is set (for
50/// tcpwindowsize > 65KB and for platforms supporting window scaling).
51/// Returns when connection has been accepted by remote side. Use IsValid()
52/// to check the validity of the socket. Every socket is added to the TROOT
53/// sockets list which will make sure that any open sockets are properly
54/// closed on program termination.
55
57 : TNamed(addr.GetHostName(), service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
58{
61
65 if (fService.Contains("root"))
67 fAddress = addr;
69 fBytesSent = 0;
70 fBytesRecv = 0;
71 fUUIDs = 0;
72 fLastUsageMtx = 0;
74
75 if (fAddress.GetPort() != -1) {
77 -1, "upd");
78
79 if (fSocket != -1) {
81 gROOT->GetListOfSockets()->Add(this);
82 }
83 } else
84 fSocket = -1;
85
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Create a socket. Connect to the specified port # at address addr.
91/// Use tcpwindowsize to specify the size of the receive buffer, it has
92/// to be specified here to make sure the window scale option is set (for
93/// tcpwindowsize > 65KB and for platforms supporting window scaling).
94/// Returns when connection has been accepted by remote side. Use IsValid()
95/// to check the validity of the socket. Every socket is added to the TROOT
96/// sockets list which will make sure that any open sockets are properly
97/// closed on program termination.
98
100 : TNamed(addr.GetHostName(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
101{
104
106 fRemoteProtocol= -1;
108 if (fService.Contains("root"))
110 fAddress = addr;
113 fBytesSent = 0;
114 fBytesRecv = 0;
115 fUUIDs = 0;
116 fLastUsageMtx = 0;
118
120 -1, "upd");
121 if (fSocket == -1)
122 fAddress.fPort = -1;
123 else {
125 gROOT->GetListOfSockets()->Add(this);
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Create a socket. Connect to named service on the remote host.
131/// Use tcpwindowsize to specify the size of the receive buffer, it has
132/// to be specified here to make sure the window scale option is set (for
133/// tcpwindowsize > 65KB and for platforms supporting window scaling).
134/// Returns when connection has been accepted by remote side. Use IsValid()
135/// to check the validity of the socket. Every socket is added to the TROOT
136/// sockets list which will make sure that any open sockets are properly
137/// closed on program termination.
138
139TUDPSocket::TUDPSocket(const char *host, const char *service)
140 : TNamed(host, service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
141{
144
146 fRemoteProtocol= -1;
148 if (fService.Contains("root"))
153 fBytesSent = 0;
154 fBytesRecv = 0;
155 fUUIDs = 0;
156 fLastUsageMtx = 0;
158
159 if (fAddress.GetPort() != -1) {
161 if (fSocket != -1) {
163 gROOT->GetListOfSockets()->Add(this);
164 }
165 } else
166 fSocket = -1;
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Create a socket; see TSocket constructor.
171
173 : TNamed(TUrl(url).GetHost(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
174{
177
178 fUrl = TString(url);
179 TString host(TUrl(fUrl).GetHost());
180
182 fRemoteProtocol= -1;
184 if (fUrl.Contains("root"))
190 fBytesSent = 0;
191 fBytesRecv = 0;
192 fUUIDs = 0;
193 fLastUsageMtx = 0;
195
197 if (fSocket == -1) {
198 fAddress.fPort = -1;
199 } else {
201 gROOT->GetListOfSockets()->Add(this);
202 }
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Create a socket in the Unix domain on 'sockpath'.
207/// Returns when connection has been accepted by the server. Use IsValid()
208/// to check the validity of the socket. Every socket is added to the TROOT
209/// sockets list which will make sure that any open sockets are properly
210/// closed on program termination.
211
213 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
214{
217
218 fUrl = sockpath;
219
220 fService = "unix";
221 fRemoteProtocol= -1;
223 fAddress.fPort = -1;
224 fName.Form("unix:%s", sockpath);
226 fBytesSent = 0;
227 fBytesRecv = 0;
228 fUUIDs = 0;
229 fLastUsageMtx = 0;
231
232 fSocket = gSystem->OpenConnection(sockpath, -1, -1, "udp");
233 if (fSocket > 0) {
235 gROOT->GetListOfSockets()->Add(this);
236 }
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Create a socket. The socket will adopt previously opened TCP socket with
241/// descriptor desc.
242
243TUDPSocket::TUDPSocket(Int_t desc) : TNamed("", ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
244{
247
248 fRemoteProtocol = 0;
249 fService = (char *)kSOCKD;
251 fBytesSent = 0;
252 fBytesRecv = 0;
253 fUUIDs = 0;
254 fLastUsageMtx = 0;
256
257 if (desc >= 0) {
258 fSocket = desc;
261 gROOT->GetListOfSockets()->Add(this);
262 } else
263 fSocket = -1;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Create a socket. The socket will adopt previously opened Unix socket with
268/// descriptor desc. The sockpath arg is for info purposes only. Use
269/// this method to adopt e.g. a socket created via socketpair().
270
272 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
273{
276
277 fUrl = sockpath;
278
279 fService = "unix";
280 fRemoteProtocol= -1;
282 fAddress.fPort = -1;
283 fName.Form("unix:%s", sockpath);
285 fBytesSent = 0;
286 fBytesRecv = 0;
287 fUUIDs = 0;
288 fLastUsageMtx = 0;
290
291 if (desc >= 0) {
292 fSocket = desc;
294 gROOT->GetListOfSockets()->Add(this);
295 } else
296 fSocket = -1;
297}
298
299
300////////////////////////////////////////////////////////////////////////////////
301/// TUDPSocket copy ctor.
302
304{
305 fSocket = s.fSocket;
306 fService = s.fService;
307 fAddress = s.fAddress;
314 fUUIDs = 0;
315 fLastUsageMtx = 0;
317
318 if (fSocket != -1) {
320 gROOT->GetListOfSockets()->Add(this);
321 }
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Close the socket. If option is "force", calls shutdown(id,2) to
326/// shut down the connection. This will close the connection also
327/// for the parent of this process. Also called via the dtor (without
328/// option "force", call explicitly Close("force") if this is desired).
329
331{
332 Bool_t force = option ? (!strcmp(option, "force") ? kTRUE : kFALSE) : kFALSE;
333
334 if (fSocket != -1) {
337 gROOT->GetListOfSockets()->Remove(this);
338 }
339 fSocket = -1;
340
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Return internet address of local host to which the socket is bound.
347/// In case of error TInetAddress::IsValid() returns kFALSE.
348
350{
351 if (IsValid()) {
352 if (fLocalAddress.GetPort() == -1)
354 return fLocalAddress;
355 }
356 return TInetAddress();
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// Return the local port # to which the socket is bound.
361/// In case of error return -1.
362
364{
365 if (IsValid()) {
366 if (fLocalAddress.GetPort() == -1)
368 return fLocalAddress.GetPort();
369 }
370 return -1;
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Waits for this socket to change status. If interest=kRead,
375/// the socket will be watched to see if characters become available for
376/// reading; if interest=kWrite the socket will be watched to
377/// see if a write will not block.
378/// The argument 'timeout' specifies a maximum time to wait in millisec.
379/// Default no timeout.
380/// Returns 1 if a change of status of interest has been detected within
381/// timeout; 0 in case of timeout; < 0 if an error occurred.
382
384{
385 Int_t rc = 1;
386
387 // Associate a TFileHandler to this socket
389
390 // Wait for an event now
391 rc = gSystem->Select(&fh, timeout);
392
393 return rc;
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Send a single message opcode. Use kind (opcode) to set the
398/// TMessage "what" field. Returns the number of bytes that were sent
399/// (always sizeof(Int_t)) and -1 in case of error. In case the kind has
400/// been or'ed with kMESS_ACK, the call will only return after having
401/// received an acknowledgement, making the sending process synchronous.
402
404{
406
407 Int_t nsent;
408 if ((nsent = Send(mess)) < 0)
409 return -1;
410
411 return nsent;
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Send a status and a single message opcode. Use kind (opcode) to set the
416/// TMessage "what" field. Returns the number of bytes that were sent
417/// (always 2*sizeof(Int_t)) and -1 in case of error. In case the kind has
418/// been or'ed with kMESS_ACK, the call will only return after having
419/// received an acknowledgement, making the sending process synchronous.
420
422{
424 mess << status;
425
426 Int_t nsent;
427 if ((nsent = Send(mess)) < 0)
428 return -1;
429
430 return nsent;
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// Send a character string buffer. Use kind to set the TMessage "what" field.
435/// Returns the number of bytes in the string str that were sent and -1 in
436/// case of error. In case the kind has been or'ed with kMESS_ACK, the call
437/// will only return after having received an acknowledgement, making the
438/// sending process synchronous.
439
441{
443 if (str) mess.WriteString(str);
444
445 Int_t nsent;
446 if ((nsent = Send(mess)) < 0)
447 return -1;
448
449 return nsent - sizeof(Int_t); // - TMessage::What()
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Send a TMessage object. Returns the number of bytes in the TMessage
454/// that were sent and -1 in case of error. In case the TMessage::What
455/// has been or'ed with kMESS_ACK, the call will only return after having
456/// received an acknowledgement, making the sending process synchronous.
457/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
458/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
459/// support for streaming TStreamerInfo added by Rene Brun May 2008
460/// support for streaming TProcessID added by Rene Brun June 2008
461
463{
465
466 if (fSocket == -1) return -1;
467
468 if (mess.IsReading()) {
469 Error("Send", "cannot send a message used for reading");
470 return -1;
471 }
472
473 // send streamer infos in case schema evolution is enabled in the TMessage
475
476 // send the process id's so TRefs work
478
479 mess.SetLength(); //write length in first word of buffer
480
481 if (GetCompressionLevel() > 0 && mess.GetCompressionLevel() == 0)
483
484 if (mess.GetCompressionLevel() > 0)
485 const_cast<TMessage&>(mess).Compress();
486
487 char *mbuf = mess.Buffer();
488 Int_t mlen = mess.Length();
489 if (mess.CompBuffer()) {
490 mbuf = mess.CompBuffer();
491 mlen = mess.CompLength();
492 }
493
495 Int_t nsent;
496 if ((nsent = gSystem->SendRaw(fSocket, mbuf, mlen, 0)) <= 0) {
497 if (nsent == -5) {
498 // Connection reset by peer or broken
500 Close();
501 }
502 return nsent;
503 }
504
505 fBytesSent += nsent;
507
508 // If acknowledgement is desired, wait for it
509 if (mess.What() & kMESS_ACK) {
512 char buf[2];
513 Int_t n = 0;
514 if ((n = gSystem->RecvRaw(fSocket, buf, sizeof(buf), 0)) < 0) {
515 if (n == -5) {
516 // Connection reset by peer or broken
518 Close();
519 } else
520 n = -1;
521 return n;
522 }
523 if (strncmp(buf, "ok", 2)) {
524 Error("Send", "bad acknowledgement");
525 return -1;
526 }
527 fBytesRecv += 2;
528 fgBytesRecv += 2;
529 }
530
531 Touch(); // update usage timestamp
532
533 return nsent - sizeof(UInt_t); //length - length header
534}
535
536////////////////////////////////////////////////////////////////////////////////
537/// Send an object. Returns the number of bytes sent and -1 in case of error.
538/// In case the "kind" has been or'ed with kMESS_ACK, the call will only
539/// return after having received an acknowledgement, making the sending
540/// synchronous.
541
543{
544 //stream object to message buffer
546 mess.WriteObject(obj);
547
548 //now sending the object itself
549 Int_t nsent;
550 if ((nsent = Send(mess)) < 0)
551 return -1;
552
553 return nsent;
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Send a raw buffer of specified length. Using option kOob one can send
558/// OOB data. Returns the number of bytes sent or -1 in case of error.
559/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
560/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
561
563{
565
566 if (fSocket == -1) return -1;
567
569 Int_t nsent;
570 if ((nsent = gSystem->SendRaw(fSocket, buffer, length, (int) opt)) <= 0) {
571 if (nsent == -5) {
572 // Connection reset or broken: close
574 Close();
575 }
576 return nsent;
577 }
578
579 fBytesSent += nsent;
581
582 Touch(); // update usage timestamp
583
584 return nsent;
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Check if TStreamerInfo must be sent. The list of TStreamerInfo of classes
589/// in the object in the message is in the fInfos list of the message.
590/// We send only the TStreamerInfos not yet sent on this socket.
591
593{
594 if (mess.fInfos && mess.fInfos->GetEntries()) {
595 TIter next(mess.fInfos);
597 TList *minilist = 0;
598 while ((info = (TStreamerInfo*)next())) {
599 Int_t uid = info->GetNumber();
600 if (fBitsInfo.TestBitNumber(uid))
601 continue; //TStreamerInfo had already been sent
603 if (!minilist)
604 minilist = new TList();
605 if (gDebug > 0)
606 Info("SendStreamerInfos", "sending TStreamerInfo: %s, version = %d",
607 info->GetName(),info->GetClassVersion());
608 minilist->Add(info);
609 }
610 if (minilist) {
612 messinfo.WriteObject(minilist);
613 delete minilist;
614 if (messinfo.fInfos)
615 messinfo.fInfos->Clear();
616 if (Send(messinfo) < 0)
617 Warning("SendStreamerInfos", "problems sending TStreamerInfo's ...");
618 }
619 }
620}
621
622////////////////////////////////////////////////////////////////////////////////
623/// Check if TProcessIDs must be sent. The list of TProcessIDs
624/// in the object in the message is found by looking in the TMessage bits.
625/// We send only the TProcessIDs not yet send on this socket.
626
628{
629 if (mess.TestBitNumber(0)) {
631 Int_t npids = pids->GetEntries();
633 TList *minilist = 0;
634 for (Int_t ipid = 0; ipid < npids; ipid++) {
635 pid = (TProcessID*)pids->At(ipid);
636 if (!pid || !mess.TestBitNumber(pid->GetUniqueID()+1))
637 continue;
638 //check if a pid with this title has already been sent through the socket
639 //if not add it to the fUUIDs list
640 if (!fUUIDs) {
641 fUUIDs = new TList();
642 } else {
643 if (fUUIDs->FindObject(pid->GetTitle()))
644 continue;
645 }
646 fUUIDs->Add(new TObjString(pid->GetTitle()));
647 if (!minilist)
648 minilist = new TList();
649 if (gDebug > 0)
650 Info("SendProcessIDs", "sending TProcessID: %s", pid->GetTitle());
651 minilist->Add(pid);
652 }
653 if (minilist) {
655 messpid.WriteObject(minilist);
656 delete minilist;
657 if (Send(messpid) < 0)
658 Warning("SendProcessIDs", "problems sending TProcessID's ...");
659 }
660 }
661}
662
663////////////////////////////////////////////////////////////////////////////////
664/// Receive a character string message of maximum max length. The expected
665/// message must be of type kMESS_STRING. Returns length of received string
666/// (can be 0 if otherside of connection is closed) or -1 in case of error
667/// or -4 in case a non-blocking socket would block (i.e. there is nothing
668/// to be read).
669
671{
672 Int_t n, kind;
673
675 if ((n = Recv(str, max, kind)) <= 0) {
676 if (n == -5) {
678 n = -1;
679 }
680 return n;
681 }
682
683 if (kind != kMESS_STRING) {
684 Error("Recv", "got message of wrong kind (expected %d, got %d)",
686 return -1;
687 }
688
689 return n;
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Receive a character string message of maximum max length. Returns in
694/// kind the message type. Returns length of received string+4 (can be 0 if
695/// other side of connection is closed) or -1 in case of error or -4 in
696/// case a non-blocking socket would block (i.e. there is nothing to be read).
697
699{
700 Int_t n;
701 TMessage *mess;
702
704 if ((n = Recv(mess)) <= 0) {
705 if (n == -5) {
707 n = -1;
708 }
709 return n;
710 }
711
712 kind = mess->What();
713 if (str) {
714 if (mess->BufferSize() > (Int_t)sizeof(Int_t)) // if mess contains more than kind
715 mess->ReadString(str, max);
716 else
717 str[0] = 0;
718 }
719
720 delete mess;
721
722 return n; // number of bytes read (len of str + sizeof(kind)
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Receives a status and a message type. Returns length of received
727/// integers, 2*sizeof(Int_t) (can be 0 if other side of connection
728/// is closed) or -1 in case of error or -4 in case a non-blocking
729/// socket would block (i.e. there is nothing to be read).
730
732{
733 Int_t n;
734 TMessage *mess;
735
737 if ((n = Recv(mess)) <= 0) {
738 if (n == -5) {
740 n = -1;
741 }
742 return n;
743 }
744
745 kind = mess->What();
746 (*mess) >> status;
747
748 delete mess;
749
750 return n; // number of bytes read (2 * sizeof(Int_t)
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Receive a TMessage object. The user must delete the TMessage object.
755/// Returns length of message in bytes (can be 0 if other side of connection
756/// is closed) or -1 in case of error or -4 in case a non-blocking socket
757/// would block (i.e. there is nothing to be read) or -5 if pipe broken
758/// or reset by peer (EPIPE || ECONNRESET). In those case mess == 0.
759
761{
763
764 if (fSocket == -1) {
765 mess = 0;
766 return -1;
767 }
768
771 Int_t n;
772 UInt_t len;
773 if ((n = gSystem->RecvRaw(fSocket, &len, sizeof(UInt_t), 0)) <= 0) {
774 if (n == 0 || n == -5) {
775 // Connection closed, reset or broken
777 Close();
778 }
779 mess = 0;
780 return n;
781 }
782 len = net2host(len); //from network to host byte order
783
784 if (len > (std::numeric_limits<decltype(len)>::max() - sizeof(decltype(len)))) {
785 Error("Recv", "Buffer length is %u and %u+sizeof(UInt_t) cannot be represented as an UInt_t.", len, len);
786 return -1;
787 }
788
790 char *buf = new char[len+sizeof(UInt_t)];
791 if ((n = gSystem->RecvRaw(fSocket, buf+sizeof(UInt_t), len, 0)) <= 0) {
792 if (n == 0 || n == -5) {
793 // Connection closed, reset or broken
795 Close();
796 }
797 delete [] buf;
798 mess = 0;
799 return n;
800 }
801
802 fBytesRecv += n + sizeof(UInt_t);
803 fgBytesRecv += n + sizeof(UInt_t);
804
805 mess = new TMessage(buf, len+sizeof(UInt_t));
806
807 // receive any streamer infos
809 goto oncemore;
810
811 // receive any process ids
812 if (RecvProcessIDs(mess))
813 goto oncemore;
814
815 if (mess->What() & kMESS_ACK) {
817 char ok[2] = { 'o', 'k' };
818 Int_t n2 = 0;
819 if ((n2 = gSystem->SendRaw(fSocket, ok, sizeof(ok), 0)) < 0) {
820 if (n2 == -5) {
821 // Connection reset or broken
823 Close();
824 }
825 delete mess;
826 mess = 0;
827 return n2;
828 }
829 mess->SetWhat(mess->What() & ~kMESS_ACK);
830
831 fBytesSent += 2;
832 fgBytesSent += 2;
833 }
834
835 Touch(); // update usage timestamp
836
837 return n;
838}
839
840////////////////////////////////////////////////////////////////////////////////
841/// Receive a raw buffer of specified length bytes. Using option kPeek
842/// one can peek at incoming data. Returns number of received bytes.
843/// Returns -1 in case of error. In case of opt == kOob: -2 means
844/// EWOULDBLOCK and -3 EINVAL. In case of non-blocking mode (kNoBlock)
845/// -4 means EWOULDBLOCK. Returns -5 if pipe broken or reset by
846/// peer (EPIPE || ECONNRESET).
847
849{
851
852 if (fSocket == -1) return -1;
853 if (length == 0) return 0;
854
856 Int_t n;
857 if ((n = gSystem->RecvRaw(fSocket, buffer, length, (int) opt)) <= 0) {
858 if (n == 0 || n == -5) {
859 // Connection closed, reset or broken
861 Close();
862 }
863 return n;
864 }
865
866 fBytesRecv += n;
867 fgBytesRecv += n;
868
869 Touch(); // update usage timestamp
870
871 return n;
872}
873
874////////////////////////////////////////////////////////////////////////////////
875/// Receive a message containing streamer infos. In case the message contains
876/// streamer infos they are imported, the message will be deleted and the
877/// method returns kTRUE.
878
880{
881 if (mess->What() == kMESS_STREAMERINFO) {
882 TList *list = (TList*)mess->ReadObject(TList::Class());
883 TIter next(list);
885 TObjLink *lnk = list->FirstLink();
886 // First call BuildCheck for regular class
887 while (lnk) {
888 info = (TStreamerInfo*)lnk->GetObject();
889 TObject *element = info->GetElements()->UncheckedAt(0);
890 Bool_t isstl = element && strcmp("This",element->GetName())==0;
891 if (!isstl) {
892 info->BuildCheck();
893 if (gDebug > 0)
894 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
895 info->GetName(), info->GetClassVersion());
896 }
897 lnk = lnk->Next();
898 }
899 // Then call BuildCheck for stl class
900 lnk = list->FirstLink();
901 while (lnk) {
902 info = (TStreamerInfo*)lnk->GetObject();
903 TObject *element = info->GetElements()->UncheckedAt(0);
904 Bool_t isstl = element && strcmp("This",element->GetName())==0;
905 if (isstl) {
906 info->BuildCheck();
907 if (gDebug > 0)
908 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
909 info->GetName(), info->GetClassVersion());
910 }
911 lnk = lnk->Next();
912 }
913 delete list;
914 delete mess;
915
916 return kTRUE;
917 }
918 return kFALSE;
919}
920
921////////////////////////////////////////////////////////////////////////////////
922/// Receive a message containing process ids. In case the message contains
923/// process ids they are imported, the message will be deleted and the
924/// method returns kTRUE.
925
927{
928 if (mess->What() == kMESS_PROCESSID) {
929 TList *list = (TList*)mess->ReadObject(TList::Class());
930 TIter next(list);
932 while ((pid = (TProcessID*)next())) {
933 // check that a similar pid is not already registered in fgPIDs
936 TProcessID *p;
937 while ((p = (TProcessID*)nextpid())) {
938 if (!strcmp(p->GetTitle(), pid->GetTitle())) {
939 delete pid;
940 pid = 0;
941 break;
942 }
943 }
944 if (pid) {
945 if (gDebug > 0)
946 Info("RecvProcessIDs", "importing TProcessID: %s", pid->GetTitle());
947 pid->IncrementCount();
948 pidslist->Add(pid);
949 Int_t ind = pidslist->IndexOf(pid);
950 pid->SetUniqueID((UInt_t)ind);
951 }
952 }
953 delete list;
954 delete mess;
955
956 return kTRUE;
957 }
958 return kFALSE;
959}
960
961////////////////////////////////////////////////////////////////////////////////
962/// Set socket options.
963
965{
966 if (fSocket == -1) return -1;
967
968 return gSystem->SetSockOpt(fSocket, opt, val);
969}
970
971////////////////////////////////////////////////////////////////////////////////
972/// Get socket options. Returns -1 in case of error.
973
975{
976 if (fSocket == -1) return -1;
977
978 return gSystem->GetSockOpt(fSocket, opt, &val);
979}
980
981////////////////////////////////////////////////////////////////////////////////
982/// Returns error code. Meaning depends on context where it is called.
983/// If no error condition returns 0 else a value < 0.
984/// For example see TServerSocket ctor.
985
987{
988 if (!IsValid())
989 return fSocket;
990
991 return 0;
992}
993
994////////////////////////////////////////////////////////////////////////////////
995/// See comments for function SetCompressionSettings
996
998{
1000 if (fCompress < 0) {
1001 // if the level is not defined yet use 4 as a default (with ZLIB was 1)
1003 } else {
1004 int level = fCompress % 100;
1005 fCompress = 100 * algorithm + level;
1006 }
1007}
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// See comments for function SetCompressionSettings
1011
1013{
1014 if (level < 0) level = 0;
1015 if (level > 99) level = 99;
1016 if (fCompress < 0) {
1017 // if the algorithm is not defined yet use 0 as a default
1018 fCompress = level;
1019 } else {
1020 int algorithm = fCompress / 100;
1022 fCompress = 100 * algorithm + level;
1023 }
1024}
1025
1026////////////////////////////////////////////////////////////////////////////////
1027/// Used to specify the compression level and algorithm:
1028/// settings = 100 * algorithm + level
1029///
1030/// level = 0, objects written to this file will not be compressed.
1031/// level = 1, minimal compression level but fast.
1032/// ....
1033/// level = 9, maximal compression level but slower and might use more memory.
1034/// (For the currently supported algorithms, the maximum level is 9)
1035/// If compress is negative it indicates the compression level is not set yet.
1036///
1037/// The enumeration ROOT::RCompressionSetting::EAlgorithm associates each
1038/// algorithm with a number. There is a utility function to help
1039/// to set the value of the argument. For example,
1040/// ROOT::CompressionSettings(ROOT::kLZMA, 1)
1041/// will build an integer which will set the compression to use
1042/// the LZMA algorithm and compression level 1. These are defined
1043/// in the header file Compression.h.
1044///
1045/// Note that the compression settings may be changed at any time.
1046/// The new compression settings will only apply to branches created
1047/// or attached after the setting is changed and other objects written
1048/// after the setting is changed.
1049
1054
1055////////////////////////////////////////////////////////////////////////////////
1056/// Print error string depending on error code.
1057
1059{
1060 // Make sure it is in range
1061 err = (err < kErrError) ? ((err > -1) ? err : 0) : kErrError;
1062
1063 if (gDebug > 0)
1064 ::Error(where, "%s", gRootdErrStr[err]);
1065}
1066
1067////////////////////////////////////////////////////////////////////////////////
1068/// Get total number of bytes sent via all sockets.
1069
1074
1075////////////////////////////////////////////////////////////////////////////////
1076/// Get total number of bytes received via all sockets.
1077
UShort_t net2host(UShort_t x)
Definition Bytes.h:561
@ kMESS_STRING
@ kMESS_ACK
@ kMESS_PROCESSID
@ kMESS_STREAMERINFO
R__EXTERN const char * gRootdErrStr[]
Definition NetErrors.h:76
@ kErrError
Definition NetErrors.h:73
#define SafeDelete(p)
Definition RConfig.hxx:507
char * host
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:85
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
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:130
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:792
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
ESockOptions
Definition TSystem.h:229
ESendRecvOptions
Definition TSystem.h:242
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define R__LOCKGUARD(mutex)
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition TBits.h:222
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition TBits.h:206
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
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
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
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:1070
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition TProcessID.h:74
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
Describes a persistent version of a class.
Basic string class.
Definition TString.h:137
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
virtual int GetServiceByName(const char *service)
Get port # of internet service.
Definition TSystem.cxx:2339
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition TSystem.cxx:2330
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:287
virtual char * GetServiceByPort(int port)
Get name of internet service.
Definition TSystem.cxx:2348
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition TSystem.cxx:2457
virtual TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
Definition TSystem.cxx:2321
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition TSystem.cxx:2357
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition TSystem.cxx:2466
virtual int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Definition TSystem.cxx:2420
virtual Int_t Select(TList *active, Long_t timeout)
Select on active file descriptors (called by TMonitor).
Definition TSystem.cxx:448
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition TSystem.cxx:2312
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition TSystem.cxx:2430
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition TSystem.cxx:2411
This class implements UDP client sockets.
Definition TUDPSocket.h:35
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Used to specify the compression level and algorithm: settings = 100 * algorithm + level.
UInt_t fBytesRecv
Definition TUDPSocket.h:48
Int_t GetErrorCode() const
Returns error code.
UInt_t fBytesSent
Definition TUDPSocket.h:49
Int_t fCompress
Definition TUDPSocket.h:50
Bool_t RecvStreamerInfos(TMessage *mess)
Receive a message containing streamer infos.
virtual TInetAddress GetLocalInetAddress()
Return internet address of local host to which the socket is bound.
EServiceType fServType
Definition TUDPSocket.h:54
TInetAddress fLocalAddress
Definition TUDPSocket.h:51
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
TVirtualMutex * fLastUsageMtx
Definition TUDPSocket.h:60
virtual Int_t GetLocalPort()
Return the local port # to which the socket is bound.
TInetAddress fAddress
Definition TUDPSocket.h:47
TString fService
Definition TUDPSocket.h:53
static ULong64_t fgBytesRecv
Definition TUDPSocket.h:63
Bool_t RecvProcessIDs(TMessage *mess)
Receive a message containing process ids.
virtual Bool_t IsValid() const
Definition TUDPSocket.h:114
Int_t fRemoteProtocol
Definition TUDPSocket.h:52
static void NetError(const char *where, Int_t error)
Print error string depending on error code.
void SetCompressionAlgorithm(Int_t algorithm=ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
See comments for function SetCompressionSettings.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
virtual void Close(Option_t *opt="")
Close the socket.
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
static ULong64_t fgBytesSent
Definition TUDPSocket.h:64
Int_t GetCompressionLevel() const
Definition TUDPSocket.h:155
void SendStreamerInfos(const TMessage &mess)
Check if TStreamerInfo must be sent.
virtual Int_t SendObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Send an object.
TList * fUUIDs
Definition TUDPSocket.h:58
void Touch()
Definition TUDPSocket.h:138
TBits fBitsInfo
Definition TUDPSocket.h:57
static ULong64_t GetSocketBytesRecv()
Get total number of bytes received via all sockets.
TString fUrl
Definition TUDPSocket.h:56
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Option_t * GetOption() const override
Definition TUDPSocket.h:79
static ULong64_t GetSocketBytesSent()
Get total number of bytes sent via all sockets.
Int_t fSocket
Definition TUDPSocket.h:55
virtual Int_t Select(Int_t interest=kRead, Long_t timeout=-1)
Waits for this socket to change status.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
void SendProcessIDs(const TMessage &mess)
Check if TProcessIDs must be sent.
This class represents a WWW compatible URL.
Definition TUrl.h:33
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