#ifndef ROOT_TSocket
#define ROOT_TSocket
#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
enum ESockOptions {
kSendBuffer,
kRecvBuffer,
kOobInline,
kKeepAlive,
kReuseAddr,
kNoDelay,
kNoBlock,
kProcessGroup,
kAtMark,
kBytesToRead
};
enum ESendRecvOptions {
kDefault,
kOob,
kPeek,
kDontBlock
};
class TMessage;
class THostAuth;
class TSocket : public TNamed {
friend class TServerSocket;
friend class TProofServ;
friend class TSlave;
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;
Int_t fTcpWindowSize;
TString fUrl;
TBits fBitsInfo;
TList *fUUIDs;
TVirtualMutex *fLastUsageMtx;
TTimeStamp fLastUsage;
static ULong64_t fgBytesRecv;
static ULong64_t fgBytesSent;
static Int_t fgClientProtocol;
TSocket() : fAddress(), fBytesRecv(0), fBytesSent(0), fCompress(0),
fLocalAddress(), fRemoteProtocol(), fSecContext(0), fService(),
fServType(kSOCKD), fSocket(-1), fTcpWindowSize(0), fUrl(),
fBitsInfo(), fUUIDs(0), fLastUsageMtx(0), fLastUsage() { }
Bool_t Authenticate(const char *user);
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:
TSocket& operator=(const TSocket &);
Option_t *GetOption() const { return TObject::GetOption(); }
public:
TSocket(TInetAddress address, const char *service, Int_t tcpwindowsize = -1);
TSocket(TInetAddress address, Int_t port, Int_t tcpwindowsize = -1);
TSocket(const char *host, const char *service, Int_t tcpwindowsize = -1);
TSocket(const char *host, Int_t port, Int_t tcpwindowsize = -1);
TSocket(const char *sockpath);
TSocket(Int_t descriptor);
TSocket(Int_t descriptor, const char *sockpath);
TSocket(const TSocket &s);
virtual ~TSocket() { 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; }
Int_t GetTcpWindowSize() const { return fTcpWindowSize; }
TTimeStamp GetLastUsage() { R__LOCKGUARD2(fLastUsageMtx); return fLastUsage; }
const char *GetUrl() const { return fUrl; }
virtual Bool_t IsAuthenticated() const { return fSecContext ? kTRUE : kFALSE; }
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 Int_t GetClientProtocol();
static ULong64_t GetSocketBytesSent();
static ULong64_t GetSocketBytesRecv();
static TSocket *CreateAuthSocket(const char *user, const char *host,
Int_t port, Int_t size = 0,
Int_t tcpwindowsize = -1, TSocket *s = 0, Int_t *err = 0);
static TSocket *CreateAuthSocket(const char *url, Int_t size = 0,
Int_t tcpwindowsize = -1, TSocket *s = 0, Int_t *err = 0);
static void NetError(const char *where, Int_t error);
ClassDef(TSocket,0)
};
inline Int_t TSocket::GetCompressionAlgorithm() const
{
return (fCompress < 0) ? -1 : fCompress / 100;
}
inline Int_t TSocket::GetCompressionLevel() const
{
return (fCompress < 0) ? -1 : fCompress % 100;
}
inline Int_t TSocket::GetCompressionSettings() const
{
return (fCompress < 0) ? -1 : fCompress;
}
#endif