VTK
vtkSocket.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSocket.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
23 #ifndef vtkSocket_h
24 #define vtkSocket_h
25 
26 #include "vtkCommonSystemModule.h" // For export macro
27 #include "vtkObject.h"
28 
30 class VTKCOMMONSYSTEM_EXPORT vtkSocket : public vtkObject
31 {
32 public:
33  vtkTypeMacro(vtkSocket, vtkObject);
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
36  // ----- Status API ----
40  int GetConnected() { return (this->SocketDescriptor >=0); }
41 
45  void CloseSocket();
46 
47  // ------ Communication API ---
52  int Send(const void* data, int length);
53 
62  int Receive(void* data, int length, int readFully=1);
63 
68  vtkGetMacro(SocketDescriptor, int);
69 
75  static int SelectSockets(const int* sockets_to_select, int size,
76  unsigned long msec, int* selected_index);
77 
78 protected:
79  vtkSocket();
80  ~vtkSocket() override;
81 
83 
84  friend class vtkSocketCollection;
85 
90  int CreateSocket();
91 
95  void CloseSocket(int socketdescriptor);
96 
101  int BindSocket(int socketdescriptor, int port);
102 
108  int SelectSocket(int socketdescriptor, unsigned long msec);
109 
114  int Accept(int socketdescriptor);
115 
119  int Listen(int socketdescriptor);
120 
124  int Connect(int socketdescriptor, const char* hostname, int port);
125 
130  int GetPort(int socketdescriptor);
131 
132 private:
133  vtkSocket(const vtkSocket&) = delete;
134  void operator=(const vtkSocket&) = delete;
135 };
136 
137 
138 #endif
139 
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:82
int GetConnected()
Check is the socket is alive.
Definition: vtkSocket.h:40
a simple class to control print indentation
Definition: vtkIndent.h:39
BSD socket encapsulation.
Definition: vtkSocket.h:30