Defines socket functions required for a simple connection type. More...
#include <simple_socket.h>
Public Member Functions | |
bool | isConnected () |
return connection status | |
bool | isReadyReceive (int timeout) |
returns true if socket data is ready to receive | |
SimpleSocket () | |
Constructor. | |
virtual | ~SimpleSocket () |
Destructor. | |
Protected Member Functions | |
int | getSockHandle () const |
void | logSocketError (const char *msg, int rc) |
bool | poll (int timeout, bool &ready, bool &error) |
polls socket for data or error | |
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) |
Method used by receive message interface method. This should be overridden for the specific connection type. | |
bool | sendBytes (industrial::byte_array::ByteArray &buffer) |
Method used by send message interface method. This should be overridden for the specific connection type. | |
virtual void | setConnected (bool connected) |
void | setSockHandle (int sock_handle_) |
Protected Attributes | |
char | buffer_ [MAX_BUFFER_SIZE+1] |
internal data buffer for receiving | |
bool | connected_ |
flag indicating socket connection status | |
int | sock_handle_ |
socket handle for sending/receiving data | |
sockaddr_in | sockaddr_ |
address/port of remote socket | |
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) | |
static const int | SOCKET_FAIL = -1 |
socket fail return value | |
static const int | SOCKET_POLL_TO = 1000 |
socket ready polling timeout (ms) |
Defines socket functions required for a simple connection type.
Definition at line 138 of file simple_socket.h.
Constructor.
Definition at line 145 of file simple_socket.h.
virtual industrial::simple_socket::SimpleSocket::~SimpleSocket | ( | ) | [inline, virtual] |
Destructor.
Definition at line 150 of file simple_socket.h.
int industrial::simple_socket::SimpleSocket::getSockHandle | ( | ) | const [inline, protected] |
Definition at line 208 of file simple_socket.h.
bool industrial::simple_socket::SimpleSocket::isConnected | ( | ) | [inline, virtual] |
return connection status
Implements industrial::smpl_msg_connection::SmplMsgConnection.
Definition at line 152 of file simple_socket.h.
bool industrial::simple_socket::SimpleSocket::isReadyReceive | ( | int | timeout | ) | [inline] |
returns true if socket data is ready to receive
timeout | (ms) negative or zero values result in blocking |
Definition at line 164 of file simple_socket.h.
void industrial::simple_socket::SimpleSocket::logSocketError | ( | const char * | msg, |
int | rc | ||
) | [inline, protected] |
Definition at line 223 of file simple_socket.h.
bool industrial::simple_socket::SimpleSocket::poll | ( | int | timeout, |
bool & | ready, | ||
bool & | error | ||
) | [protected] |
polls socket for data or error
timeout | (ms) negative or zero values result in blocking |
ready | true if ready |
except | true if exception |
Definition at line 183 of file simple_socket.cpp.
virtual int industrial::simple_socket::SimpleSocket::rawReceiveBytes | ( | char * | buffer, |
industrial::shared_types::shared_int | num_bytes | ||
) | [protected, pure virtual] |
Implemented in industrial::udp_socket::UdpSocket, and industrial::tcp_socket::TcpSocket.
virtual int industrial::simple_socket::SimpleSocket::rawSendBytes | ( | char * | buffer, |
industrial::shared_types::shared_int | num_bytes | ||
) | [protected, pure virtual] |
Implemented in industrial::udp_socket::UdpSocket, and industrial::tcp_socket::TcpSocket.
bool industrial::simple_socket::SimpleSocket::receiveBytes | ( | industrial::byte_array::ByteArray & | buffer, |
industrial::shared_types::shared_int | num_bytes | ||
) | [protected, virtual] |
Method used by receive message interface method. This should be overridden for the specific connection type.
data | to receive. |
size | (in bytes) of data to receive |
Implements industrial::smpl_msg_connection::SmplMsgConnection.
Reimplemented in TestTcpServer.
Definition at line 94 of file simple_socket.cpp.
bool industrial::simple_socket::SimpleSocket::sendBytes | ( | industrial::byte_array::ByteArray & | buffer | ) | [protected, virtual] |
Method used by send message interface method. This should be overridden for the specific connection type.
data | to send. |
Implements industrial::smpl_msg_connection::SmplMsgConnection.
Reimplemented in TestTcpClient.
Definition at line 48 of file simple_socket.cpp.
virtual void industrial::simple_socket::SimpleSocket::setConnected | ( | bool | connected | ) | [inline, protected, virtual] |
Definition at line 218 of file simple_socket.h.
void industrial::simple_socket::SimpleSocket::setSockHandle | ( | int | sock_handle_ | ) | [inline, protected] |
Definition at line 213 of file simple_socket.h.
char industrial::simple_socket::SimpleSocket::buffer_[MAX_BUFFER_SIZE+1] [protected] |
internal data buffer for receiving
Definition at line 206 of file simple_socket.h.
bool industrial::simple_socket::SimpleSocket::connected_ [protected] |
flag indicating socket connection status
Definition at line 185 of file simple_socket.h.
const int industrial::simple_socket::SimpleSocket::MAX_BUFFER_SIZE = 1024 [static, protected] |
maximum size of buffer for receiving data (fixed memory size used in order to avoid dynamic memory allocation)
Definition at line 196 of file simple_socket.h.
int industrial::simple_socket::SimpleSocket::sock_handle_ [protected] |
socket handle for sending/receiving data
Definition at line 175 of file simple_socket.h.
sockaddr_in industrial::simple_socket::SimpleSocket::sockaddr_ [protected] |
address/port of remote socket
Definition at line 180 of file simple_socket.h.
const int industrial::simple_socket::SimpleSocket::SOCKET_FAIL = -1 [static, protected] |
socket fail return value
Definition at line 190 of file simple_socket.h.
const int industrial::simple_socket::SimpleSocket::SOCKET_POLL_TO = 1000 [static, protected] |
socket ready polling timeout (ms)
Definition at line 201 of file simple_socket.h.