PdCom  5.2
Process data communication client
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PdCom::PosixProcess Class Reference

Wrapper around POSIX socket. More...

#include <PosixProcess.h>

Public Member Functions

 PosixProcess (const char *host, unsigned short port)
 Constructor. More...
 
 PosixProcess (int fd)
 Constructor. More...
 
 PosixProcess (PosixProcess &&o)=delete
 
 PosixProcess (PosixProcess const &)=delete
 
PosixProcessoperator= (PosixProcess &&o)=delete
 
PosixProcessoperator= (PosixProcess const &)=delete
 

Protected Member Functions

void posixWriteBuffered (const char *buf, size_t count)
 Buffered Wrapper for write(). More...
 
void posixWriteDirect (const char *buf, size_t count)
 Unbuffered Wrapper for write(). More...
 
int posixRead (char *buf, int count)
 Wrapper for read(). More...
 
void posixFlush ()
 Flush internal buffer to socket. More...
 
void setWriteTimeout (std::chrono::milliseconds ms)
 Timeout for posixWriteDirect() in non-blocking mode. More...
 
void reconnect (const char *host, unsigned short port)
 Establish a new connection. More...
 

Protected Attributes

int fd_
 File descriptior of the socket.
 

Detailed Description

Wrapper around POSIX socket.

You can derive from this class to use POSIX socket with your Process instance.

Examples:
advanced_example.cpp, gnutls_example.cpp, and sasl_example.cpp.

Constructor & Destructor Documentation

◆ PosixProcess() [1/2]

PdCom::PosixProcess::PosixProcess ( const char *  host,
unsigned short  port 
)

Constructor.

Parameters
hostHost, can be a hostname or an IP(v6) address.
portPort
Exceptions
ConnectionFailedConnection could not be established.

◆ PosixProcess() [2/2]

PdCom::PosixProcess::PosixProcess ( int  fd)
explicit

Constructor.

Parameters
fdFile descriptor, assumed to be connected, will be closed by dtor.

Member Function Documentation

◆ posixFlush()

void PdCom::PosixProcess::posixFlush ( )
protected

Flush internal buffer to socket.

If the socket works in nonblocking mode, it will be select()ed with a timeout set by setWriteTimeout() until everything is written.

Exceptions
WriteFailurewrite() to socket fails.
Examples:
advanced_example.cpp, and sasl_example.cpp.

◆ posixRead()

int PdCom::PosixProcess::posixRead ( char *  buf,
int  count 
)
protected

Wrapper for read().

Parameters
bufBuffer to read into.
countSize of the buffer in bytes.
Returns
Number of bytes read, 0 for EOF or -EAGAIN or -EINTR.
Exceptions
ReadFailureread() from socket fails.
Examples:
advanced_example.cpp, gnutls_example.cpp, and sasl_example.cpp.

◆ posixWriteBuffered()

void PdCom::PosixProcess::posixWriteBuffered ( const char *  buf,
size_t  count 
)
protected

Buffered Wrapper for write().

This loops around write(), so no short writes can occur. It uses an internal buffer which can be flushed used posixFlush(). If the buffer is not big enough, it will be flushed and the content of buf is written directly to the socket using posixWriteDirect().

If the socket works in nonblocking mode, it will be select()ed with a timeout set by setWriteTimeout() until everything is written.

Parameters
bufBuffer to send.
countNumber of bytes to send.
Exceptions
WriteFailurewrite() to socket fails.
Examples:
advanced_example.cpp, and sasl_example.cpp.

◆ posixWriteDirect()

void PdCom::PosixProcess::posixWriteDirect ( const char *  buf,
size_t  count 
)
protected

Unbuffered Wrapper for write().

This loops around write(), so no short writes can occur. No internal buffer is used. If you used posixWriteBuffered() before, you'll have to flush() the internal buffer. Otherwise your data will be corrupted.

If the socket works in nonblocking mode, it will be select()ed with a timeout set by setWriteTimeout() until everything is written.

Parameters
bufBuffer to send.
countNumber of bytes to send.
Exceptions
WriteFailurewrite() to socket fails.
Examples:
gnutls_example.cpp.

◆ reconnect()

void PdCom::PosixProcess::reconnect ( const char *  host,
unsigned short  port 
)
protected

Establish a new connection.

The internal buffer will be cleared, too.

Parameters
hostHost, can be a hostname or an IP(v6) address.
portPort
Exceptions
ConnectionFailedConnection could not be established.

◆ setWriteTimeout()

void PdCom::PosixProcess::setWriteTimeout ( std::chrono::milliseconds  ms)
protected

Timeout for posixWriteDirect() in non-blocking mode.

Parameters
msTimeout.

The documentation for this class was generated from the following file: