1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "../../deps/mqtt-c/mqtt.h"
- #include <open62541/network_tcp.h>
- ssize_t
- mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, int flags) {
- UA_Connection *connection = (UA_Connection*) fd->connection;
- UA_ByteString sendBuffer;
- sendBuffer.data = (UA_Byte*)UA_malloc(len);
- sendBuffer.length = len;
- memcpy(sendBuffer.data, buf, len);
- UA_StatusCode ret = connection->send(connection, &sendBuffer);
- if(ret != UA_STATUSCODE_GOOD)
- return -1;
- return (ssize_t)len;
- }
- ssize_t
- mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int flags) {
- UA_Connection *connection = (UA_Connection*) fd->connection;
- connection->config.recvBufferSize = (UA_UInt32) bufsz;
- UA_ByteString inBuffer;
- UA_StatusCode ret = connection->recv(connection, &inBuffer, fd->timeout);
- if(ret == UA_STATUSCODE_GOOD ){
-
- memcpy(buf, inBuffer.data, inBuffer.length);
- ssize_t bytesReceived = (ssize_t)inBuffer.length;
-
- connection->releaseRecvBuffer(connection, &inBuffer);
- return bytesReceived;
- }else if(ret == UA_STATUSCODE_GOODNONCRITICALTIMEOUT){
- return 0;
- }else{
- return -1;
- }
- }
|