Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
industrial::simple_socket::SimpleSocket Class Referenceabstract

Defines socket functions required for a simple connection type. More...

#include <simple_socket.h>

Inheritance diagram for industrial::simple_socket::SimpleSocket:
Inheritance graph
[legend]

Public Member Functions

bool isConnected ()
 return connection status More...
 
bool isReadyReceive (int timeout)
 returns true if socket data is ready to receive More...
 
virtual void setDisconnected ()
 
 SimpleSocket ()
 Constructor. More...
 
virtual ~SimpleSocket ()
 Destructor. More...
 
- Public Member Functions inherited from industrial::smpl_msg_connection::SmplMsgConnection
virtual bool makeConnect ()=0
 connects to the remote host More...
 
virtual bool receiveMsg (industrial::simple_message::SimpleMessage &message)
 Receives a message using the data connection. More...
 
virtual bool receiveMsg (industrial::simple_message::SimpleMessage &message, industrial::shared_types::shared_int timeout_ms)
 Receives a message using the data connection with a timeout. More...
 
bool sendAndReceiveMsg (industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, bool verbose=false)
 Performs a complete send and receive. This is helpful when sending a message that requires and explicit reply. More...
 
bool sendAndReceiveMsg (industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, industrial::shared_types::shared_int timeout_ms, bool verbose=false)
 Performs a complete send and receive with a timeout. This is helpful when sending a message that requires and explicit reply. More...
 
virtual bool sendMsg (industrial::simple_message::SimpleMessage &message)
 Sends a message using the data connection. More...
 

Protected Member Functions

 __attribute__ ((deprecated("Please use: logSocketError(const char* msg, const int rc, const int error_no)"))) void logSocketError(const char *msg
 Logs message to error log and reports associated socket system error. More...
 
int getSockHandle () const
 
void logSocketError (const char *msg, const int rc, const int error_no)
 Logs message to error log and reports associated socket system error. More...
 
virtual bool rawPoll (int timeout, bool &ready, bool &error)=0
 polls socket for data or error More...
 
virtual int rawReceiveBytes (char *buffer, industrial::shared_types::shared_int num_bytes)=0
 
virtual int rawSendBytes (char *buffer, industrial::shared_types::shared_int num_bytes)=0
 
bool receiveBytes (industrial::byte_array::ByteArray &buffer, industrial::shared_types::shared_int num_bytes, industrial::shared_types::shared_int timeout_ms)
 Method used by receive message interface method. This should be overridden for the specific connection type. More...
 
bool sendBytes (industrial::byte_array::ByteArray &buffer)
 Method used by send message interface method. This should be overridden for the specific connection type. More...
 
virtual void setConnected (bool connected)
 
void setSockHandle (int sock_handle_)
 

Protected Attributes

char buffer_ [MAX_BUFFER_SIZE+1]
 internal data buffer for receiving More...
 
bool connected_
 flag indicating socket connection status More...
 
int rc
 
int sock_handle_
 socket handle for sending/receiving data More...
 
sockaddr_in sockaddr_
 address/port of remote socket More...
 

Static Protected Attributes

static const int MAX_BUFFER_SIZE = 1024
 maximum size of buffer for receiving data (fixed memory size used in order to avoid dynamic memory allocation) More...
 
static const int SOCKET_FAIL = -1
 socket fail return value More...
 
static const int SOCKET_POLL_TO = 10
 socket ready polling timeout (ms) More...
 

Detailed Description

Defines socket functions required for a simple connection type.

Definition at line 149 of file simple_socket.h.

Constructor & Destructor Documentation

◆ SimpleSocket()

industrial::simple_socket::SimpleSocket::SimpleSocket ( )
inline

Constructor.

Definition at line 156 of file simple_socket.h.

◆ ~SimpleSocket()

virtual industrial::simple_socket::SimpleSocket::~SimpleSocket ( )
inlinevirtual

Destructor.

Definition at line 166 of file simple_socket.h.

Member Function Documentation

◆ __attribute__()

industrial::simple_socket::SimpleSocket::__attribute__ ( (deprecated( "Please use: logSocketError(const char* msg, const int rc, const int error_no)"))  ) const
protected

Logs message to error log and reports associated socket system error.

Deprecated:
This could report the wrong error number. The method that takes errno as an argument should be used instead.
Parameters
msgcustom message prefixed to system error
rcreturn code from socket

◆ getSockHandle()

int industrial::simple_socket::SimpleSocket::getSockHandle ( ) const
inlineprotected

Definition at line 233 of file simple_socket.h.

◆ isConnected()

bool industrial::simple_socket::SimpleSocket::isConnected ( )
inlinevirtual

return connection status

Returns
true if connected

Implements industrial::smpl_msg_connection::SmplMsgConnection.

Definition at line 168 of file simple_socket.h.

◆ isReadyReceive()

bool industrial::simple_socket::SimpleSocket::isReadyReceive ( int  timeout)
inline

returns true if socket data is ready to receive

Parameters
timeout(ms) negative or zero values result in blocking
Returns
true if data is ready to recieve

Definition at line 188 of file simple_socket.h.

◆ logSocketError()

void industrial::simple_socket::SimpleSocket::logSocketError ( const char *  msg,
const int  rc,
const int  error_no 
)
inlineprotected

Logs message to error log and reports associated socket system error.

Parameters
msgcustom message prefixed to system error
rcreturn code from socket
error_noerrno value see (http://man7.org/linux/man-pages/man3/errno.3.html )

Definition at line 265 of file simple_socket.h.

◆ rawPoll()

virtual bool industrial::simple_socket::SimpleSocket::rawPoll ( int  timeout,
bool &  ready,
bool &  error 
)
protectedpure virtual

polls socket for data or error

Parameters
timeout(ms) negative or zero values result in blocking
readytrue if ready
excepttrue if exception
Returns
true if function DID NOT timeout (must check flags)

Implemented in industrial::udp_socket::UdpSocket, and industrial::tcp_socket::TcpSocket.

◆ rawReceiveBytes()

virtual int industrial::simple_socket::SimpleSocket::rawReceiveBytes ( char *  buffer,
industrial::shared_types::shared_int  num_bytes 
)
protectedpure virtual

◆ rawSendBytes()

virtual int industrial::simple_socket::SimpleSocket::rawSendBytes ( char *  buffer,
industrial::shared_types::shared_int  num_bytes 
)
protectedpure virtual

◆ receiveBytes()

bool industrial::simple_socket::SimpleSocket::receiveBytes ( industrial::byte_array::ByteArray buffer,
industrial::shared_types::shared_int  num_bytes,
industrial::shared_types::shared_int  timeout_ms 
)
protectedvirtual

Method used by receive message interface method. This should be overridden for the specific connection type.

Parameters
datato receive.
size(in bytes) of data to receive
timeout_msTimeout to receive a message (in milliseconds). A negative timeout means that this function should wait indefinitely.
Returns
true if successful

Implements industrial::smpl_msg_connection::SmplMsgConnection.

Reimplemented in TestServer.

Definition at line 98 of file simple_socket.cpp.

◆ sendBytes()

bool industrial::simple_socket::SimpleSocket::sendBytes ( industrial::byte_array::ByteArray buffer)
protectedvirtual

Method used by send message interface method. This should be overridden for the specific connection type.

Parameters
datato send.
Returns
true if successful

Implements industrial::smpl_msg_connection::SmplMsgConnection.

Reimplemented in TestClient.

Definition at line 48 of file simple_socket.cpp.

◆ setConnected()

virtual void industrial::simple_socket::SimpleSocket::setConnected ( bool  connected)
inlineprotectedvirtual

Definition at line 292 of file simple_socket.h.

◆ setDisconnected()

virtual void industrial::simple_socket::SimpleSocket::setDisconnected ( )
inlinevirtual

Definition at line 176 of file simple_socket.h.

◆ setSockHandle()

void industrial::simple_socket::SimpleSocket::setSockHandle ( int  sock_handle_)
inlineprotected

Definition at line 238 of file simple_socket.h.

Member Data Documentation

◆ buffer_

char industrial::simple_socket::SimpleSocket::buffer_[MAX_BUFFER_SIZE+1]
protected

internal data buffer for receiving

Definition at line 231 of file simple_socket.h.

◆ connected_

bool industrial::simple_socket::SimpleSocket::connected_
protected

flag indicating socket connection status

Definition at line 210 of file simple_socket.h.

◆ MAX_BUFFER_SIZE

const int industrial::simple_socket::SimpleSocket::MAX_BUFFER_SIZE = 1024
staticprotected

maximum size of buffer for receiving data (fixed memory size used in order to avoid dynamic memory allocation)

Definition at line 221 of file simple_socket.h.

◆ rc

int industrial::simple_socket::SimpleSocket::rc
protected
Initial value:
{
logSocketError(msg, rc, errno)

Definition at line 255 of file simple_socket.h.

◆ sock_handle_

int industrial::simple_socket::SimpleSocket::sock_handle_
protected

socket handle for sending/receiving data

Definition at line 200 of file simple_socket.h.

◆ sockaddr_

sockaddr_in industrial::simple_socket::SimpleSocket::sockaddr_
protected

address/port of remote socket

Definition at line 205 of file simple_socket.h.

◆ SOCKET_FAIL

const int industrial::simple_socket::SimpleSocket::SOCKET_FAIL = -1
staticprotected

socket fail return value

Definition at line 215 of file simple_socket.h.

◆ SOCKET_POLL_TO

const int industrial::simple_socket::SimpleSocket::SOCKET_POLL_TO = 10
staticprotected

socket ready polling timeout (ms)

Definition at line 226 of file simple_socket.h.


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


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Jul 19 2021 12:45:19