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#include "NetErrors.h"
26#include "TError.h"
27#include "TMessage.h"
28#include "TUDPSocket.h"
29#include "TObjString.h"
30#include "TPluginManager.h"
31#include "TROOT.h"
32#include "TString.h"
33#include "TSystem.h"
34#include "TUrl.h"
35#include "TStreamerInfo.h"
36#include "TProcessID.h"
37
38#include <limits>
39
42
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Create a socket. Connect to the named service at address addr.
47/// Use tcpwindowsize to specify the size of the receive buffer, it has
48/// to be specified here to make sure the window scale option is set (for
49/// tcpwindowsize > 65KB and for platforms supporting window scaling).
50/// Returns when connection has been accepted by remote side. Use IsValid()
51/// to check the validity of the socket. Every socket is added to the TROOT
52/// sockets list which will make sure that any open sockets are properly
53/// closed on program termination.
54
56 : TNamed(addr.GetHostName(), service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
57{
60
64 if (fService.Contains("root"))
66 fAddress = addr;
68 fBytesSent = 0;
69 fBytesRecv = 0;
70 fUUIDs = 0;
71 fLastUsageMtx = 0;
73
74 if (fAddress.GetPort() != -1) {
76 -1, "upd");
77
78 if (fSocket != -1) {
80 gROOT->GetListOfSockets()->Add(this);
81 }
82 } else
83 fSocket = -1;
84
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Create a socket. Connect to the specified port # at address addr.
90/// Use tcpwindowsize to specify the size of the receive buffer, it has
91/// to be specified here to make sure the window scale option is set (for
92/// tcpwindowsize > 65KB and for platforms supporting window scaling).
93/// Returns when connection has been accepted by remote side. Use IsValid()
94/// to check the validity of the socket. Every socket is added to the TROOT
95/// sockets list which will make sure that any open sockets are properly
96/// closed on program termination.
97
99 : TNamed(addr.GetHostName(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
100{
103
105 fRemoteProtocol= -1;
107 if (fService.Contains("root"))
109 fAddress = addr;
110 fAddress.fPort = port;
112 fBytesSent = 0;
113 fBytesRecv = 0;
114 fUUIDs = 0;
115 fLastUsageMtx = 0;
117
119 -1, "upd");
120 if (fSocket == -1)
121 fAddress.fPort = -1;
122 else {
124 gROOT->GetListOfSockets()->Add(this);
125 }
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Create a socket. Connect to named service on the remote host.
130/// Use tcpwindowsize to specify the size of the receive buffer, it has
131/// to be specified here to make sure the window scale option is set (for
132/// tcpwindowsize > 65KB and for platforms supporting window scaling).
133/// Returns when connection has been accepted by remote side. Use IsValid()
134/// to check the validity of the socket. Every socket is added to the TROOT
135/// sockets list which will make sure that any open sockets are properly
136/// closed on program termination.
137
138TUDPSocket::TUDPSocket(const char *host, const char *service)
139 : TNamed(host, service), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
140{
143
145 fRemoteProtocol= -1;
147 if (fService.Contains("root"))
152 fBytesSent = 0;
153 fBytesRecv = 0;
154 fUUIDs = 0;
155 fLastUsageMtx = 0;
157
158 if (fAddress.GetPort() != -1) {
159 fSocket = gSystem->OpenConnection(host, fAddress.GetPort(), -1, "upd");
160 if (fSocket != -1) {
162 gROOT->GetListOfSockets()->Add(this);
163 }
164 } else
165 fSocket = -1;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Create a socket; see TSocket constructor.
170
172 : TNamed(TUrl(url).GetHost(), ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
173{
176
177 fUrl = TString(url);
178 TString host(TUrl(fUrl).GetHost());
179
181 fRemoteProtocol= -1;
183 if (fUrl.Contains("root"))
186 fAddress.fPort = port;
189 fBytesSent = 0;
190 fBytesRecv = 0;
191 fUUIDs = 0;
192 fLastUsageMtx = 0;
194
195 fSocket = gSystem->OpenConnection(host, fAddress.GetPort(), -1, "udp");
196 if (fSocket == -1) {
197 fAddress.fPort = -1;
198 } else {
200 gROOT->GetListOfSockets()->Add(this);
201 }
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Create a socket in the Unix domain on 'sockpath'.
206/// Returns when connection has been accepted by the server. Use IsValid()
207/// to check the validity of the socket. Every socket is added to the TROOT
208/// sockets list which will make sure that any open sockets are properly
209/// closed on program termination.
210
212 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
213{
216
217 fUrl = sockpath;
218
219 fService = "unix";
220 fRemoteProtocol= -1;
222 fAddress.fPort = -1;
223 fName.Form("unix:%s", sockpath);
225 fBytesSent = 0;
226 fBytesRecv = 0;
227 fUUIDs = 0;
228 fLastUsageMtx = 0;
230
231 fSocket = gSystem->OpenConnection(sockpath, -1, -1, "udp");
232 if (fSocket > 0) {
234 gROOT->GetListOfSockets()->Add(this);
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Create a socket. The socket will adopt previously opened TCP socket with
240/// descriptor desc.
241
242TUDPSocket::TUDPSocket(Int_t desc) : TNamed("", ""), fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
243{
246
247 fRemoteProtocol = 0;
248 fService = (char *)kSOCKD;
250 fBytesSent = 0;
251 fBytesRecv = 0;
252 fUUIDs = 0;
253 fLastUsageMtx = 0;
255
256 if (desc >= 0) {
257 fSocket = desc;
260 gROOT->GetListOfSockets()->Add(this);
261 } else
262 fSocket = -1;
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Create a socket. The socket will adopt previously opened Unix socket with
267/// descriptor desc. The sockpath arg is for info purposes only. Use
268/// this method to adopt e.g. a socket created via socketpair().
269
271 fCompress(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
272{
275
276 fUrl = sockpath;
277
278 fService = "unix";
279 fRemoteProtocol= -1;
281 fAddress.fPort = -1;
282 fName.Form("unix:%s", sockpath);
284 fBytesSent = 0;
285 fBytesRecv = 0;
286 fUUIDs = 0;
287 fLastUsageMtx = 0;
289
290 if (desc >= 0) {
291 fSocket = desc;
293 gROOT->GetListOfSockets()->Add(this);
294 } else
295 fSocket = -1;
296}
297
298
299////////////////////////////////////////////////////////////////////////////////
300/// TUDPSocket copy ctor.
301
303{
304 fSocket = s.fSocket;
305 fService = s.fService;
306 fAddress = s.fAddress;
313 fUUIDs = 0;
314 fLastUsageMtx = 0;
316
317 if (fSocket != -1) {
319 gROOT->GetListOfSockets()->Add(this);
320 }
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// Close the socket. If option is "force", calls shutdown(id,2) to
325/// shut down the connection. This will close the connection also
326/// for the parent of this process. Also called via the dtor (without
327/// option "force", call explicitly Close("force") if this is desired).
328
330{
331 Bool_t force = option ? (!strcmp(option, "force") ? kTRUE : kFALSE) : kFALSE;
332
333 if (fSocket != -1) {
336 gROOT->GetListOfSockets()->Remove(this);
337 }
338 fSocket = -1;
339
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Return internet address of local host to which the socket is bound.
346/// In case of error TInetAddress::IsValid() returns kFALSE.
347
349{
350 if (IsValid()) {
351 if (fLocalAddress.GetPort() == -1)
353 return fLocalAddress;
354 }
355 return TInetAddress();
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Return the local port # to which the socket is bound.
360/// In case of error return -1.
361
363{
364 if (IsValid()) {
365 if (fLocalAddress.GetPort() == -1)
367 return fLocalAddress.GetPort();
368 }
369 return -1;
370}
371
372////////////////////////////////////////////////////////////////////////////////
373/// Waits for this socket to change status. If interest=kRead,
374/// the socket will be watched to see if characters become available for
375/// reading; if interest=kWrite the socket will be watched to
376/// see if a write will not block.
377/// The argument 'timeout' specifies a maximum time to wait in millisec.
378/// Default no timeout.
379/// Returns 1 if a change of status of interest has been detected within
380/// timeout; 0 in case of timeout; < 0 if an error occurred.
381
383{
384 Int_t rc = 1;
385
386 // Associate a TFileHandler to this socket
388
389 // Wait for an event now
390 rc = gSystem->Select(&fh, timeout);
391
392 return rc;
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Send a single message opcode. Use kind (opcode) to set the
397/// TMessage "what" field. Returns the number of bytes that were sent
398/// (always sizeof(Int_t)) and -1 in case of error. In case the kind has
399/// been or'ed with kMESS_ACK, the call will only return after having
400/// received an acknowledgement, making the sending process synchronous.
401
403{
404 TMessage mess(kind);
405
406 Int_t nsent;
407 if ((nsent = Send(mess)) < 0)
408 return -1;
409
410 return nsent;
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Send a status and a single message opcode. Use kind (opcode) to set the
415/// TMessage "what" field. Returns the number of bytes that were sent
416/// (always 2*sizeof(Int_t)) and -1 in case of error. In case the kind has
417/// been or'ed with kMESS_ACK, the call will only return after having
418/// received an acknowledgement, making the sending process synchronous.
419
421{
422 TMessage mess(kind);
423 mess << status;
424
425 Int_t nsent;
426 if ((nsent = Send(mess)) < 0)
427 return -1;
428
429 return nsent;
430}
431
432////////////////////////////////////////////////////////////////////////////////
433/// Send a character string buffer. Use kind to set the TMessage "what" field.
434/// Returns the number of bytes in the string str that were sent and -1 in
435/// case of error. In case the kind has been or'ed with kMESS_ACK, the call
436/// will only return after having received an acknowledgement, making the
437/// sending process synchronous.
438
439Int_t TUDPSocket::Send(const char *str, Int_t kind)
440{
441 TMessage mess(kind);
442 if (str) mess.WriteString(str);
443
444 Int_t nsent;
445 if ((nsent = Send(mess)) < 0)
446 return -1;
447
448 return nsent - sizeof(Int_t); // - TMessage::What()
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// Send a TMessage object. Returns the number of bytes in the TMessage
453/// that were sent and -1 in case of error. In case the TMessage::What
454/// has been or'ed with kMESS_ACK, the call will only return after having
455/// received an acknowledgement, making the sending process synchronous.
456/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
457/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
458/// support for streaming TStreamerInfo added by Rene Brun May 2008
459/// support for streaming TProcessID added by Rene Brun June 2008
460
462{
464
465 if (fSocket == -1) return -1;
466
467 if (mess.IsReading()) {
468 Error("Send", "cannot send a message used for reading");
469 return -1;
470 }
471
472 // send streamer infos in case schema evolution is enabled in the TMessage
474
475 // send the process id's so TRefs work
477
478 mess.SetLength(); //write length in first word of buffer
479
480 if (GetCompressionLevel() > 0 && mess.GetCompressionLevel() == 0)
482
483 if (mess.GetCompressionLevel() > 0)
484 const_cast<TMessage&>(mess).Compress();
485
486 char *mbuf = mess.Buffer();
487 Int_t mlen = mess.Length();
488 if (mess.CompBuffer()) {
489 mbuf = mess.CompBuffer();
490 mlen = mess.CompLength();
491 }
492
494 Int_t nsent;
495 if ((nsent = gSystem->SendRaw(fSocket, mbuf, mlen, 0)) <= 0) {
496 if (nsent == -5) {
497 // Connection reset by peer or broken
499 Close();
500 }
501 return nsent;
502 }
503
504 fBytesSent += nsent;
506
507 // If acknowledgement is desired, wait for it
508 if (mess.What() & kMESS_ACK) {
511 char buf[2];
512 Int_t n = 0;
513 if ((n = gSystem->RecvRaw(fSocket, buf, sizeof(buf), 0)) < 0) {
514 if (n == -5) {
515 // Connection reset by peer or broken
517 Close();
518 } else
519 n = -1;
520 return n;
521 }
522 if (strncmp(buf, "ok", 2)) {
523 Error("Send", "bad acknowledgement");
524 return -1;
525 }
526 fBytesRecv += 2;
527 fgBytesRecv += 2;
528 }
529
530 Touch(); // update usage timestamp
531
532 return nsent - sizeof(UInt_t); //length - length header
533}
534
535////////////////////////////////////////////////////////////////////////////////
536/// Send an object. Returns the number of bytes sent and -1 in case of error.
537/// In case the "kind" has been or'ed with kMESS_ACK, the call will only
538/// return after having received an acknowledgement, making the sending
539/// synchronous.
540
542{
543 //stream object to message buffer
544 TMessage mess(kind);
545 mess.WriteObject(obj);
546
547 //now sending the object itself
548 Int_t nsent;
549 if ((nsent = Send(mess)) < 0)
550 return -1;
551
552 return nsent;
553}
554
555////////////////////////////////////////////////////////////////////////////////
556/// Send a raw buffer of specified length. Using option kOob one can send
557/// OOB data. Returns the number of bytes sent or -1 in case of error.
558/// Returns -4 in case of kNoBlock and errno == EWOULDBLOCK.
559/// Returns -5 if pipe broken or reset by peer (EPIPE || ECONNRESET).
560
562{
564
565 if (fSocket == -1) return -1;
566
568 Int_t nsent;
569 if ((nsent = gSystem->SendRaw(fSocket, buffer, length, (int) opt)) <= 0) {
570 if (nsent == -5) {
571 // Connection reset or broken: close
573 Close();
574 }
575 return nsent;
576 }
577
578 fBytesSent += nsent;
580
581 Touch(); // update usage timestamp
582
583 return nsent;
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Check if TStreamerInfo must be sent. The list of TStreamerInfo of classes
588/// in the object in the message is in the fInfos list of the message.
589/// We send only the TStreamerInfos not yet sent on this socket.
590
592{
593 if (mess.fInfos && mess.fInfos->GetEntries()) {
594 TIter next(mess.fInfos);
596 TList *minilist = 0;
597 while ((info = (TStreamerInfo*)next())) {
598 Int_t uid = info->GetNumber();
599 if (fBitsInfo.TestBitNumber(uid))
600 continue; //TStreamerInfo had already been sent
602 if (!minilist)
603 minilist = new TList();
604 if (gDebug > 0)
605 Info("SendStreamerInfos", "sending TStreamerInfo: %s, version = %d",
606 info->GetName(),info->GetClassVersion());
607 minilist->Add(info);
608 }
609 if (minilist) {
611 messinfo.WriteObject(minilist);
612 delete minilist;
613 if (messinfo.fInfos)
614 messinfo.fInfos->Clear();
615 if (Send(messinfo) < 0)
616 Warning("SendStreamerInfos", "problems sending TStreamerInfo's ...");
617 }
618 }
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Check if TProcessIDs must be sent. The list of TProcessIDs
623/// in the object in the message is found by looking in the TMessage bits.
624/// We send only the TProcessIDs not yet send on this socket.
625
627{
628 if (mess.TestBitNumber(0)) {
630 Int_t npids = pids->GetEntries();
631 TProcessID *pid;
632 TList *minilist = 0;
633 for (Int_t ipid = 0; ipid < npids; ipid++) {
634 pid = (TProcessID*)pids->At(ipid);
635 if (!pid || !mess.TestBitNumber(pid->GetUniqueID()+1))
636 continue;
637 //check if a pid with this title has already been sent through the socket
638 //if not add it to the fUUIDs list
639 if (!fUUIDs) {
640 fUUIDs = new TList();
641 } else {
642 if (fUUIDs->FindObject(pid->GetTitle()))
643 continue;
644 }
645 fUUIDs->Add(new TObjString(pid->GetTitle()));
646 if (!minilist)
647 minilist = new TList();
648 if (gDebug > 0)
649 Info("SendProcessIDs", "sending TProcessID: %s", pid->GetTitle());
650 minilist->Add(pid);
651 }
652 if (minilist) {
654 messpid.WriteObject(minilist);
655 delete minilist;
656 if (Send(messpid) < 0)
657 Warning("SendProcessIDs", "problems sending TProcessID's ...");
658 }
659 }
660}
661
662////////////////////////////////////////////////////////////////////////////////
663/// Receive a character string message of maximum max length. The expected
664/// message must be of type kMESS_STRING. Returns length of received string
665/// (can be 0 if otherside of connection is closed) or -1 in case of error
666/// or -4 in case a non-blocking socket would block (i.e. there is nothing
667/// to be read).
668
670{
671 Int_t n, kind;
672
674 if ((n = Recv(str, max, kind)) <= 0) {
675 if (n == -5) {
677 n = -1;
678 }
679 return n;
680 }
681
682 if (kind != kMESS_STRING) {
683 Error("Recv", "got message of wrong kind (expected %d, got %d)",
684 kMESS_STRING, kind);
685 return -1;
686 }
687
688 return n;
689}
690
691////////////////////////////////////////////////////////////////////////////////
692/// Receive a character string message of maximum max length. Returns in
693/// kind the message type. Returns length of received string+4 (can be 0 if
694/// other side of connection is closed) or -1 in case of error or -4 in
695/// case a non-blocking socket would block (i.e. there is nothing to be read).
696
697Int_t TUDPSocket::Recv(char *str, Int_t max, Int_t &kind)
698{
699 Int_t n;
700 TMessage *mess;
701
703 if ((n = Recv(mess)) <= 0) {
704 if (n == -5) {
706 n = -1;
707 }
708 return n;
709 }
710
711 kind = mess->What();
712 if (str) {
713 if (mess->BufferSize() > (Int_t)sizeof(Int_t)) // if mess contains more than kind
714 mess->ReadString(str, max);
715 else
716 str[0] = 0;
717 }
718
719 delete mess;
720
721 return n; // number of bytes read (len of str + sizeof(kind)
722}
723
724////////////////////////////////////////////////////////////////////////////////
725/// Receives a status and a message type. Returns length of received
726/// integers, 2*sizeof(Int_t) (can be 0 if other side of connection
727/// is closed) or -1 in case of error or -4 in case a non-blocking
728/// socket would block (i.e. there is nothing to be read).
729
731{
732 Int_t n;
733 TMessage *mess;
734
736 if ((n = Recv(mess)) <= 0) {
737 if (n == -5) {
739 n = -1;
740 }
741 return n;
742 }
743
744 kind = mess->What();
745 (*mess) >> status;
746
747 delete mess;
748
749 return n; // number of bytes read (2 * sizeof(Int_t)
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Receive a TMessage object. The user must delete the TMessage object.
754/// Returns length of message in bytes (can be 0 if other side of connection
755/// is closed) or -1 in case of error or -4 in case a non-blocking socket
756/// would block (i.e. there is nothing to be read) or -5 if pipe broken
757/// or reset by peer (EPIPE || ECONNRESET). In those case mess == 0.
758
760{
762
763 if (fSocket == -1) {
764 mess = 0;
765 return -1;
766 }
767
770 Int_t n;
771 UInt_t len;
772 if ((n = gSystem->RecvRaw(fSocket, &len, sizeof(UInt_t), 0)) <= 0) {
773 if (n == 0 || n == -5) {
774 // Connection closed, reset or broken
776 Close();
777 }
778 mess = 0;
779 return n;
780 }
781 len = net2host(len); //from network to host byte order
782
783 if (len > (std::numeric_limits<decltype(len)>::max() - sizeof(decltype(len)))) {
784 Error("Recv", "Buffer length is %u and %u+sizeof(UInt_t) cannot be represented as an UInt_t.", len, len);
785 return -1;
786 }
787
789 char *buf = new char[len+sizeof(UInt_t)];
790 if ((n = gSystem->RecvRaw(fSocket, buf+sizeof(UInt_t), len, 0)) <= 0) {
791 if (n == 0 || n == -5) {
792 // Connection closed, reset or broken
794 Close();
795 }
796 delete [] buf;
797 mess = 0;
798 return n;
799 }
800
801 fBytesRecv += n + sizeof(UInt_t);
802 fgBytesRecv += n + sizeof(UInt_t);
803
804 mess = new TMessage(buf, len+sizeof(UInt_t));
805
806 // receive any streamer infos
808 goto oncemore;
809
810 // receive any process ids
811 if (RecvProcessIDs(mess))
812 goto oncemore;
813
814 if (mess->What() & kMESS_ACK) {
816 char ok[2] = { 'o', 'k' };
817 Int_t n2 = 0;
818 if ((n2 = gSystem->SendRaw(fSocket, ok, sizeof(ok), 0)) < 0) {
819 if (n2 == -5) {
820 // Connection reset or broken
822 Close();
823 }
824 delete mess;
825 mess = 0;
826 return n2;
827 }
828 mess->SetWhat(mess->What() & ~kMESS_ACK);
829
830 fBytesSent += 2;
831 fgBytesSent += 2;
832 }
833
834 Touch(); // update usage timestamp
835
836 return n;
837}
838
839////////////////////////////////////////////////////////////////////////////////
840/// Receive a raw buffer of specified length bytes. Using option kPeek
841/// one can peek at incoming data. Returns number of received bytes.
842/// Returns -1 in case of error. In case of opt == kOob: -2 means
843/// EWOULDBLOCK and -3 EINVAL. In case of non-blocking mode (kNoBlock)
844/// -4 means EWOULDBLOCK. Returns -5 if pipe broken or reset by
845/// peer (EPIPE || ECONNRESET).
846
848{
850
851 if (fSocket == -1) return -1;
852 if (length == 0) return 0;
853
855 Int_t n;
856 if ((n = gSystem->RecvRaw(fSocket, buffer, length, (int) opt)) <= 0) {
857 if (n == 0 || n == -5) {
858 // Connection closed, reset or broken
860 Close();
861 }
862 return n;
863 }
864
865 fBytesRecv += n;
866 fgBytesRecv += n;
867
868 Touch(); // update usage timestamp
869
870 return n;
871}
872
873////////////////////////////////////////////////////////////////////////////////
874/// Receive a message containing streamer infos. In case the message contains
875/// streamer infos they are imported, the message will be deleted and the
876/// method returns kTRUE.
877
879{
880 if (mess->What() == kMESS_STREAMERINFO) {
881 TList *list = (TList*)mess->ReadObject(TList::Class());
882 TIter next(list);
884 TObjLink *lnk = list->FirstLink();
885 // First call BuildCheck for regular class
886 while (lnk) {
887 info = (TStreamerInfo*)lnk->GetObject();
888 TObject *element = info->GetElements()->UncheckedAt(0);
889 Bool_t isstl = element && strcmp("This",element->GetName())==0;
890 if (!isstl) {
891 info->BuildCheck();
892 if (gDebug > 0)
893 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
894 info->GetName(), info->GetClassVersion());
895 }
896 lnk = lnk->Next();
897 }
898 // Then call BuildCheck for stl class
899 lnk = list->FirstLink();
900 while (lnk) {
901 info = (TStreamerInfo*)lnk->GetObject();
902 TObject *element = info->GetElements()->UncheckedAt(0);
903 Bool_t isstl = element && strcmp("This",element->GetName())==0;
904 if (isstl) {
905 info->BuildCheck();
906 if (gDebug > 0)
907 Info("RecvStreamerInfos", "importing TStreamerInfo: %s, version = %d",
908 info->GetName(), info->GetClassVersion());
909 }
910 lnk = lnk->Next();
911 }
912 delete list;
913 delete mess;
914
915 return kTRUE;
916 }
917 return kFALSE;
918}
919
920////////////////////////////////////////////////////////////////////////////////
921/// Receive a message containing process ids. In case the message contains
922/// process ids they are imported, the message will be deleted and the
923/// method returns kTRUE.
924
926{
927 if (mess->What() == kMESS_PROCESSID) {
928 TList *list = (TList*)mess->ReadObject(TList::Class());
929 TIter next(list);
930 TProcessID *pid;
931 while ((pid = (TProcessID*)next())) {
932 // check that a similar pid is not already registered in fgPIDs
935 TProcessID *p;
936 while ((p = (TProcessID*)nextpid())) {
937 if (!strcmp(p->GetTitle(), pid->GetTitle())) {
938 delete pid;
939 pid = 0;
940 break;
941 }
942 }
943 if (pid) {
944 if (gDebug > 0)
945 Info("RecvProcessIDs", "importing TProcessID: %s", pid->GetTitle());
946 pid->IncrementCount();
947 pidslist->Add(pid);
948 Int_t ind = pidslist->IndexOf(pid);
949 pid->SetUniqueID((UInt_t)ind);
950 }
951 }
952 delete list;
953 delete mess;
954
955 return kTRUE;
956 }
957 return kFALSE;
958}
959
960////////////////////////////////////////////////////////////////////////////////
961/// Set socket options.
962
964{
965 if (fSocket == -1) return -1;
966
967 return gSystem->SetSockOpt(fSocket, opt, val);
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Get socket options. Returns -1 in case of error.
972
974{
975 if (fSocket == -1) return -1;
976
977 return gSystem->GetSockOpt(fSocket, opt, &val);
978}
979
980////////////////////////////////////////////////////////////////////////////////
981/// Returns error code. Meaning depends on context where it is called.
982/// If no error condition returns 0 else a value < 0.
983/// For example see TServerSocket ctor.
984
986{
987 if (!IsValid())
988 return fSocket;
989
990 return 0;
991}
992
993////////////////////////////////////////////////////////////////////////////////
994/// See comments for function SetCompressionSettings
995
997{
999 if (fCompress < 0) {
1000 // if the level is not defined yet use 4 as a default (with ZLIB was 1)
1002 } else {
1003 int level = fCompress % 100;
1004 fCompress = 100 * algorithm + level;
1005 }
1006}
1007
1008////////////////////////////////////////////////////////////////////////////////
1009/// See comments for function SetCompressionSettings
1010
1012{
1013 if (level < 0) level = 0;
1014 if (level > 99) level = 99;
1015 if (fCompress < 0) {
1016 // if the algorithm is not defined yet use 0 as a default
1017 fCompress = level;
1018 } else {
1019 int algorithm = fCompress / 100;
1021 fCompress = 100 * algorithm + level;
1022 }
1023}
1024
1025////////////////////////////////////////////////////////////////////////////////
1026/// Used to specify the compression level and algorithm:
1027/// settings = 100 * algorithm + level
1028///
1029/// level = 0, objects written to this file will not be compressed.
1030/// level = 1, minimal compression level but fast.
1031/// ....
1032/// level = 9, maximal compression level but slower and might use more memory.
1033/// (For the currently supported algorithms, the maximum level is 9)
1034/// If compress is negative it indicates the compression level is not set yet.
1035///
1036/// The enumeration ROOT::RCompressionSetting::EAlgorithm associates each
1037/// algorithm with a number. There is a utility function to help
1038/// to set the value of the argument. For example,
1039/// ROOT::CompressionSettings(ROOT::kLZMA, 1)
1040/// will build an integer which will set the compression to use
1041/// the LZMA algorithm and compression level 1. These are defined
1042/// in the header file Compression.h.
1043///
1044/// Note that the compression settings may be changed at any time.
1045/// The new compression settings will only apply to branches created
1046/// or attached after the setting is changed and other objects written
1047/// after the setting is changed.
1048
1053
1054////////////////////////////////////////////////////////////////////////////////
1055/// Print error string depending on error code.
1056
1057void TUDPSocket::NetError(const char *where, Int_t err)
1058{
1059 // Make sure it is in range
1060 err = (err < kErrError) ? ((err > -1) ? err : 0) : kErrError;
1061
1062 if (gDebug > 0)
1063 ::Error(where, "%s", gRootdErrStr[err]);
1064}
1065
1066////////////////////////////////////////////////////////////////////////////////
1067/// Get total number of bytes sent via all sockets.
1068
1073
1074////////////////////////////////////////////////////////////////////////////////
1075/// Get total number of bytes received via all sockets.
1076
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:72
@ kErrError
Definition NetErrors.h:69
#define SafeDelete(p)
Definition RConfig.hxx:525
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:777
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
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
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
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
Describes a persistent version of a class.
Basic string class.
Definition TString.h:138
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
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:2333
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition TSystem.cxx:2324
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:286
virtual char * GetServiceByPort(int port)
Get name of internet service.
Definition TSystem.cxx:2342
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition TSystem.cxx:2451
virtual TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
Definition TSystem.cxx:2315
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition TSystem.cxx:2351
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition TSystem.cxx:2460
virtual int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Definition TSystem.cxx:2414
virtual Int_t Select(TList *active, Long_t timeout)
Select on active file descriptors (called by TMonitor).
Definition TSystem.cxx:447
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition TSystem.cxx:2306
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition TSystem.cxx:2424
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition TSystem.cxx:2405
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