PLCnext API Documentation  22.9.0.33
IpcSocket.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Net/PollMode.hpp"
9 #include "Arp/System/Commons/Net/SelectMode.hpp"
10 #include "Arp/System/Commons/Net/ShutdownMode.hpp"
11 #include "Arp/System/Commons/Ipc/IpcSocketError.hpp"
12 
13 // forwards
14 namespace Arp { namespace System { namespace Ve
15 {
16 class ISocketService;
17 }}}
18 
19 namespace Arp { namespace System { namespace Commons { namespace Ipc
20 {
21 
33 class IpcSocket
34 {
35 
36 public: // typedefs/usings
37 
39  typedef std::shared_ptr<IpcSocket> Ptr;
40 
43 
46 
49 
50 private: // typedefs/usings
51  using ISocketService = Arp::System::Ve::ISocketService;
52 
53 public: // construction/destruction
56  IpcSocket(bool blocking = true);
58  IpcSocket(const IpcSocket& arg) = delete;
60  IpcSocket(IpcSocket&& arg) = default;
62  IpcSocket& operator=(const IpcSocket& arg) = delete;
64  ~IpcSocket(void);
65 
66 private: // construction/destruction
67  IpcSocket(ISocketService *pSocket);
68 
69 public: // operations
70 
77 
89  IpcSocketError Listen(size_t backlog);
90 
100 
109  bool Select(SelectMode mode, Microseconds timeout, IpcSocketError& error);
110 
124  int Poll(PollMode mode, Milliseconds timeout, IpcSocketError& error);
125 
142 
149 
154 
161 
169  int Send(const void *pBuffer, size_t length, IpcSocketError& error);
170 
178  int Receive(void *pBuffer, size_t length, IpcSocketError& error);
179 
180 private: // fields
181 
182  ISocketService *pSocketService;
183 
184 };
185 
186 }}}}
Socket for interprocess communication between processes on the same controller.
Definition: IpcSocket.hpp:34
IpcSocket & operator=(const IpcSocket &arg)=delete
Assignment operator is deleted.
int Poll(PollMode mode, Milliseconds timeout, IpcSocketError &error)
Checks if an i/o operation can be processed without blocking.
~IpcSocket(void)
Closes the socket and releases all ressources.
int Receive(void *pBuffer, size_t length, IpcSocketError &error)
Reads data from connected socket.
IpcSocket(bool blocking=true)
Constructs a new socket for interprocess communication.
bool Select(SelectMode mode, Microseconds timeout, IpcSocketError &error)
Checks if an i/o operation can be performed without blocking the calling thread.
std::shared_ptr< IpcSocket > Ptr
Contextual definition of pointer type.
Definition: IpcSocket.hpp:39
Ptr Accept(IpcSocketError &error)
Accepts a pending connection request.
IpcSocketError Listen(size_t backlog)
Marks this socket as a passive socket that accepts incoming connection requests.
IpcSocketError Connect(const Arp::String &path)
Tries to connect with a remote socket.
IpcSocketError Shutdown(void)
Shuts down a connection.
IpcSocketError Bind(const Arp::String &path)
Assigns an address to this socket so that other process can connect with it.
int Send(const void *pBuffer, size_t length, IpcSocketError &error)
Transmit data over the socket that is in a connected state.
IpcSocket(const IpcSocket &arg)=delete
Copy constructor is deleted.
IpcSocketError Shutdown(ShutdownMode mode)
Shuts down a connection.
IpcSocketError Close(void)
Closes the socket. This ends all communication on the socket.
IpcSocket(IpcSocket &&arg)=default
Move constructor.
std::chrono::milliseconds Milliseconds
The Arp Milliseconds unit class.
Definition: TypeSystem.h:36
std::chrono::microseconds Microseconds
The Arp Microseconds unit class.
Definition: TypeSystem.h:34
@ System
System components used by the System, Device, Plc or Io domains.
IpcSocketError
Enumeration of possible error return codes from IpcSocket operations.
Definition: IpcSocketError.hpp:14
PollMode
This enum is used to specifiy the poll mode of the <cref name="Socket::Poll" > operation.
Definition: PollMode.hpp:15
SelectMode
Modes for Select call to check different data channels.
Definition: SelectMode.hpp:14
ShutdownMode
This enum is used to specifiy the shutdown mode of the <cref name="Socket::Shutdown(ShutdownMode)" > ...
Definition: ShutdownMode.hpp:15
Root namespace for the PLCnext API