/usr/include/vtk-6.2/vtkSocketCommunicator.h is in libvtk6-dev 6.2.0+dfsg1-10build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkSocketCommunicator.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkSocketCommunicator - Process communication using Sockets
// .SECTION Description
// This is a concrete implementation of vtkCommunicator which supports
// interprocess communication using BSD style sockets.
// It supports byte swapping for the communication of machines
// with different endianness.
// .SECTION Caveats
// Communication between 32 bit and 64 bit systems is not fully
// supported. If a type does not have the same length on both
// systems, this communicator can not be used to transfer data
// of that type.
// .SECTION see also
// vtkCommunicator vtkSocketController
#ifndef vtkSocketCommunicator_h
#define vtkSocketCommunicator_h
#include "vtkParallelCoreModule.h" // For export macro
#include "vtkCommunicator.h"
#include "vtkByteSwap.h" // Needed for vtkSwap macros
#ifdef VTK_WORDS_BIGENDIAN
# define vtkSwap4 vtkByteSwap::Swap4LE
# define vtkSwap4Range vtkByteSwap::Swap4LERange
# define vtkSwap8 vtkByteSwap::Swap8LE
# define vtkSwap8Range vtkByteSwap::Swap8LERange
#else
# define vtkSwap4 vtkByteSwap::Swap4BE
# define vtkSwap4Range vtkByteSwap::Swap4BERange
# define vtkSwap8 vtkByteSwap::Swap8BE
# define vtkSwap8Range vtkByteSwap::Swap8BERange
#endif
class vtkClientSocket;
class vtkServerSocket;
class VTKPARALLELCORE_EXPORT vtkSocketCommunicator : public vtkCommunicator
{
public:
static vtkSocketCommunicator *New();
vtkTypeMacro(vtkSocketCommunicator,vtkCommunicator);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Wait for connection on a given port.
// These methods return 1 on success, 0 on error.
virtual int WaitForConnection(int port);
virtual int WaitForConnection(vtkServerSocket* socket,
unsigned long msec = 0);
// Description:
// Close a connection.
virtual void CloseConnection();
// Description:
// Open a connection to host.
virtual int ConnectTo(const char* hostName, int port);
// Description:
// Returns 1 if bytes must be swapped in received ints, floats, etc
vtkGetMacro(SwapBytesInReceivedData, int);
// Description:
// Is the communicator connected?.
int GetIsConnected();
// Description:
// Set the number of processes you will be using.
virtual void SetNumberOfProcesses(int num);
//------------------ Communication --------------------
// Description:
// Performs the actual communication. You will usually use the convenience
// Send functions defined in the superclass.
virtual int SendVoidArray(const void *data, vtkIdType length, int type,
int remoteHandle, int tag);
virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
int remoteHandle, int tag);
// Description:
// This class foolishly breaks the conventions of the superclass, so this
// overload fixes the method.
virtual void Barrier();
// Description:
// This class foolishly breaks the conventions of the superclass, so the
// default implementations of these methods do not work. These just give
// errors instead.
virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
int srcProcessId);
virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type, int destProcessId);
virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType sendLength, vtkIdType *recvLengths,
vtkIdType *offsets, int type, int destProcessId);
virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type, int srcProcessId);
virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType *sendLengths, vtkIdType *offsets,
vtkIdType recvLength, int type,
int srcProcessId);
virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type);
virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType sendLength, vtkIdType *recvLengths,
vtkIdType *offsets, int type);
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type,
int operation, int destProcessId);
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type,
Operation *operation, int destProcessId);
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type,
int operation);
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
vtkIdType length, int type,
Operation *operation);
// Description:
// Set or get the PerformHandshake ivar. If it is on, the communicator
// will try to perform a handshake when connected.
// It is on by default.
vtkSetClampMacro(PerformHandshake, int, 0, 1);
vtkBooleanMacro(PerformHandshake, int);
vtkGetMacro(PerformHandshake, int);
//BTX
// Description:
// Get/Set the output stream to which communications should be
// logged. This is intended as a debugging feature.
virtual void SetLogStream(ostream* stream);
virtual ostream* GetLogStream();
//ETX
// Description:
// Log messages to the given file. The file is truncated unless the
// second argument is non-zero (default is to truncate). If the
// file name is empty or NULL, logging is disabled. Returns 0 if
// the file failed to open, and 1 otherwise.
virtual int LogToFile(const char* name);
virtual int LogToFile(const char* name, int append);
// Description:
// If ReportErrors if false, all vtkErrorMacros are suppressed.
vtkSetMacro(ReportErrors, int);
vtkGetMacro(ReportErrors, int);
// Description:
// Get/Set the actual socket used for communication.
vtkGetObjectMacro(Socket, vtkClientSocket);
void SetSocket(vtkClientSocket*);
// Description:
// Performs handshake. This uses vtkClientSocket::ConnectingSide to decide
// whether to perform ServerSideHandshake or ClientSideHandshake.
int Handshake();
// Description:
// Performs ServerSide handshake.
// One should preferably use Handshake() which calls ServerSideHandshake or
// ClientSideHandshake as required.
int ServerSideHandshake();
// Description:
// Performs ClientSide handshake.
// One should preferably use Handshake() which calls ServerSideHandshake or
// ClientSideHandshake as required.
int ClientSideHandshake();
// Description:
// Returns true if this side of the socket is the server. The result
// is invalid if the socket is not connected.
vtkGetMacro(IsServer, int);
// Description:
// Uniquely identifies the version of this class. If the versions match,
// then the socket communicators should be compatible.
static int GetVersion();
// Description:
// This flag is cleared before vtkCommand::WrongTagEvent is fired when ever a
// message with mismatched tag is received. If the handler wants the message
// to be buffered for later use, it should set this flag to true. In which
// case the vtkSocketCommunicator will buffer the messsage and it will be
// automatically processed the next time one does a ReceiveTagged() with a
// matching tag.
void BufferCurrentMessage()
{ this->BufferMessage = true; }
// Description:
// Returns true if there are any messages in the receive buffer.
bool HasBufferredMessages();
//BTX
protected:
vtkClientSocket* Socket;
int SwapBytesInReceivedData;
int RemoteHas64BitIds;
int PerformHandshake;
int IsServer;
int ReportErrors;
ofstream* LogFile;
ostream* LogStream;
vtkSocketCommunicator();
~vtkSocketCommunicator();
// Wrappers around send/recv calls to implement loops. Return 1 for
// success, and 0 for failure.
int SendTagged(const void* data, int wordSize, int numWords, int tag,
const char* logName);
int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
const char* logName);
int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
const char* logName);
int ReceivedTaggedFromBuffer(
void* data, int wordSize, int numWords, int tag, const char* logName);
// Description:
// Fix byte order for received data.
void FixByteOrder(void* data, int wordSize, int numWords);
// Internal utility methods.
void LogTagged(const char* name, const void* data, int wordSize, int numWords,
int tag, const char* logName);
int CheckForErrorInternal(int id);
bool BufferMessage;
private:
vtkSocketCommunicator(const vtkSocketCommunicator&); // Not implemented.
void operator=(const vtkSocketCommunicator&); // Not implemented.
int SelectSocket(int socket, unsigned long msec);
// SwapBytesInReceiveData needs an invalid / not set.
// This avoids checking length of endian handshake.
enum ErrorIds {
SwapOff = 0,
SwapOn,
SwapNotSet
};
// One may be tempted to change this to a vtkIdType, but really an int is
// enough since we split messages > VTK_INT_MAX.
int TagMessageLength;
// Buffer to save messages received with different tag than requested.
class vtkMessageBuffer;
vtkMessageBuffer* ReceivedMessageBuffer;
//ETX
};
#endif
|