Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPServerSocket.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Fons Rademakers 19/1/2001
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, 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//////////////////////////////////////////////////////////////////////////
13// //
14// TPServerSocket //
15// //
16// This class implements parallel server sockets. A parallel server //
17// socket waits for requests to come in over the network. It performs //
18// some operation based on that request and then possibly returns a //
19// full duplex parallel socket to the requester. The actual work is //
20// done via the TSystem class (either TUnixSystem or TWinNTSystem). //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TPServerSocket.h"
25#include "TROOT.h"
26#include "TVirtualMutex.h"
27
29
30////////////////////////////////////////////////////////////////////////////////
31/// Create a parallel server socket object on a specified port. Set reuse
32/// to true to force reuse of the server socket (i.e. do not wait for the
33/// time out to pass). Using backlog one can set the desirable queue length
34/// for pending connections.
35/// Use tcpwindowsize to specify the size of the receive buffer, it has
36/// to be specified here to make sure the window scale option is set (for
37/// tcpwindowsize > 65KB and for platforms supporting window scaling).
38/// Use IsValid() to check the validity of the
39/// server socket. In case server socket is not valid use GetErrorCode()
40/// to obtain the specific error value. These values are:
41/// 0 = no error (socket is valid)
42/// -1 = low level socket() call failed
43/// -2 = low level bind() call failed
44/// -3 = low level listen() call failed
45/// Every valid server socket is added to the TROOT sockets list which
46/// will make sure that any open sockets are properly closed on
47/// program termination.
48
50 Int_t tcpwindowsize) :
51 TServerSocket(port, reuse, backlog, tcpwindowsize)
52{
53 fTcpWindowSize = tcpwindowsize;
54 SetName("PServerSocket");
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Create a parallel server socket object for a named service. Set reuse
59/// to true to force reuse of the server socket (i.e. do not wait for the
60/// time out to pass). Using backlog one can set the desirable queue length
61/// for pending connections.
62/// Use tcpwindowsize to specify the size of the receive buffer, it has
63/// to be specified here to make sure the window scale option is set (for
64/// tcpwindowsize > 65KB and for platforms supporting window scaling).
65/// Use IsValid() to check the validity of the
66/// server socket. In case server socket is not valid use GetErrorCode()
67/// to obtain the specific error value. These values are:
68/// 0 = no error (socket is valid)
69/// -1 = low level socket() call failed
70/// -2 = low level bind() call failed
71/// -3 = low level listen() call failed
72/// Every valid server socket is added to the TROOT sockets list which
73/// will make sure that any open sockets are properly closed on
74/// program termination.
75
76TPServerSocket::TPServerSocket(const char *service, Bool_t reuse, Int_t backlog,
77 Int_t tcpwindowsize) :
78 TServerSocket(service, reuse, backlog, tcpwindowsize)
79{
80 fTcpWindowSize = tcpwindowsize;
81 SetName("PServerSocket");
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Accept a connection on a parallel server socket. Returns a full-duplex
86/// parallel communication TPSocket object. If no pending connections are
87/// present on the queue and nonblocking mode has not been enabled
88/// with SetOption(kNoBlock,1) the call blocks until a connection is
89/// present. The returned socket must be deleted by the user. The socket
90/// is also added to the TROOT sockets list which will make sure that
91/// any open sockets are properly closed on program termination.
92/// In case of error 0 is returned and in case non-blocking I/O is
93/// enabled and no connections are available -1 is returned.
94
96{
97 TSocket *setupSocket = 0;
98 TSocket **pSockets;
99 TPSocket *newPSocket = 0;
100
101 Int_t size, port;
102
103 // wait for the incoming connections to the server and accept them
104 setupSocket = TServerSocket::Accept(Opt);
105
106 if (setupSocket == 0) return 0;
107
108 // receive the port number and number of parallel sockets from the
109 // client and establish 'n' connections
110 if (setupSocket->Recv(port, size) < 0) {
111 Error("Accept", "error receiving port number and number of sockets");
112 return 0;
113 }
114
115 // Check if client is running in single mode
116 if (size == 0) {
117 pSockets = new TSocket*[1];
118
119 pSockets[0] = setupSocket;
120
121 // create TPSocket object with the original socket
122 newPSocket = new TPSocket(pSockets, 1);
123
124 } else {
125 pSockets = new TSocket*[size];
126
127 for (int i = 0; i < size; i++) {
128 pSockets[i] = new TSocket(setupSocket->GetInetAddress(),
129 port, fTcpWindowSize);
131 gROOT->GetListOfSockets()->Remove(pSockets[i]);
132 }
133
134 // create TPSocket object with all the accepted sockets
135 newPSocket = new TPSocket(pSockets, size);
136
137 }
138
139 // Transmit authentication information, if any
140 if (setupSocket->IsAuthenticated())
141 newPSocket->SetSecContext(setupSocket->GetSecContext());
142
143 // clean up, if needed
144 if (size > 0)
145 delete setupSocket;
146
147 // return the TSocket object
148 return newPSocket;
149}
150
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned char UChar_t
Definition RtypesCore.h:38
#define ClassImp(name)
Definition Rtypes.h:382
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:406
#define R__LOCKGUARD(mutex)
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:993
TPSocket * Accept(UChar_t Opt=kSrvNoAuth) override
Accept a connection on a parallel server socket.
TPServerSocket(const TPServerSocket &)=delete
virtual TSocket * Accept(UChar_t Opt=0)
Accept a connection on a server socket.
TSocket()
Definition TSocket.h:83
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:818
TInetAddress GetInetAddress() const
Definition TSocket.h:113
TSecContext * GetSecContext() const
Definition TSocket.h:127
void SetSecContext(TSecContext *ctx)
Definition TSocket.h:152
virtual Bool_t IsAuthenticated() const
Definition TSocket.h:131