VTK  9.3.0
vtkSocket.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
11 #ifndef vtkSocket_h
12 #define vtkSocket_h
13 
14 #include "vtkCommonSystemModule.h" // For export macro
15 #include "vtkObject.h"
16 
17 VTK_ABI_NAMESPACE_BEGIN
19 class VTKCOMMONSYSTEM_EXPORT vtkSocket : public vtkObject
20 {
21 public:
22  vtkTypeMacro(vtkSocket, vtkObject);
23  void PrintSelf(ostream& os, vtkIndent indent) override;
24 
25  // ----- Status API ----
29  int GetConnected() { return (this->SocketDescriptor >= 0); }
30 
34  void CloseSocket();
35 
36  // ------ Communication API ---
41  int Send(const void* data, int length);
42 
51  int Receive(void* data, int length, int readFully = 1);
52 
57  vtkGetMacro(SocketDescriptor, int);
58 
64  static int SelectSockets(
65  const int* sockets_to_select, int size, unsigned long msec, int* selected_index);
66 
67 protected:
69  ~vtkSocket() override;
70 
72 
73  friend class vtkSocketCollection;
74 
79  int CreateSocket();
80 
84  void CloseSocket(int socketdescriptor);
85 
90  int BindSocket(int socketdescriptor, int port);
91 
97  int SelectSocket(int socketdescriptor, unsigned long msec);
98 
103  int Accept(int socketdescriptor);
104 
108  int Listen(int socketdescriptor);
109 
113  int Connect(int socketdescriptor, const char* hostname, int port);
114 
119  int GetPort(int socketdescriptor);
120 
121 private:
122  vtkSocket(const vtkSocket&) = delete;
123  void operator=(const vtkSocket&) = delete;
124 };
125 
126 VTK_ABI_NAMESPACE_END
127 #endif
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
a collection for sockets.
BSD socket encapsulation.
Definition: vtkSocket.h:20
void CloseSocket()
Close the socket.
int CreateSocket()
Creates an endpoint for communication and returns the descriptor.
static int SelectSockets(const int *sockets_to_select, int size, unsigned long msec, int *selected_index)
Selects set of sockets.
int Accept(int socketdescriptor)
Accept a connection on a socket.
int SelectSocket(int socketdescriptor, unsigned long msec)
Selects a socket ie.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Listen(int socketdescriptor)
Listen for connections on a socket.
int GetConnected()
Check is the socket is alive.
Definition: vtkSocket.h:29
void CloseSocket(int socketdescriptor)
Close the socket.
int BindSocket(int socketdescriptor, int port)
Binds socket to a particular port.
int GetPort(int socketdescriptor)
Returns the port to which the socket is connected.
~vtkSocket() override
int SocketDescriptor
Definition: vtkSocket.h:71
int Connect(int socketdescriptor, const char *hostname, int port)
Connect to a server socket.
int Receive(void *data, int length, int readFully=1)
Receive data from the socket.
int Send(const void *data, int length)
These methods send data over the socket.
@ length
Definition: vtkX3D.h:393
@ port
Definition: vtkX3D.h:447
@ size
Definition: vtkX3D.h:253
@ data
Definition: vtkX3D.h:315