VTK  9.5.20251126
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
10
11#ifndef vtkSocket_h
12#define vtkSocket_h
13
14#include "vtkCommonSystemModule.h" // For export macro
15#include "vtkObject.h"
16
17VTK_ABI_NAMESPACE_BEGIN
19class VTKCOMMONSYSTEM_EXPORT vtkSocket : public vtkObject
20{
21public:
22 vtkTypeMacro(vtkSocket, vtkObject);
23 void PrintSelf(ostream& os, vtkIndent indent) override;
24
25 // ----- Status API ----
29 int GetConnected() { return (this->SocketDescriptor >= 0); }
30
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
72protected:
74 ~vtkSocket() override;
75
77
78 friend class vtkSocketCollection;
79
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
130private:
131 std::string BoundAddress;
132
133 vtkSocket(const vtkSocket&) = delete;
134 void operator=(const vtkSocket&) = delete;
135};
136
137VTK_ABI_NAMESPACE_END
138#endif
a simple class to control print indentation
Definition vtkIndent.h:108
a collection for sockets.
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.
friend class vtkSocketCollection
Definition vtkSocket.h:78
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, const std::string &bindAddr)
Binds socket to a particular port and IPv4 address if specified.
int BindSocket(int socketdescriptor, int port)
Binds socket to a particular port and IPv4 address if specified.
int GetPort(int socketdescriptor)
Returns the port to which the socket is connected.
~vtkSocket() override
int SocketDescriptor
Definition vtkSocket.h:76
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.