45 namespace simple_socket
50 int rc = this->SOCKET_FAIL;
53 if (this->isConnected())
62 std::vector<char> localBuffer;
63 buffer.
copyTo(localBuffer);
64 rc = rawSendBytes(&localBuffer[0], localBuffer.size());
65 if (this->SOCKET_FAIL != rc)
72 logSocketError(
"Socket sendBytes failed", rc, errno);
78 LOG_ERROR(
"Buffer size: %u, is greater than max socket size: %u", buffer.
getBufferSize(), this->MAX_BUFFER_SIZE);
86 LOG_WARN(
"Not connected, bytes not sent");
91 this->setConnected(
false);
100 int rc = this->SOCKET_FAIL;
109 memset(&this->buffer_, 0,
sizeof(this->buffer_));
115 LOG_WARN(
"Socket buffer max size: %u, is larger than byte array buffer: %u",
118 if (this->isConnected())
121 while (remainBytes > 0)
126 if (this->rawPoll(this->SOCKET_POLL_TO, ready, error))
130 rc = rawReceiveBytes(this->buffer_, remainBytes);
131 if (this->SOCKET_FAIL == rc)
133 this->logSocketError(
"Socket received failed", rc, errno);
140 LOG_WARN(
"Recieved zero bytes: %u", rc);
147 remainBytes = remainBytes - rc;
148 LOG_COMM(
"Byte array receive, bytes read: %u, bytes reqd: %u, bytes left: %u",
149 rc, num_bytes, remainBytes);
150 buffer.
load(&this->buffer_, rc);
156 LOG_ERROR(
"Socket poll returned an error");
162 LOG_ERROR(
"Uknown error from socket poll");
169 LOG_COMM(
"Socket poll timeout, trying again");
175 LOG_WARN(
"Not connected, bytes not sent");
181 this->setConnected(
false);
Contains platform specific type definitions that guarantee the size of primitive data types...
void init()
Initializes or Reinitializes an empty buffer.
#define LOG_WARN(format,...)
#define LOG_COMM(format,...)
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
#define LOG_ERROR(format,...)
The byte array wraps a dynamic array of bytes (i.e. char).
unsigned int getMaxBufferSize()
gets current buffer size
void copyTo(std::vector< char > &out)
Copy to std::vector, for raw-ptr access.
unsigned int getBufferSize()
gets current buffer size