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\file TPServerSocket.cxx
14\class TPServerSocket
15\brief This class implements parallel server sockets.
16\note This class deals with sockets: the user is entirely responsible for the security of their usage, for example, but
17not limited to, the management of the connections to said sockets.
18
19This class implements parallel server sockets. A parallel server
20socket waits for requests to come in over the network. It performs
21some operation based on that request and then possibly returns a
22full duplex parallel socket to the requester. The actual work is
23done via the TSystem class (either TUnixSystem or TWinNTSystem).
24**/
25
26#include "TPServerSocket.h"
27#include "TROOT.h"
28#include "TVirtualMutex.h"
29
31
32////////////////////////////////////////////////////////////////////////////////
33/// Create a parallel server socket object on a specified port. Set reuse
34/// to true to force reuse of the server socket (i.e. do not wait for the
35/// time out to pass). Using backlog one can set the desirable queue length
36/// for pending connections.
37/// Use tcpwindowsize to specify the size of the receive buffer, it has
38/// to be specified here to make sure the window scale option is set (for
39/// tcpwindowsize > 65KB and for platforms supporting window scaling).
40/// Use IsValid() to check the validity of the
41/// server socket. In case server socket is not valid use GetErrorCode()
42/// to obtain the specific error value. These values are:
43/// 0 = no error (socket is valid)
44/// -1 = low level socket() call failed
45/// -2 = low level bind() call failed
46/// -3 = low level listen() call failed
47/// Every valid server socket is added to the TROOT sockets list which
48/// will make sure that any open sockets are properly closed on
49/// program termination.
50
58
59////////////////////////////////////////////////////////////////////////////////
60/// Create a parallel server socket object for a named service. Set reuse
61/// to true to force reuse of the server socket (i.e. do not wait for the
62/// time out to pass). Using backlog one can set the desirable queue length
63/// for pending connections.
64/// Use tcpwindowsize to specify the size of the receive buffer, it has
65/// to be specified here to make sure the window scale option is set (for
66/// tcpwindowsize > 65KB and for platforms supporting window scaling).
67/// Use IsValid() to check the validity of the
68/// server socket. In case server socket is not valid use GetErrorCode()
69/// to obtain the specific error value. These values are:
70/// 0 = no error (socket is valid)
71/// -1 = low level socket() call failed
72/// -2 = low level bind() call failed
73/// -3 = low level listen() call failed
74/// Every valid server socket is added to the TROOT sockets list which
75/// will make sure that any open sockets are properly closed on
76/// program termination.
77
85
86////////////////////////////////////////////////////////////////////////////////
87/// Accept a connection on a parallel server socket. Returns a full-duplex
88/// parallel communication TPSocket object. If no pending connections are
89/// present on the queue and nonblocking mode has not been enabled
90/// with SetOption(kNoBlock,1) the call blocks until a connection is
91/// present. The returned socket must be deleted by the user. The socket
92/// is also added to the TROOT sockets list which will make sure that
93/// any open sockets are properly closed on program termination.
94/// In case of error 0 is returned and in case non-blocking I/O is
95/// enabled and no connections are available -1 is returned.
96
98{
101 TPSocket *newPSocket = 0;
102
103 Int_t size, port;
104
105 // wait for the incoming connections to the server and accept them
107
108 if (setupSocket == 0) return 0;
109
110 // receive the port number and number of parallel sockets from the
111 // client and establish 'n' connections
112 if (setupSocket->Recv(port, size) < 0) {
113 Error("Accept", "error receiving port number and number of sockets");
114 return 0;
115 }
116
117 // Check if client is running in single mode
118 if (size == 0) {
119 pSockets = new TSocket*[1];
120
122
123 // create TPSocket object with the original socket
124 newPSocket = new TPSocket(pSockets, 1);
125
126 } else {
127 pSockets = new TSocket*[size];
128
129 for (int i = 0; i < size; i++) {
130 pSockets[i] = new TSocket(setupSocket->GetInetAddress(),
131 port, fTcpWindowSize);
133 gROOT->GetListOfSockets()->Remove(pSockets[i]);
134 }
135
136 // create TPSocket object with all the accepted sockets
138
139 }
140
141 // Transmit authentication information, if any
142 if (setupSocket->IsAuthenticated())
143 newPSocket->SetSecContext(setupSocket->GetSecContext());
144
145 // clean up, if needed
146 if (size > 0)
147 delete setupSocket;
148
149 // return the TSocket object
150 return newPSocket;
151}
152
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:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:414
#define R__LOCKGUARD(mutex)
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
This class implements parallel server sockets.
TPSocket * Accept(UChar_t Opt=kSrvNoAuth) override
Accept a connection on a parallel server socket.
TPServerSocket(const TPServerSocket &)=delete
This class implements parallel server sockets.
Definition TPSocket.h:33
This class implements server sockets.
virtual TSocket * Accept(UChar_t Opt=0)
Accept a connection on a server socket.
This class implements client sockets.
Definition TSocket.h:41
TSocket()
Definition TSocket.h:83