library: libCore #include "TServerSocket.h"

# TServerSocket

class description - source file - inheritance tree (.pdf)

## class TServerSocket : public TSocket

| Inheritance Chart:
`TObject`
| <- | `TNamed`
| <- | `TSocket`
| <- | `TServerSocket` |
<- |
`TPServerSocket` |

        private:

                        TServerSocket()
                        TServerSocket(const TServerSocket&)
                 Bool_t Authenticate(TSocket*)
                   void operator=(const TServerSocket&)

        public:

                               TServerSocket(Int_t port, Bool_t reuse = kFALSE, Int_t backlog = kDefaultBacklog, Int_t tcpwindowsize = -1)
                               TServerSocket(const char* service, Bool_t reuse = kFALSE, Int_t backlog = kDefaultBacklog, Int_t tcpwindowsize = -1)
                       virtual ~TServerSocket()
              virtual TSocket* Accept(UChar_t Opt = 0)
                static TClass* Class()
                static UChar_t GetAcceptOptions()
          virtual TInetAddress GetLocalInetAddress()
                 virtual Int_t GetLocalPort()
               virtual TClass* IsA() const
                 virtual Int_t Recv(TMessage*&)
                 virtual Int_t Recv(Int_t&, Int_t&)
                 virtual Int_t Recv(char*, Int_t)
                 virtual Int_t Recv(char*, Int_t, Int_t&)
                 virtual Int_t RecvRaw(void*, Int_t, ESendRecvOptions = kDefault)
                 virtual Int_t Send(const TMessage&)
                 virtual Int_t Send(Int_t)
                 virtual Int_t Send(Int_t, Int_t)
                 virtual Int_t Send(const char*, Int_t = kMESS_STRING)
                 virtual Int_t SendObject(const TObject*, Int_t = kMESS_OBJECT)
                 virtual Int_t SendRaw(const void*, Int_t, ESendRecvOptions = kDefault)
                   static void SetAcceptOptions(UChar_t Opt)
                   static void ShowAcceptOptions()
                  virtual void ShowMembers(TMemberInspector& insp, char* parent)
                  virtual void Streamer(TBuffer& b)
                          void StreamerNVirtual(TBuffer& b)

### Data Members

        private:

          TSeqCollection* fSecContexts       List of TSecContext with cleanup info
             static void* fgSrvAuthHook
             static void* fgSrvAuthClupHook
           static UChar_t fgAcceptOpt        Default accept options

        public:

          static const enum TServerSocket:: kDefaultBacklog

## Class Description

     TServerSocket

     This class implements server sockets. A server socket waits for
     requests to come in over the network. It performs some operation
     based on that request and then possibly returns a full duplex socket
     to the requester. The actual work is done via the TSystem class
     (either TUnixSystem or TWinNTSystem).

TServerSocket(const char *service, Bool_t reuse, Int_t backlog, Int_t tcpwindowsize)

     Create a server socket object for a named service. Set reuse to true
     to force reuse of the server socket (i.e. do not wait for the time
     out to pass). Using backlog one can set the desirable queue length
     for pending connections.
     Use tcpwindowsize to specify the size of the receive buffer, it has
     to be specified here to make sure the window scale option is set (for
     tcpwindowsize > 65KB and for platforms supporting window scaling).
     Use IsValid() to check the validity of the
     server socket. In case server socket is not valid use GetErrorCode()
     to obtain the specific error value. These values are:
      0 = no error (socket is valid)
     -1 = low level socket() call failed
     -2 = low level bind() call failed
     -3 = low level listen() call failed
     Every valid server socket is added to the TROOT sockets list which
     will make sure that any open sockets are properly closed on
     program termination.

TServerSocket(Int_t port, Bool_t reuse, Int_t backlog, Int_t tcpwindowsize)

     Create a server socket object on a specified port. Set reuse to true
     to force reuse of the server socket (i.e. do not wait for the time
     out to pass). Using backlog one can set the desirable queue length
     for pending connections. If port is 0 a port scan will be done to
     find a free port. This option is mutual exlusive with the reuse option.
     Use tcpwindowsize to specify the size of the receive buffer, it has
     to be specified here to make sure the window scale option is set (for
     tcpwindowsize > 65KB and for platforms supporting window scaling).
     Use IsValid() to check the validity of the
     server socket. In case server socket is not valid use GetErrorCode()
     to obtain the specific error value. These values are:
      0 = no error (socket is valid)
     -1 = low level socket() call failed
     -2 = low level bind() call failed
     -3 = low level listen() call failed
     Every valid server socket is added to the TROOT sockets list which
     will make sure that any open sockets are properly closed on
     program termination.

~TServerSocket()

     Destructor: cleanup authentication stuff (if any) and close

TSocket* Accept(UChar_t Opt)

     Accept a connection on a server socket. Returns a full-duplex
     communication TSocket object. If no pending connections are
     present on the queue and nonblocking mode has not been enabled
     with SetOption(kNoBlock,1) the call blocks until a connection is
     present. The returned socket must be deleted by the user. The socket
     is also added to the TROOT sockets list which will make sure that
     any open sockets are properly closed on program termination.
     In case of error 0 is returned and in case non-blocking I/O is
     enabled and no connections are available -1 is returned.

     Opt can be used to require client authentication; valid options are

        kSrvAuth   =   require client authentication
        kSrvNoAuth =   force no client authentication

     Example: use Opt = kSrvAuth to require client authentication.

     Default options are taken from fgAcceptOpt and are initially
     equivalent to kSrvNoAuth; they can be changed with the static
     method TServerSocket::SetAcceptOptions(Opt).
     The active defaults can be visualized using the static method
     TServerSocket::ShowAcceptOptions().

TInetAddress GetLocalInetAddress()

     Return internet address of host to which the server socket is bound,
     i.e. the local host. In case of error TInetAddress::IsValid() returns
     kFALSE.

Int_t GetLocalPort()

     Get port # to which server socket is bound. In case of error returns -1.

UChar_t GetAcceptOptions()

     Return default options for Accept

void SetAcceptOptions(UChar_t mod)

     Set default options for Accept according to modifier 'mod'.
     Use:
       kSrvAuth                 require client authentication
       kSrvNoAuth               do not require client authentication

void ShowAcceptOptions()

     Print default options for Accept

Bool_t Authenticate(TSocket *sock)

     Check authentication request from the client on new
     open connection

### Inline Functions

                     void operator=(const TServerSocket&)
            TServerSocket TServerSocket(Int_t port, Bool_t reuse = kFALSE, Int_t backlog = kDefaultBacklog, Int_t tcpwindowsize = -1)
            TServerSocket TServerSocket(const char* service, Bool_t reuse = kFALSE, Int_t backlog = kDefaultBacklog, Int_t tcpwindowsize = -1)
                    Int_t Send(const TMessage&)
                    Int_t Send(Int_t)
                    Int_t Send(Int_t, Int_t)
                    Int_t Send(const char*, Int_t = kMESS_STRING)
                    Int_t SendObject(const TObject*, Int_t = kMESS_OBJECT)
                    Int_t SendRaw(const void*, Int_t, ESendRecvOptions = kDefault)
                    Int_t Recv(TMessage*&)
                    Int_t Recv(Int_t&, Int_t&)
                    Int_t Recv(char*, Int_t)
                    Int_t Recv(char*, Int_t, Int_t&)
                    Int_t RecvRaw(void*, Int_t, ESendRecvOptions = kDefault)
                  TClass* Class()
                  TClass* IsA() const
                     void ShowMembers(TMemberInspector& insp, char* parent)
                     void Streamer(TBuffer& b)
                     void StreamerNVirtual(TBuffer& b)

Author: Fons Rademakers 18/12/96
Last update: root/net:$Name: $:$Id: TServerSocket.cxx,v 1.10 2005/06/23 06:24:27 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *