PLCnext API Documentation 24.6.0.58
ISocketService.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Ve/IServiceObject.hpp"
9
10namespace Arp { namespace System { namespace Ve
11{
12class ISocketService : public virtual IServiceObject
13{
14public: //typedefs
15 enum class SocketType
16 {
17 None = 0,
18 Tcp = 1,
19 Udp = 2
20 };
21
22 enum class SocketDomain
23 {
24 None = 0,
25 Ipv4 = 1,
26 Ipv6 = 2,
27 Local
28 };
29
30 enum class SocketBlockingMode
31 {
32 None = 0,
33 Blocking = 1,
34 NoneBlocking = 2
35 };
36
37 enum class SelectMode
38 {
39 SelectRead = 0,
40 SelectWrite = 1,
41 SelectConnect = 3,
42 SelectAccept = 4
43 };
44
45 enum class PollMode
46 {
47 None = 0,
48 Read = 1,
49 Write = 2,
50 Connect = 3,
51 Accept = 4
52 };
53
54 enum class ShutdownMode
55 {
56 Read = 0,
57 Write = 1,
58 ReadWrite = 2,
59 };
60
66 {
72 SocketOptionReuseAddress = 0x0004,
73
79 SocketOptionKeepAlive = 0x0008,
80
86 SocketOptionBroadcast = 0x0020,
87
91 SocketOptionLinger = 0x0080,
92
96 SocketOptionReceiveTimeout = 0x0200,
97
101 SocketOptionSendTimeout = 0x0800,
102
108 SocketOptionNoDelay = 1,
109
113 SocketOptionPeerCredentials = 2,
114
125 SocketOptionUserTimeout = 100,
126
133 SocketOptionKeepAliveIdleTime = 101,
134
141 SocketOptionKeepAliveProbeInterval = 102,
142
149 SocketOptionKeepAliveProbeCount = 103,
150 };
151
152
153 //error codes for socket from eclr
154 enum class SocketError
155 {
157 Success = 0,
159 Unspecified = -1,
161 Interrupted = (10000 + 4), //WSAEINTR
163 InvalidArgument = (10000 + 22), //WSAEINVAL
165 TooManyOpenSockets = (10000 + 24), //WSAEMFILE
167 WouldBlock = (10000 + 35), //WSAEWOULDBLOCK
169 InProgress = (10000 + 36), //WSAEINPROGRESS
171 AlreadyInProgress = (10000 + 37), //WSAEALREADY
173 NotSocket = (10000 + 38), //WSAENOTSOCK
175 DestinationAddressRequired = (10000 + 39), //WSAEDESTADDRREQ
180 MessageSize = (10000 + 40), //WSAEMSGSIZE
185 ProtoType = (10000 + 41), //WSAEPROTOTYPE
187 ProtocolOption = (10000 + 42), //WSAENOPROTOOPT
189 ProtocolNotSupported = (10000 + 43), //WSAEPROTONOSUPPORT
191 SocketNotSupported = (10000 + 44), //WSAESOCKTNOSUPPORT
193 OperationNotSupported = (10000 + 45), //WSAEOPNOTSUPP
195 ProtocolFamilyNotSupported = (10000 + 46), //WSAEPFNOSUPPORT
197 AddressFamilyNotSupported = (10000 + 47), //WSAEAFNOSUPPORT
199 AddressAlreadyInUse = (10000 + 48), //WSAEADDRINUSE
201 AddressNotAvailable = (10000 + 49), //WSAEADDRNOTAVAIL
203 NetworkDown = (10000 + 50), //WSAENETDOWN
205 NetworkUnreachable = (10000 + 51), //WSAENETUNREACH
207 NetworkReset = (10000 + 52), //WSAENETRESET
209 ConnectionAborted = (10000 + 53), //WSAECONNABORTED
211 ConnectionReset = (10000 + 54), //WSAECONNRESET
213 NoBufferSpaceAvailable = (10000 + 55), //WSAENOBUFS
215 IsConnected = (10000 + 56), //WSAEISCONN
220 NotConnected = (10000 + 57), //WSAENOTCONN
225 Shutdown = (10000 + 58), //WSAESHUTDOWN
230 TimedOut = (10000 + 60), //WSAETIMEDOUT
232 ConnectionRefused = (10000 + 61), //WSAECONNREFUSED
234 HostDown = (10000 + 64), //WSAEHOSTDOWN
236 HostUnreachable = (10000 + 65), //WSAEHOSTUNREACH
238 ProcessLimit = (10000 + 67), //WSAEPROCLIM
243 SystemNotReady = (10000 + 91), //WSASYSNOTREADY
245 VersionNotSupported = (10000 + 92), //WSAVERNOTSUPPORTED
247 NotInitialized = (10000 + 93), //WSANOTINITIALISED
249 Disconnecting = (10000 + 101), //WSAEDISCON
251 HostNotFound = (10000 + 1001), //WSAHOST_NOT_FOUND
256 TryAgain = (10000 + 1002) //WSATRY_AGAIN
257 };
258
260 {
261 int uid = -1;
262 int gid = -1;
263 int pid = -1;
264 };
265
266public: // methods
267 virtual SocketError Bind(uint32 ip4Address, int& port) = 0;
268 virtual SocketError Bind(const String& path) = 0;
269 virtual ISocketService* Accept(uint32& ip4Address, int& port, SocketError& error) = 0;
270 virtual ISocketService* Accept(String& path, SocketError& error) = 0;
271 virtual SocketError Connect(uint32 ip4Address, int port) = 0;
272 virtual SocketError Connect(const String& path) = 0;
273 virtual SocketError Listen(int backlog) = 0;
274 virtual SocketError SetSockOpt(SocketOptionName optionName, const void* optionValue, size_t optionLength) = 0;
275 virtual SocketError GetSockOpt(SocketOptionName optionName, void* optionValue, size_t *optionLength) = 0;
276 virtual int Select(SelectMode mode, size_t timeout_us, SocketError& error) = 0;
277 virtual int Poll(PollMode mode, size_t timeoutMillis, SocketError& error) = 0;
278 virtual SocketError Close(void) = 0;
279 virtual SocketError Shutdown(void) = 0;
280 virtual SocketError Shutdown(ShutdownMode mode) = 0;
281 virtual int Send(const void* pBuffer, size_t len, SocketError& error) = 0;
282 virtual int SendTo(const void* pBuffer, size_t len, SocketError& error, uint32 ip4Address, int port) = 0;
283 virtual int Recv(void* pBuffer, size_t len, SocketError& error) = 0;
284 virtual int RecvFrom(void* pBuffer, size_t len, SocketError& error, uint32& ip4Address, int& port) = 0;
285 virtual SocketError SetOptionBlocking(bool enable) = 0;
286
287 virtual SocketError SetOptionLinger(bool enable, size_t timeout) = 0;
288 virtual SocketError GetOptionLinger(bool& enable, size_t& timeout) = 0;
289
290 virtual SocketError SetOptionUserTimeout(size_t timeout_ms) = 0;
291 virtual SocketError GetOptionUserTimeout(size_t& timeout_ms) = 0;
292
293 virtual SocketError SetOptionKeepAliveIdleTime(int seconds) = 0;
294 virtual SocketError GetOptionKeepAliveIdleTime(int& seconds) = 0;
295 virtual SocketError SetOptionKeepAliveProbeInterval(int seconds) = 0;
296 virtual SocketError GetOptionKeepAliveProbeInterval(int& seconds) = 0;
297 virtual SocketError SetOptionKeepAliveProbeCount(int probeCount) = 0;
298 virtual SocketError GetOptionKeepAliveProbeCount(int& probeCount) = 0;
299
300 virtual intptr GetNativeHandle() const = 0;
301 virtual PeerCredentials GetPeerCredentials(SocketError& error) = 0;
302};
303
304}}} // end of namespace Arp::System::Ve
Definition: IServiceObject.hpp:14
Definition: ISocketService.hpp:13
SocketOptionName
Specifies socket options to be set by the application. Copied from Eclr Socket Adaption
Definition: ISocketService.hpp:66
SocketError
Definition: ISocketService.hpp:155
ShutdownMode
Definition: ISocketService.hpp:55
uint32 intptr
The Arp integer type matching pointer size.
Definition: TypeSystem.h:85
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:36
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API
Definition: ISocketService.hpp:260