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
28
29////////////////////////////////////////////////////////////////////////////////
30/// Create a parallel server socket object on a specified port. Set reuse
31/// to true to force reuse of the server socket (i.e. do not wait for the
32/// time out to pass). Using backlog one can set the desirable queue length
33/// for pending connections.
34/// Use tcpwindowsize to specify the size of the receive buffer, it has
35/// to be specified here to make sure the window scale option is set (for
36/// tcpwindowsize > 65KB and for platforms supporting window scaling).
37/// Use IsValid() to check the validity of the
38/// server socket. In case server socket is not valid use GetErrorCode()
39/// to obtain the specific error value. These values are:
40/// 0 = no error (socket is valid)
41/// -1 = low level socket() call failed
42/// -2 = low level bind() call failed
43/// -3 = low level listen() call failed
44/// Every valid server socket is added to the TROOT sockets list which
45/// will make sure that any open sockets are properly closed on
46/// program termination.
47
55
56////////////////////////////////////////////////////////////////////////////////
57/// Create a parallel server socket object for a named service. Set reuse
58/// to true to force reuse of the server socket (i.e. do not wait for the
59/// time out to pass). Using backlog one can set the desirable queue length
60/// for pending connections.
61/// Use tcpwindowsize to specify the size of the receive buffer, it has
62/// to be specified here to make sure the window scale option is set (for
63/// tcpwindowsize > 65KB and for platforms supporting window scaling).
64/// Use IsValid() to check the validity of the
65/// server socket. In case server socket is not valid use GetErrorCode()
66/// to obtain the specific error value. These values are:
67/// 0 = no error (socket is valid)
68/// -1 = low level socket() call failed
69/// -2 = low level bind() call failed
70/// -3 = low level listen() call failed
71/// Every valid server socket is added to the TROOT sockets list which
72/// will make sure that any open sockets are properly closed on
73/// program termination.
74
82
83////////////////////////////////////////////////////////////////////////////////
84/// Accept a connection on a parallel server socket. Returns a full-duplex
85/// parallel communication TPSocket object. If no pending connections are
86/// present on the queue and nonblocking mode has not been enabled
87/// with SetOption(kNoBlock,1) the call blocks until a connection is
88/// present. The returned socket must be deleted by the user. The socket
89/// is also added to the TROOT sockets list which will make sure that
90/// any open sockets are properly closed on program termination.
91/// In case of error 0 is returned and in case non-blocking I/O is
92/// enabled and no connections are available -1 is returned.
93
95{
99
100 Int_t size, port;
101
102 // wait for the incoming connections to the server and accept them
104
105 if (setupSocket == 0) return 0;
106
107 // receive the port number and number of parallel sockets from the
108 // client and establish 'n' connections
109 if (setupSocket->Recv(port, size) < 0) {
110 Error("Accept", "error receiving port number and number of sockets");
111 return 0;
112 }
113
114 // Check if client is running in single mode
115 if (size == 0) {
116 pSockets = new TSocket*[1];
117
119
120 // create TPSocket object with the original socket
121 newPSocket = new TPSocket(pSockets, 1);
122
123 } else {
124 pSockets = new TSocket*[size];
125
126 for (int i = 0; i < size; i++) {
127 pSockets[i] = new TSocket(setupSocket->GetInetAddress(),
128 port, fTcpWindowSize);
130 gROOT->GetListOfSockets()->Remove(pSockets[i]);
131 }
132
133 // create TPSocket object with all the accepted sockets
135
136 }
137
138 // Transmit authentication information, if any
139 if (setupSocket->IsAuthenticated())
140 newPSocket->SetSecContext(setupSocket->GetSecContext());
141
142 // clean up, if needed
143 if (size > 0)
144 delete setupSocket;
145
146 // return the TSocket object
147 return newPSocket;
148}
149
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
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:411
#define R__LOCKGUARD(mutex)
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
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:81