File indexing completed on 2025-01-18 10:12:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TUDPSocket
0013 #define ROOT_TUDPSocket
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #include "TNamed.h"
0028 #include "TBits.h"
0029 #include "TInetAddress.h"
0030 #include "MessageTypes.h"
0031 #include "TVirtualAuth.h"
0032 #include "TSecContext.h"
0033 #include "TTimeStamp.h"
0034 #include "TVirtualMutex.h"
0035 #include "TSocket.h"
0036
0037 class TUDPSocket : public TNamed {
0038
0039 friend class TServerSocket;
0040
0041 public:
0042 enum EStatusBits { kIsUnix = BIT(16),
0043 kBrokenConn = BIT(17)
0044 };
0045 enum EInterest { kRead = 1, kWrite = 2 };
0046 enum EServiceType { kSOCKD, kROOTD, kPROOFD };
0047
0048 protected:
0049 TInetAddress fAddress;
0050 UInt_t fBytesRecv;
0051 UInt_t fBytesSent;
0052 Int_t fCompress;
0053 TInetAddress fLocalAddress;
0054 Int_t fRemoteProtocol;
0055 TSecContext *fSecContext;
0056
0057 TString fService;
0058 EServiceType fServType;
0059 Int_t fSocket;
0060 TString fUrl;
0061 TBits fBitsInfo;
0062 TList *fUUIDs;
0063
0064 TVirtualMutex *fLastUsageMtx;
0065 TTimeStamp fLastUsage;
0066
0067 static ULong64_t fgBytesRecv;
0068 static ULong64_t fgBytesSent;
0069
0070 TUDPSocket() : fAddress(), fBytesRecv(0), fBytesSent(0), fCompress(0),
0071 fLocalAddress(), fRemoteProtocol(), fSecContext(nullptr), fService(),
0072 fServType(kSOCKD), fSocket(-1), fUrl(),
0073 fBitsInfo(), fUUIDs(nullptr), fLastUsageMtx(nullptr), fLastUsage() { }
0074
0075 void SetDescriptor(Int_t desc) { fSocket = desc; }
0076 void SendStreamerInfos(const TMessage &mess);
0077 Bool_t RecvStreamerInfos(TMessage *mess);
0078 void SendProcessIDs(const TMessage &mess);
0079 Bool_t RecvProcessIDs(TMessage *mess);
0080
0081 private:
0082 TUDPSocket& operator=(const TUDPSocket &) = delete;
0083 Option_t *GetOption() const override { return TObject::GetOption(); }
0084
0085 public:
0086 TUDPSocket(TInetAddress address, const char *service);
0087 TUDPSocket(TInetAddress address, Int_t port);
0088 TUDPSocket(const char *host, const char *service);
0089 TUDPSocket(const char *host, Int_t port);
0090 TUDPSocket(const char *sockpath);
0091
0092 TUDPSocket(Int_t descriptor);
0093 TUDPSocket(Int_t descriptor, const char *sockpath);
0094 TUDPSocket(const TUDPSocket &s);
0095
0096 virtual ~TUDPSocket() { Close(); }
0097
0098 virtual void Close(Option_t *opt="");
0099 virtual Int_t GetDescriptor() const { return fSocket; }
0100 TInetAddress GetInetAddress() const { return fAddress; }
0101 virtual TInetAddress GetLocalInetAddress();
0102 Int_t GetPort() const { return fAddress.GetPort(); }
0103 const char *GetService() const { return fService; }
0104 Int_t GetServType() const { return (Int_t)fServType; }
0105 virtual Int_t GetLocalPort();
0106 UInt_t GetBytesSent() const { return fBytesSent; }
0107 UInt_t GetBytesRecv() const { return fBytesRecv; }
0108 Int_t GetCompressionAlgorithm() const;
0109 Int_t GetCompressionLevel() const;
0110 Int_t GetCompressionSettings() const;
0111 Int_t GetErrorCode() const;
0112 virtual Int_t GetOption(ESockOptions opt, Int_t &val);
0113 Int_t GetRemoteProtocol() const { return fRemoteProtocol; }
0114 TSecContext *GetSecContext() const { return fSecContext; }
0115
0116 TTimeStamp GetLastUsage() { R__LOCKGUARD2(fLastUsageMtx); return fLastUsage; }
0117 const char *GetUrl() const { return fUrl; }
0118
0119 virtual Bool_t IsValid() const { return fSocket < 0 ? kFALSE : kTRUE; }
0120 virtual Int_t Recv(TMessage *&mess);
0121 virtual Int_t Recv(Int_t &status, Int_t &kind);
0122 virtual Int_t Recv(char *mess, Int_t max);
0123 virtual Int_t Recv(char *mess, Int_t max, Int_t &kind);
0124 virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault);
0125 virtual Int_t Reconnect() { return -1; }
0126 virtual Int_t Select(Int_t interest = kRead, Long_t timeout = -1);
0127 virtual Int_t Send(const TMessage &mess);
0128 virtual Int_t Send(Int_t kind);
0129 virtual Int_t Send(Int_t status, Int_t kind);
0130 virtual Int_t Send(const char *mess, Int_t kind = kMESS_STRING);
0131 virtual Int_t SendObject(const TObject *obj, Int_t kind = kMESS_OBJECT);
0132 virtual Int_t SendRaw(const void *buffer, Int_t length,
0133 ESendRecvOptions opt = kDefault);
0134 void SetCompressionAlgorithm(Int_t algorithm = ROOT::RCompressionSetting::EAlgorithm::kUseGlobal);
0135 void SetCompressionLevel(Int_t level = ROOT::RCompressionSetting::ELevel::kUseMin);
0136 void SetCompressionSettings(Int_t settings = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
0137 virtual Int_t SetOption(ESockOptions opt, Int_t val);
0138 void SetRemoteProtocol(Int_t rproto) { fRemoteProtocol = rproto; }
0139 void SetSecContext(TSecContext *ctx) { fSecContext = ctx; }
0140 void SetService(const char *service) { fService = service; }
0141 void SetServType(Int_t st) { fServType = (EServiceType)st; }
0142 void SetUrl(const char *url) { fUrl = url; }
0143
0144 void Touch() { R__LOCKGUARD2(fLastUsageMtx); fLastUsage.Set(); }
0145
0146 static ULong64_t GetSocketBytesSent();
0147 static ULong64_t GetSocketBytesRecv();
0148
0149 static void NetError(const char *where, Int_t error);
0150
0151 ClassDefOverride(TUDPSocket,0)
0152 };
0153
0154
0155 inline Int_t TUDPSocket::GetCompressionAlgorithm() const
0156 {
0157 return (fCompress < 0) ? -1 : fCompress / 100;
0158 }
0159
0160
0161 inline Int_t TUDPSocket::GetCompressionLevel() const
0162 {
0163 return (fCompress < 0) ? -1 : fCompress % 100;
0164 }
0165
0166
0167 inline Int_t TUDPSocket::GetCompressionSettings() const
0168 {
0169 return (fCompress < 0) ? -1 : fCompress;
0170 }
0171
0172 #endif