From 89b39d603e4cebd360fb4cb11023092fe9797f72 Mon Sep 17 00:00:00 2001 From: "hyuna0213.jo" Date: Mon, 7 Nov 2016 09:45:47 +0900 Subject: [PATCH] Return correct error code when send fails in catcpserver Modified ssl adapter along with modified return type. Change-Id: I68d0d1ab73f1a858c42b3340947f01ca61974987 Signed-off-by: hyuna0213.jo Signed-off-by: Joonghwan Lee Reviewed-on: https://gerrit.iotivity.org/gerrit/13991 Tested-by: jenkins-iotivity Reviewed-by: Dave Thaler Reviewed-by: Randeep Singh Reviewed-by: jihwan seo Reviewed-by: Jaehong Jo Reviewed-by: Ashok Babu Channa --- .../csdk/connectivity/inc/ca_adapter_net_ssl.h | 6 +- .../csdk/connectivity/inc/caadapterinterface.h | 4 +- resource/csdk/connectivity/inc/caadapternetdtls.h | 4 +- resource/csdk/connectivity/inc/catcpinterface.h | 19 ++++-- .../src/adapter_util/ca_adapter_net_ssl.c | 18 +++-- .../csdk/connectivity/src/ip_adapter/caipadapter.c | 11 ++-- .../src/tcp_adapter/arduino/catcpserver_eth.cpp | 20 +++--- .../connectivity/src/tcp_adapter/catcpadapter.c | 48 ++++++++------ .../connectivity/src/tcp_adapter/catcpserver.c | 77 +++++++++++----------- .../csdk/connectivity/test/ssladapter_test.cpp | 15 +++-- 10 files changed, 125 insertions(+), 97 deletions(-) diff --git a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h index ff1cff3..d189fb3 100644 --- a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h +++ b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h @@ -33,10 +33,10 @@ extern "C" { #define MAX_SUPPORTED_ADAPTERS 2 typedef void (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep, - const void *data, uint32_t dataLength); + const void *data, size_t dataLength); -typedef void (*CAPacketSendCallback)(CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength); +typedef ssize_t (*CAPacketSendCallback)(CAEndpoint_t *endpoint, + const void *data, size_t dataLength); /** * Select the cipher suite for dtls handshake diff --git a/resource/csdk/connectivity/inc/caadapterinterface.h b/resource/csdk/connectivity/inc/caadapterinterface.h index 3b1d466..90a53cc 100644 --- a/resource/csdk/connectivity/inc/caadapterinterface.h +++ b/resource/csdk/connectivity/inc/caadapterinterface.h @@ -188,7 +188,7 @@ typedef void (*CARegisterConnectivityCallback)(CAConnectivityHandler_t handler); * @see SendUnicastData(), SendMulticastData() */ typedef void (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep, - const void *data, uint32_t dataLen); + const void *data, size_t dataLen); /** * This will be used to notify network changes to the connectivity common logic layer. @@ -204,7 +204,7 @@ typedef void (*CAConnectionChangeCallback)(const CAEndpoint_t *info, bool isConn * This will be used to notify error result to the connectivity common logic layer. */ typedef void (*CAErrorHandleCallback)(const CAEndpoint_t *endpoint, - const void *data, uint32_t dataLen, + const void *data, size_t dataLen, CAResult_t result); #ifdef __cplusplus diff --git a/resource/csdk/connectivity/inc/caadapternetdtls.h b/resource/csdk/connectivity/inc/caadapternetdtls.h index 3006256..b7239ef 100644 --- a/resource/csdk/connectivity/inc/caadapternetdtls.h +++ b/resource/csdk/connectivity/inc/caadapternetdtls.h @@ -33,10 +33,10 @@ #define MAX_SUPPORTED_ADAPTERS 2 typedef void (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep, - const void *data, uint32_t dataLength); + const void *data, size_t dataLength); typedef void (*CAPacketSendCallback)(CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength); + const void *data, size_t dataLength); /** * Data structure for holding the send and recv callbacks. diff --git a/resource/csdk/connectivity/inc/catcpinterface.h b/resource/csdk/connectivity/inc/catcpinterface.h index 0d30c61..3d48bc4 100644 --- a/resource/csdk/connectivity/inc/catcpinterface.h +++ b/resource/csdk/connectivity/inc/catcpinterface.h @@ -48,7 +48,7 @@ extern "C" */ typedef void (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, const void *data, - uint32_t dataLength); + size_t dataLength); /** * Callback to notify error in the TCP adapter. @@ -60,7 +60,7 @@ typedef void (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, * @pre Callback must be registered using CAIPSetPacketReceiveCallback(). */ typedef void (*CATCPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result); + size_t dataLength, CAResult_t result); /** * Callback to notify connection information in the TCP adapter. @@ -153,10 +153,9 @@ void CATCPSetConnectionChangedCallback(CATCPConnectionHandleCallback connHandler * @param[in] endpoint complete network address to send to. * @param[in] data Data to be send. * @param[in] dataLength Length of data in bytes. - * @param[in] isMulticast Whether data needs to be sent to multicast ip. + * @return Sent data length or -1 on error. */ -void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength, - bool isMulticast); +ssize_t CATCPSendData(CAEndpoint_t *endpoint, const void *data, size_t dataLength); /** * Get a list of CAInterface_t items. @@ -215,6 +214,16 @@ size_t CAGetTotalLengthFromHeader(const unsigned char *recvBuffer); CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index); /** + * Find the session with endpoint info and remove it from list. + * + * @param[in] endpoint Remote Endpoint information (like ipaddress, + * port, reference uri and transport type) to + * which the unicast data has to be sent. + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CASearchAndDeleteTCPSession(const CAEndpoint_t *endpoint); + +/** * Get total payload length from CoAP over TCP header. * * @param[in] data Data to be send. diff --git a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c index 0aaa6b4..e7b0826 100644 --- a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c +++ b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c @@ -485,29 +485,35 @@ static int GetAdapterIndex(CATransportAdapter_t adapter) * @param[in] data message * @param[in] dataLen message length * - * @return message length + * @return message length or -1 on error. */ static int SendCallBack(void * tep, const unsigned char * data, size_t dataLen) { OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); - VERIFY_NON_NULL_RET(tep, NET_SSL_TAG, "secure endpoint is NULL", 0); - VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", 0); + VERIFY_NON_NULL_RET(tep, NET_SSL_TAG, "secure endpoint is NULL", -1); + VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", -1); OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data len: %zu", dataLen); OIC_LOG_V(DEBUG, NET_SSL_TAG, "Adapter: %u", ((SslEndPoint_t * )tep)->sep.endpoint.adapter); + ssize_t sentLen = 0; int adapterIndex = GetAdapterIndex(((SslEndPoint_t * )tep)->sep.endpoint.adapter); if (0 == adapterIndex || 1 == adapterIndex) { CAPacketSendCallback sendCallback = g_caSslContext->adapterCallbacks[adapterIndex].sendCallback; - sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, (uint32_t) dataLen); + sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataLen); + if (sentLen != dataLen) + { + OIC_LOG_V(DEBUG, NET_SSL_TAG, + "Packet was partially sent - total/sent/remained bytes : %d/%d/%d", + sentLen, dataLen, (dataLen - sentLen)); + } } else { OIC_LOG(ERROR, NET_SSL_TAG, "Unsupported adapter"); - dataLen = 0; } OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); - return dataLen; + return sentLen; } /** * Read callback. diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c index 42fe1a6..72d1f11 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c @@ -79,8 +79,8 @@ static CAErrorHandleCallback g_errorCallback = NULL; static void CAIPPacketReceivedCB(const CASecureEndpoint_t *endpoint, const void *data, uint32_t dataLength); #ifdef __WITH_DTLS__ -static void CAIPPacketSendCB(CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength); +static int32_t CAIPPacketSendCB(CAEndpoint_t *endpoint, + const void *data, uint32_t dataLength); #endif #ifndef SINGLE_THREAD @@ -151,12 +151,13 @@ void CAIPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status) } #ifdef __WITH_DTLS__ -static void CAIPPacketSendCB(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength) +static int32_t CAIPPacketSendCB(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength) { - VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); - VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); + VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint is NULL", -1); + VERIFY_NON_NULL_RET(data, TAG, "data is NULL", -1); CAIPSendData(endpoint, data, dataLength, false); + return dataLength; } #endif diff --git a/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp b/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp index 58293fd..6e6404e 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp +++ b/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp @@ -284,8 +284,8 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_NOT_SUPPORTED; } -static void sendData(const CAEndpoint_t *endpoint, - const void *data, size_t dlen) +static ssize_t sendData(const CAEndpoint_t *endpoint, + const void *data, size_t dlen) { uint16_t port = endpoint->port; uint8_t ipAddr[4] = { 0 }; @@ -294,14 +294,14 @@ static void sendData(const CAEndpoint_t *endpoint, &parsedPort) != CA_STATUS_OK) { OIC_LOG(ERROR, TAG, "parse fail"); - return; + return -1; } if (dlen > 65535) // Max value for uint16_t { // This will never happen as max buffer size we are dealing with is COAP_MAX_PDU_SIZE OIC_LOG(ERROR, TAG, "Size exceeded"); - return; + return -1; } uint32_t ret = send(g_unicastSocket, (const uint8_t *)data, (uint16_t)dlen); @@ -311,19 +311,17 @@ static void sendData(const CAEndpoint_t *endpoint, } OIC_LOG(DEBUG, TAG, "OUT"); + return ret; } -void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen, - bool isMulticast) +ssize_t CATCPSendData(CAEndpoint_t *endpoint, const void *data, size_t datalen) { VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); - if (!isMulticast) + if (caglobals.tcp.ipv4tcpenabled && (endpoint->adapter & CA_ADAPTER_TCP)) { - if (caglobals.tcp.ipv4tcpenabled && (endpoint->adapter & CA_ADAPTER_TCP)) - { - sendData(endpoint, data, datalen); - } + return sendData(endpoint, data, datalen); } + return -1; } diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c index 2892edf..d31d349 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c @@ -91,6 +91,9 @@ static CAErrorHandleCallback g_errorCallback = NULL; static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data, uint32_t dataLength); +static void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data, + size_t dataLength, CAResult_t result); + /** * KeepAlive Connected or Disconnected Callback to CA adapter. */ @@ -167,22 +170,28 @@ void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data, } #ifdef __WITH_TLS__ -static void CATCPPacketSendCB(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength) +static ssize_t CATCPPacketSendCB(CAEndpoint_t *endpoint, const void *data, size_t dataLength) { OIC_LOG_V(DEBUG, TAG, "In %s", __func__); - VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); - VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); + VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint is NULL", -1); + VERIFY_NON_NULL_RET(data, TAG, "data is NULL", -1); OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port); OIC_LOG_BUFFER(DEBUG, TAG, data, dataLength); - CATCPSendData(endpoint, data, dataLength, false); - OIC_LOG_V(DEBUG, TAG, "Out %s", __func__); + ssize_t ret = CATCPSendData(endpoint, data, dataLength); + if (-1 == ret) + { + CASearchAndDeleteTCPSession(endpoint); + CATCPErrorHandler(endpoint, data, dataLength, CA_SEND_FAILED); + } + OIC_LOG_V(DEBUG, TAG, "Out %s : %d bytes sent", __func__, ret); + return ret; } #endif -void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result) +static void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data, + size_t dataLength, CAResult_t result) { VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); @@ -436,8 +445,7 @@ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint, #ifndef SINGLE_THREAD return CAQueueTCPData(false, endpoint, data, dataLength); #else - CATCPSendData(endpoint, data, dataLength, false); - return dataLength; + return CATCPSendData(endpoint, data, dataLength); #endif } @@ -512,17 +520,13 @@ void CATCPSendDataThread(void *threadData) { // if payload length is zero, disconnect from remote device. OIC_LOG(DEBUG, TAG, "payload length is zero, disconnect from remote device"); - size_t index = 0; - CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(tcpData->remoteEndpoint, - &index); - if (svritem) +#ifdef __WITH_TLS__ + if (CA_STATUS_OK != CAcloseSslConnection(tcpData->remoteEndpoint)) { - result = CADisconnectTCPSession(svritem, index); - if (CA_STATUS_OK != result) - { - OIC_LOG_V(ERROR, TAG, "CADisconnectTCPSession failed, result[%d]", result); - } + OIC_LOG(ERROR, TAG, "Failed to close TLS session"); } +#endif + CASearchAndDeleteTCPSession(tcpData->remoteEndpoint); return; } @@ -542,7 +546,13 @@ void CATCPSendDataThread(void *threadData) } #endif //Processing for sending unicast - CATCPSendData(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen, false); + ssize_t dlen = CATCPSendData(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen); + if (-1 == dlen) + { + CASearchAndDeleteTCPSession(tcpData->remoteEndpoint); + CATCPErrorHandler(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen, + CA_SEND_FAILED); + } } } diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 5b6982c..398b86e 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -596,6 +596,12 @@ static void CAReceiveMessage(int fd) //disconnect session and clean-up data if any error occurs if (res != CA_STATUS_OK) { +#ifdef __WITH_TLS__ + if (CA_STATUS_OK != CAcloseSslConnection(&svritem->sep.endpoint)) + { + OIC_LOG(ERROR, TAG, "Failed to close TLS session"); + } +#endif CADisconnectTCPSession(svritem, index); CACleanData(svritem); } @@ -983,8 +989,8 @@ size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen) return payloadLen; } -static void sendData(const CAEndpoint_t *endpoint, const void *data, - size_t dlen, const char *fam) +static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, + size_t dlen, const char *fam) { // #1. get TCP Server object from list size_t index = 0; @@ -996,11 +1002,7 @@ static void sendData(const CAEndpoint_t *endpoint, const void *data, if (!svritem) { OIC_LOG(ERROR, TAG, "Failed to create TCP server object"); - if (g_tcpErrorHandler) - { - g_tcpErrorHandler(endpoint, data, dlen, CA_SOCKET_OPERATION_FAILED); - } - return; + return -1; } } @@ -1009,12 +1011,7 @@ static void sendData(const CAEndpoint_t *endpoint, const void *data, { // if file descriptor value is wrong, remove TCP Server info from list OIC_LOG(ERROR, TAG, "Failed to connect to TCP server"); - CADisconnectTCPSession(svritem, index); - if (g_tcpErrorHandler) - { - g_tcpErrorHandler(endpoint, data, dlen, CA_SOCKET_OPERATION_FAILED); - } - return; + return -1; } // #3. send data to TCP Server @@ -1027,11 +1024,7 @@ static void sendData(const CAEndpoint_t *endpoint, const void *data, if (EWOULDBLOCK != errno) { OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(errno)); - if (g_tcpErrorHandler) - { - g_tcpErrorHandler(endpoint, data, dlen, CA_SEND_FAILED); - } - return; + return len; } continue; } @@ -1043,25 +1036,23 @@ static void sendData(const CAEndpoint_t *endpoint, const void *data, (void)fam; #endif OIC_LOG_V(INFO, TAG, "unicast %stcp sendTo is successful: %zu bytes", fam, dlen); + return dlen; } -void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen, - bool isMulticast) +ssize_t CATCPSendData(CAEndpoint_t *endpoint, const void *data, size_t datalen) { - VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); - VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); + VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint is NULL", -1); + VERIFY_NON_NULL_RET(data, TAG, "data is NULL", -1); - if (!isMulticast) + if (caglobals.tcp.ipv6tcpenabled && (endpoint->flags & CA_IPV6)) { - if (caglobals.tcp.ipv6tcpenabled && (endpoint->flags & CA_IPV6)) - { - sendData(endpoint, data, datalen, "ipv6"); - } - if (caglobals.tcp.ipv4tcpenabled && (endpoint->flags & CA_IPV4)) - { - sendData(endpoint, data, datalen, "ipv4"); - } + return sendData(endpoint, data, datalen, "ipv6"); } + if (caglobals.tcp.ipv4tcpenabled && (endpoint->flags & CA_IPV4)) + { + return sendData(endpoint, data, datalen, "ipv4"); + } + return -1; } CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) @@ -1183,13 +1174,6 @@ CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index) oc_mutex_lock(g_mutexObjectList); -#ifdef __WITH_TLS__ - if (CA_STATUS_OK != CAcloseSslConnection(&svritem->sep.endpoint)) - { - OIC_LOG(ERROR, TAG, "Failed to close TLS session"); - } -#endif - // close the socket and remove TCP connection info in list if (svritem->fd >= 0) { @@ -1295,6 +1279,23 @@ CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index) return NULL; } +CAResult_t CASearchAndDeleteTCPSession(const CAEndpoint_t *endpoint) +{ + CAResult_t result = CA_STATUS_OK; + size_t index = 0; + CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(endpoint, &index); + if (svritem) + { + result = CADisconnectTCPSession(svritem, index); + if (CA_STATUS_OK != result) + { + OIC_LOG_V(ERROR, TAG, "CADisconnectTCPSession failed, result[%d]", result); + } + } + + return result; +} + size_t CAGetTotalLengthFromHeader(const unsigned char *recvBuffer) { OIC_LOG(DEBUG, TAG, "IN - CAGetTotalLengthFromHeader"); diff --git a/resource/csdk/connectivity/test/ssladapter_test.cpp b/resource/csdk/connectivity/test/ssladapter_test.cpp index 45864ff..a292b6d 100644 --- a/resource/csdk/connectivity/test/ssladapter_test.cpp +++ b/resource/csdk/connectivity/test/ssladapter_test.cpp @@ -236,16 +236,17 @@ static void socketConnect() error("ERROR connecting"); } -static void CATCPPacketSendCB(CAEndpoint_t *, const void *buf, uint32_t buflen) +static ssize_t CATCPPacketSendCB(CAEndpoint_t *, const void *buf, size_t buflen) { int n; n = write(sockfd, buf, buflen); if (n < 0) error("ERROR writing to socket"); + return n; } -char msg[256] = {0}; int msglen = 0; -static void CATCPPacketReceivedCB(const CASecureEndpoint_t *, const void *data, uint32_t dataLength) +char msg[256] = {0}; size_t msglen = 0; +static void CATCPPacketReceivedCB(const CASecureEndpoint_t *, const void *data, size_t dataLength) { memcpy(msg, data, dataLength); msglen = dataLength; @@ -314,15 +315,16 @@ static void socketOpen_server() error("\nERROR on accept"); } -static void CATCPPacketSendCB_server(CAEndpoint_t *, const void *buf, uint32_t buflen) +static ssize_t CATCPPacketSendCB_server(CAEndpoint_t *, const void *buf, size_t buflen) { int n; n = write(newsockfd,buf,buflen); if (n < 0) error("ERROR writing to socket"); + return n; } -static void CATCPPacketReceivedCB_server(const CASecureEndpoint_t *, const void *data, uint32_t dataLength) +static void CATCPPacketReceivedCB_server(const CASecureEndpoint_t *, const void *data, size_t dataLength) { memcpy(msg, data, dataLength); msglen = dataLength; @@ -1242,7 +1244,7 @@ unsigned char predictedClientHello[] = { }; static unsigned char controlBuf[sizeof(predictedClientHello)]; static char controlBufLen = 0; -static void CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, uint32_t buflen) +static ssize_t CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, size_t buflen) { int n; n = write(sockfd, buf, buflen); @@ -1252,6 +1254,7 @@ static void CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, ui memset(controlBuf, 0, sizeof(predictedClientHello)); memcpy(controlBuf, buf, buflen); controlBufLen = buflen; + return buflen; } static void * test0CAinitiateSslHandshake(void * arg) -- 2.7.4