Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TUDPSocket.h
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#ifndef ROOT_TUDPSocket
13#define ROOT_TUDPSocket
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TUDPSocket //
19// //
20// This class implements udp client sockets. A socket is an endpoint //
21// for communication between two machines. //
22// The actual work is done via the TSystem class (either TUnixSystem, //
23// or TWinNTSystem). //
24// //
25//////////////////////////////////////////////////////////////////////////
26
27#include "TNamed.h"
28#include "TBits.h"
29#include "TInetAddress.h"
30#include "MessageTypes.h"
31#include "TSecContext.h"
32#include "TTimeStamp.h"
33#include "TVirtualMutex.h"
34#include "TSocket.h"
35
36class TUDPSocket : public TNamed {
37
38friend class TServerSocket;
39
40public:
41 enum EStatusBits { kIsUnix = BIT(16), // set if unix socket
42 kBrokenConn = BIT(17) // set if conn reset by peer or broken
43 };
44 enum EInterest { kRead = 1, kWrite = 2 };
46
47protected:
48 TInetAddress fAddress; // remote internet address and port #
49 UInt_t fBytesRecv; // total bytes received over this socket
50 UInt_t fBytesSent; // total bytes sent using this socket
51 Int_t fCompress; // Compression level and algorithm
52 TInetAddress fLocalAddress; // local internet address and port #
53 Int_t fRemoteProtocol; // protocol of remote daemon
54 ROOT::Deprecated::TSecContext *fSecContext; // after a successful Authenticate call
55 // points to related security context
56 TString fService; // name of service (matches remote port #)
57 EServiceType fServType; // remote service type
58 Int_t fSocket; // socket descriptor
59 TString fUrl; // needs this for special authentication options
60 TBits fBitsInfo; // bits array to mark TStreamerInfo classes already sent
61 TList *fUUIDs; // list of TProcessIDs already sent through the socket
62
63 TVirtualMutex *fLastUsageMtx; // Protect last usage setting / reading
64 TTimeStamp fLastUsage; // Time stamp of last usage
65
66 static ULong64_t fgBytesRecv; // total bytes received by all socket objects
67 static ULong64_t fgBytesSent; // total bytes sent by all socket objects
68
73
74 void SetDescriptor(Int_t desc) { fSocket = desc; }
75 void SendStreamerInfos(const TMessage &mess);
77 void SendProcessIDs(const TMessage &mess);
79
80private:
81 TUDPSocket& operator=(const TUDPSocket &) = delete;
82 Option_t *GetOption() const override { return TObject::GetOption(); }
83
84public:
85 TUDPSocket(TInetAddress address, const char *service);
86 TUDPSocket(TInetAddress address, Int_t port);
87 TUDPSocket(const char *host, const char *service);
88 TUDPSocket(const char *host, Int_t port);
89 TUDPSocket(const char *sockpath);
90
92 TUDPSocket(Int_t descriptor, const char *sockpath);
93 TUDPSocket(const TUDPSocket &s);
94
95 virtual ~TUDPSocket() { Close(); }
96
97 virtual void Close(Option_t *opt="");
98 virtual Int_t GetDescriptor() const { return fSocket; }
101 Int_t GetPort() const { return fAddress.GetPort(); }
102 const char *GetService() const { return fService; }
103 Int_t GetServType() const { return (Int_t)fServType; }
104 virtual Int_t GetLocalPort();
105 UInt_t GetBytesSent() const { return fBytesSent; }
106 UInt_t GetBytesRecv() const { return fBytesRecv; }
110 Int_t GetErrorCode() const;
111 virtual Int_t GetOption(ESockOptions opt, Int_t &val);
114 R__DEPRECATED(6, 42, "TUDPSocket::GetSecContext is deprecated") { return fSecContext; }
115
117 const char *GetUrl() const { return fUrl; }
118
119 virtual Bool_t IsValid() const { return fSocket < 0 ? kFALSE : kTRUE; }
120 virtual Int_t Recv(TMessage *&mess);
121 virtual Int_t Recv(Int_t &status, Int_t &kind);
122 virtual Int_t Recv(char *mess, Int_t max);
123 virtual Int_t Recv(char *mess, Int_t max, Int_t &kind);
124 virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault);
125 virtual Int_t Reconnect() { return -1; }
126 virtual Int_t Select(Int_t interest = kRead, Long_t timeout = -1);
127 virtual Int_t Send(const TMessage &mess);
128 virtual Int_t Send(Int_t kind);
129 virtual Int_t Send(Int_t status, Int_t kind);
130 virtual Int_t Send(const char *mess, Int_t kind = kMESS_STRING);
131 virtual Int_t SendObject(const TObject *obj, Int_t kind = kMESS_OBJECT);
132 virtual Int_t SendRaw(const void *buffer, Int_t length,
137 virtual Int_t SetOption(ESockOptions opt, Int_t val);
140 R__DEPRECATED(6, 42, "TUDPSocket::SetSecContext is deprecated"){ fSecContext = ctx; }
141 void SetService(const char *service) { fService = service; }
143 void SetUrl(const char *url) { fUrl = url; }
144
146
149
150 static void NetError(const char *where, Int_t error);
151
152 ClassDefOverride(TUDPSocket,0) //This class implements UDP client sockets
153};
154
155//______________________________________________________________________________
157{
158 return (fCompress < 0) ? -1 : fCompress / 100;
159}
160
161//______________________________________________________________________________
163{
164 return (fCompress < 0) ? -1 : fCompress % 100;
165}
166
167//______________________________________________________________________________
169{
170 return (fCompress < 0) ? -1 : fCompress;
171}
172
173#endif
@ kMESS_STRING
@ kMESS_OBJECT
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
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
#define BIT(n)
Definition Rtypes.h:91
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
ESockOptions
Definition TSystem.h:229
ESendRecvOptions
Definition TSystem.h:242
@ kDefault
Definition TSystem.h:243
#define R__LOCKGUARD2(mutex)
Container of bits.
Definition TBits.h:26
This class represents an Internet Protocol (IP) address.
Int_t GetPort() const
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:42
virtual Option_t * GetOption() const
Definition TObject.h:147
This class implements server sockets.
Basic string class.
Definition TString.h:138
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:45
void Set()
Set Date/Time to current time as reported by the system.
This class implements UDP client sockets.
Definition TUDPSocket.h:36
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:49
void SetRemoteProtocol(Int_t rproto)
Definition TUDPSocket.h:138
TTimeStamp GetLastUsage()
Definition TUDPSocket.h:116
Int_t GetErrorCode() const
Returns error code.
UInt_t fBytesSent
Definition TUDPSocket.h:50
Int_t fCompress
Definition TUDPSocket.h:51
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:57
TInetAddress fLocalAddress
Definition TUDPSocket.h:52
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
TUDPSocket & operator=(const TUDPSocket &)=delete
UInt_t GetBytesSent() const
Definition TUDPSocket.h:105
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:63
virtual Int_t GetLocalPort()
Return the local port # to which the socket is bound.
TInetAddress fAddress
Definition TUDPSocket.h:48
TString fService
Definition TUDPSocket.h:56
static ULong64_t fgBytesRecv
Definition TUDPSocket.h:66
const char * GetUrl() const
Definition TUDPSocket.h:117
Bool_t RecvProcessIDs(TMessage *mess)
Receive a message containing process ids.
virtual Bool_t IsValid() const
Definition TUDPSocket.h:119
ROOT::Deprecated::TSecContext * GetSecContext() const R__DEPRECATED(6
const char * GetService() const
Definition TUDPSocket.h:102
Int_t fRemoteProtocol
Definition TUDPSocket.h:53
static void NetError(const char *where, Int_t error)
Print error string depending on error code.
TInetAddress GetInetAddress() const
Definition TUDPSocket.h:99
void SetSecContext(ROOT::Deprecated::TSecContext *ctx) R__DEPRECATED(6
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 ~TUDPSocket()
Definition TUDPSocket.h:95
Int_t GetRemoteProtocol() const
Definition TUDPSocket.h:112
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
static ULong64_t fgBytesSent
Definition TUDPSocket.h:67
void SetDescriptor(Int_t desc)
Definition TUDPSocket.h:74
Int_t GetCompressionLevel() const
Definition TUDPSocket.h:162
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:61
void Touch()
Definition TUDPSocket.h:145
TBits fBitsInfo
Definition TUDPSocket.h:60
Int_t GetPort() const
Definition TUDPSocket.h:101
TTimeStamp fLastUsage
Definition TUDPSocket.h:64
static ULong64_t GetSocketBytesRecv()
Get total number of bytes received via all sockets.
ROOT::Deprecated::TSecContext * fSecContext
Definition TUDPSocket.h:54
TString fUrl
Definition TUDPSocket.h:59
void SetServType(Int_t st)
Definition TUDPSocket.h:142
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Int_t GetCompressionSettings() const
Definition TUDPSocket.h:168
Option_t * GetOption() const override
Definition TUDPSocket.h:82
UInt_t GetBytesRecv() const
Definition TUDPSocket.h:106
void SetService(const char *service)
Definition TUDPSocket.h:141
static ULong64_t GetSocketBytesSent()
Get total number of bytes sent via all sockets.
Int_t fSocket
Definition TUDPSocket.h:58
virtual Int_t Reconnect()
Definition TUDPSocket.h:125
virtual Int_t Select(Int_t interest=kRead, Long_t timeout=-1)
Waits for this socket to change status.
Int_t GetCompressionAlgorithm() const
Definition TUDPSocket.h:156
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
virtual Int_t GetDescriptor() const
Definition TUDPSocket.h:98
void SetUrl(const char *url)
Definition TUDPSocket.h:143
Int_t GetServType() const
Definition TUDPSocket.h:103
void SendProcessIDs(const TMessage &mess)
Check if TProcessIDs must be sent.
This class implements a mutex interface.
@ kUseGlobal
Use the global compression algorithm.
Definition Compression.h:93
@ kUseCompiledDefault
Use the compile-time default setting.
Definition Compression.h:53
@ kUseMin
Compression level reserved when we are not sure what to use (1 is for the fastest compression)
Definition Compression.h:72