#ifndef ROOT_TUDPSocket
#define ROOT_TUDPSocket
#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
#ifndef ROOT_TBits
#include "TBits.h"
#endif
#ifndef ROOT_TInetAddress
#include "TInetAddress.h"
#endif
#ifndef ROOT_MessageTypes
#include "MessageTypes.h"
#endif
#ifndef ROOT_TVirtualAuth
#include "TVirtualAuth.h"
#endif
#ifndef ROOT_TSecContext
#include "TSecContext.h"
#endif
#ifndef ROOT_TTimeStamp
#include "TTimeStamp.h"
#endif
#ifndef ROOT_TVirtualMutex
#include "TVirtualMutex.h"
#endif
#ifndef ROOT_TSocket
#include "TSocket.h"
#endif
class TUDPSocket : public TNamed {
friend class TServerSocket;
public:
enum EStatusBits { kIsUnix = BIT(16),
kBrokenConn = BIT(17)
};
enum EInterest { kRead = 1, kWrite = 2 };
enum EServiceType { kSOCKD, kROOTD, kPROOFD };
protected:
TInetAddress fAddress;
UInt_t fBytesRecv;
UInt_t fBytesSent;
Int_t fCompress;
TInetAddress fLocalAddress;
Int_t fRemoteProtocol;
TSecContext *fSecContext;
TString fService;
EServiceType fServType;
Int_t fSocket;
TString fUrl;
TBits fBitsInfo;
TList *fUUIDs;
TVirtualMutex *fLastUsageMtx;
TTimeStamp fLastUsage;
static ULong64_t fgBytesRecv;
static ULong64_t fgBytesSent;
TUDPSocket() : fAddress(), fBytesRecv(0), fBytesSent(0), fCompress(0),
fLocalAddress(), fRemoteProtocol(), fSecContext(0), fService(),
fServType(kSOCKD), fSocket(-1), fUrl(),
fBitsInfo(), fUUIDs(0), fLastUsageMtx(0), fLastUsage() { }
void SetDescriptor(Int_t desc) { fSocket = desc; }
void SendStreamerInfos(const TMessage &mess);
Bool_t RecvStreamerInfos(TMessage *mess);
void SendProcessIDs(const TMessage &mess);
Bool_t RecvProcessIDs(TMessage *mess);
private:
TUDPSocket& operator=(const TUDPSocket &);
Option_t *GetOption() const { return TObject::GetOption(); }
public:
TUDPSocket(TInetAddress address, const char *service);
TUDPSocket(TInetAddress address, Int_t port);
TUDPSocket(const char *host, const char *service);
TUDPSocket(const char *host, Int_t port);
TUDPSocket(const char *sockpath);
TUDPSocket(Int_t descriptor);
TUDPSocket(Int_t descriptor, const char *sockpath);
TUDPSocket(const TUDPSocket &s);
virtual ~TUDPSocket() { Close(); }
virtual void Close(Option_t *opt="");
virtual Int_t GetDescriptor() const { return fSocket; }
TInetAddress GetInetAddress() const { return fAddress; }
virtual TInetAddress GetLocalInetAddress();
Int_t GetPort() const { return fAddress.GetPort(); }
const char *GetService() const { return fService; }
Int_t GetServType() const { return (Int_t)fServType; }
virtual Int_t GetLocalPort();
UInt_t GetBytesSent() const { return fBytesSent; }
UInt_t GetBytesRecv() const { return fBytesRecv; }
Int_t GetCompressionAlgorithm() const;
Int_t GetCompressionLevel() const;
Int_t GetCompressionSettings() const;
Int_t GetErrorCode() const;
virtual Int_t GetOption(ESockOptions opt, Int_t &val);
Int_t GetRemoteProtocol() const { return fRemoteProtocol; }
TSecContext *GetSecContext() const { return fSecContext; }
TTimeStamp GetLastUsage() { R__LOCKGUARD2(fLastUsageMtx); return fLastUsage; }
const char *GetUrl() const { return fUrl; }
virtual Bool_t IsValid() const { return fSocket < 0 ? kFALSE : kTRUE; }
virtual Int_t Recv(TMessage *&mess);
virtual Int_t Recv(Int_t &status, Int_t &kind);
virtual Int_t Recv(char *mess, Int_t max);
virtual Int_t Recv(char *mess, Int_t max, Int_t &kind);
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault);
virtual Int_t Reconnect() { return -1; }
virtual Int_t Select(Int_t interest = kRead, Long_t timeout = -1);
virtual Int_t Send(const TMessage &mess);
virtual Int_t Send(Int_t kind);
virtual Int_t Send(Int_t status, Int_t kind);
virtual Int_t Send(const char *mess, Int_t kind = kMESS_STRING);
virtual Int_t SendObject(const TObject *obj, Int_t kind = kMESS_OBJECT);
virtual Int_t SendRaw(const void *buffer, Int_t length,
ESendRecvOptions opt = kDefault);
void SetCompressionAlgorithm(Int_t algorithm=0);
void SetCompressionLevel(Int_t level=1);
void SetCompressionSettings(Int_t settings=1);
virtual Int_t SetOption(ESockOptions opt, Int_t val);
void SetRemoteProtocol(Int_t rproto) { fRemoteProtocol = rproto; }
void SetSecContext(TSecContext *ctx) { fSecContext = ctx; }
void SetService(const char *service) { fService = service; }
void SetServType(Int_t st) { fServType = (EServiceType)st; }
void SetUrl(const char *url) { fUrl = url; }
void Touch() { R__LOCKGUARD2(fLastUsageMtx); fLastUsage.Set(); }
static ULong64_t GetSocketBytesSent();
static ULong64_t GetSocketBytesRecv();
static void NetError(const char *where, Int_t error);
ClassDef(TUDPSocket,0)
};
inline Int_t TUDPSocket::GetCompressionAlgorithm() const
{
return (fCompress < 0) ? -1 : fCompress / 100;
}
inline Int_t TUDPSocket::GetCompressionLevel() const
{
return (fCompress < 0) ? -1 : fCompress % 100;
}
inline Int_t TUDPSocket::GetCompressionSettings() const
{
return (fCompress < 0) ? -1 : fCompress;
}
#endif