VTK  9.7.1
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 
62  vtkGetMacro(BoundAddress, std::string);
63 
69  static int SelectSockets(
70  const int* sockets_to_select, int size, unsigned long msec, int* selected_index);
71 
72 protected:
73  vtkSocket();
74  ~vtkSocket() override;
75 
77 
78  friend class vtkSocketCollection;
79 
84  int CreateSocket();
85 
89  void CloseSocket(int socketdescriptor);
90 
92 
97  int BindSocket(int socketdescriptor, int port, const std::string& bindAddr);
98  int BindSocket(int socketdescriptor, int port);
100 
106  int SelectSocket(int socketdescriptor, unsigned long msec);
107 
112  int Accept(int socketdescriptor);
113 
117  int Listen(int socketdescriptor);
118 
122  int Connect(int socketdescriptor, const char* hostname, int port);
123 
128  int GetPort(int socketdescriptor);
129 
130 private:
131  std::string BoundAddress;
132 
133  vtkSocket(const vtkSocket&) = delete;
134  void operator=(const vtkSocket&) = delete;
135 };
136 
137 VTK_ABI_NAMESPACE_END
138 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a collection for sockets.
int SocketDescriptor
Definition: vtkSocket.h:76
int GetConnected()
Check is the socket is alive.
Definition: vtkSocket.h:29
a simple class to control print indentation
Definition: vtkIndent.h:28
BSD socket encapsulation.
Definition: vtkSocket.h:19