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