PLCnext API Documentation
21.0.0.35466
|
Socket for interprocess communication between processes on the same controller. More...
#include <IpcSocket.hpp>
Public Types | |
typedef std::shared_ptr< IpcSocket > | Ptr |
Contextual definition of pointer type. More... | |
using | SelectMode = Arp::System::Commons::Net::SelectMode |
Contextual definition of available select modes. More... | |
Public Member Functions | |
IpcSocket (bool blocking=true) | |
Constructs a new socket for interprocess communication. More... | |
~IpcSocket (void) | |
Closes the socket and releases all ressources. More... | |
IpcSocketError | Bind (const Arp::String &path) |
Assigns an address to this socket so that other process can connect with it. More... | |
IpcSocketError | Listen (size_t backlog) |
Marks this socket as a passive socket that accepts incoming connection requests. More... | |
IpcSocketError | Connect (const Arp::String &path) |
Tries to connect with a remote socket. More... | |
bool | Select (SelectMode mode, Microseconds timeout, IpcSocketError &error) |
Checks if an i/o operation can be performed without blocking the calling thread. More... | |
Ptr | Accept (IpcSocketError &error) |
Accepts a pending connection request. More... | |
IpcSocketError | Shutdown (void) |
Shuts down a connection. More... | |
IpcSocketError | Close (void) |
Closes the socket. This ends all communication on the socket. More... | |
int | Send (const void *pBuffer, size_t length, IpcSocketError &error) |
Transmit data over the socket that is in a connected state. More... | |
int | Receive (void *pBuffer, size_t length, IpcSocketError &error) |
Reads data from connected socket. More... | |
Socket for interprocess communication between processes on the same controller.
In contrast to instances of Arp::System::Commons::Net::Socket instances of this class can only be used to perform communication between processes on the same controller. The benefit of using an IpcSocket instead of a common Socket is that the API remains the same but the underlying mechanism is optimized for speed and performance by not using a complete network stack like TCP/IP and is thus much more lightweight.
IpcSockets can be used in a similar manner as normal TCP-sockets. A server needs a socket listening for incoming connection requests of clients. If such a request is processed a new socket instance is created that provides an endport for the communication between the server process and the client process. Server and client can then exchange data using binary read and write calls.
typedef std::shared_ptr<IpcSocket> Arp::System::Commons::Ipc::IpcSocket::Ptr |
Contextual definition of pointer type.
Contextual definition of available select modes.
Arp::System::Commons::Ipc::IpcSocket::IpcSocket | ( | bool | blocking = true | ) |
Constructs a new socket for interprocess communication.
blocking | Indicates if calls to accept and receive block until data is available or not. |
Arp::System::Commons::Ipc::IpcSocket::~IpcSocket | ( | void | ) |
Closes the socket and releases all ressources.
Ptr Arp::System::Commons::Ipc::IpcSocket::Accept | ( | IpcSocketError & | error | ) |
Accepts a pending connection request.
Before a socket can accept connection requests, it must be Bind with an address and must be set to Listen state.
If no connection request is pending and the socket is in
Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.
error | Holds error code in case the method returns nullptr. |
IpcSocketError Arp::System::Commons::Ipc::IpcSocket::Bind | ( | const Arp::String & | path | ) |
Assigns an address to this socket so that other process can connect with it.
path | to connect to. |
IpcSocketError Arp::System::Commons::Ipc::IpcSocket::Close | ( | void | ) |
Closes the socket. This ends all communication on the socket.
If this socket is bound to a file the file will be removed.
IpcSocketError Arp::System::Commons::Ipc::IpcSocket::Connect | ( | const Arp::String & | path | ) |
Tries to connect with a remote socket.
Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.
path | Name of socket to connect with. |
IpcSocketError Arp::System::Commons::Ipc::IpcSocket::Listen | ( | size_t | backlog | ) |
Marks this socket as a passive socket that accepts incoming connection requests.
A socket in listening state features an internal queue where incoming connection requests are stored until they are processed by an Accept invocation. The maximal capacity of this queue is determined by the parameter backlog. If a connection request arrives while the queue is filled, the client may receive an error telling that the connection is refused or, if the utilized protocol allows retransmissions, the request may be ignored so that a consecutive reattempt to connnect may succeed.
backlog | Defines the maximum number of pending connection requests. |
int Arp::System::Commons::Ipc::IpcSocket::Receive | ( | void * | pBuffer, |
size_t | length, | ||
IpcSocketError & | error | ||
) |
Reads data from connected socket.
pBuffer | Pointer to buffer where read data can be stored. |
length | Capacity in bytes of buffer pBuffer. |
error | Container variable holding error code after call returned. |
bool Arp::System::Commons::Ipc::IpcSocket::Select | ( | SelectMode | mode, |
Microseconds | timeout, | ||
IpcSocketError & | error | ||
) |
Checks if an i/o operation can be performed without blocking the calling thread.
mode | Determines the i/o operation to be checked. |
timeout | Specifies the time to wait for the socket to be ready for the i/o operation. If set to zero, the call will return immediately. |
error | Container variable holding error code after call returned. |
int Arp::System::Commons::Ipc::IpcSocket::Send | ( | const void * | pBuffer, |
size_t | length, | ||
IpcSocketError & | error | ||
) |
Transmit data over the socket that is in a connected state.
pBuffer | Pointer to buffer containing serialized data to be send. |
length | Amount of bytes to be send. |
error | Container variable holding error code after call returned. |
IpcSocketError Arp::System::Commons::Ipc::IpcSocket::Shutdown | ( | void | ) |
Shuts down a connection.
After the shutdown has been called, further reception and transmission on the socket is disallowed.