void CATCPSetPacketReceiveCallback(CATCPPacketReceivedCallback callback);
/**
+ * Set this callback for receiving the changed connection information from peer devices.
+ *
+ * @param[in] callback Callback to be notified when connection state changes.
+ */
+void CATCPSetConnectionChangedCallback(CATCPConnectionHandleCallback connHandler);
+
+/**
* API to send unicast TCP data.
*
* @param[in] endpoint complete network address to send to.
{
OIC_LOG(DEBUG, TAG, "CAStartListeningServer");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CAStopListeningServer");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CAStartDiscoveryServer");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CARegisterHandler");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
OIC_LOG(DEBUG, TAG, "CA is not initialized");
return;
{
OIC_LOG(DEBUG, TAG, "CARegisterDTLSHandshakeCallback");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CARegisterDTLSCredentialsHandler");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CARegisterDTLSX509CredentialsHandler");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CARegisterDTLSCrlHandler");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CASendRequest");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG(DEBUG, TAG, "CASendResponse");
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
{
OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
- if(!g_isInitialized)
+ if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
static void CARegisterCallback(CAConnectivityHandler_t handler)
{
- if(handler.startAdapter == NULL ||
+ if (handler.startAdapter == NULL ||
handler.startListenServer == NULL ||
handler.stopListenServer == NULL ||
handler.startDiscoveryServer == NULL ||
{
void* ptrType = u_arraylist_get(list, i);
- if(NULL == ptrType)
+ if (NULL == ptrType)
{
continue;
}
OIC_LOG_V(DEBUG, TAG, "address : %s", ep->addr);
- if(CA_RESPONSE_DATA == dataType)
+ if (CA_RESPONSE_DATA == dataType)
{
CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
if (!resInfo)
return NULL;
}
- if(CA_REQUEST_DATA == dataType)
+ if (CA_REQUEST_DATA == dataType)
{
// clone request info
CARequestInfo_t *request = CACloneRequestInfo((CARequestInfo_t *)sendData);
- if(!request)
+ if (!request)
{
OIC_LOG(ERROR, TAG, "CACloneRequestInfo failed");
goto exit;
cadata->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
cadata->requestInfo = request;
}
- else if(CA_RESPONSE_DATA == dataType)
+ else if (CA_RESPONSE_DATA == dataType)
{
// clone response info
CAResponseInfo_t *response = CACloneResponseInfo((CAResponseInfo_t *)sendData);
#ifdef SINGLE_THREAD
CAResult_t result = CAProcessSendData(data);
- if(CA_STATUS_OK != result)
+ if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
CADestroyData(data, sizeof(CAData_t));
{
// send block data
CAResult_t res = CASendBlockWiseData(data);
- if(CA_NOT_SUPPORTED == res)
+ if (CA_NOT_SUPPORTED == res)
{
OIC_LOG(DEBUG, TAG, "normal msg will be sent");
CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
static void CALogPayloadInfo(CAInfo_t *info)
{
- if(info)
+ if (info)
{
if (info->options)
{
// should remain that way so a 0 byte of length 1 is inserted.
len = 1;
option[0]=0;
- } else {
+ }
+ else
+ {
memcpy(option, data, len);
option[len] = '\0';
}
if (NULL == thread)
{
OIC_LOG(ERROR, TAG, "thread data passing error!!");
-
return;
}
thread->isStop = true;
thread->threadTask = task;
thread->destroy = destroy;
- if(NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+ if (NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+ {
goto ERROR_MEM_FAILURE;
+ }
return CA_STATUS_OK;
- ERROR_MEM_FAILURE:
- if(thread->dataQueue)
+
+ERROR_MEM_FAILURE:
+ if (thread->dataQueue)
{
u_queue_delete(thread->dataQueue);
thread->dataQueue = NULL;
}
- if(thread->threadMutex)
+ if (thread->threadMutex)
{
ca_mutex_free(thread->threadMutex);
thread->threadMutex = NULL;
}
- if(thread->threadCond)
+ if (thread->threadCond)
{
ca_cond_free(thread->threadCond);
thread->threadCond = NULL;
}
return CA_MEMORY_ALLOC_FAILED;
-
}
CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread)
u_queue_message_t *message = u_queue_get_element(thread->dataQueue);
// free
- if(NULL != message)
+ if (NULL != message)
{
if (NULL != thread->destroy)
{
#include "caremotehandler.h"
#include "caprotocolmessage.h"
#include "oic_malloc.h"
+#include "ocrandom.h"
#include "logger.h"
#define TAG "OIC_CA_RETRANS"
*/
static uint64_t CAGetTimeoutValue()
{
- return ((DEFAULT_ACK_TIMEOUT_SEC * 1000) + ((1000 * (random() & 0xFF)) >> 8)) *
+#ifdef HAVE_SRANDOM
+ return ((DEFAULT_ACK_TIMEOUT_SEC * 1000) + ((1000 * OCGetRandomByte()) >> 8)) *
(uint64_t) 1000;
+#else
+ return ((DEFAULT_ACK_TIMEOUT_SEC * 1000) + ((1000 * OCGetRandomByte()) >> 8)) *
+ (uint64_t) 1000;
+#endif
}
CAResult_t CARetransmissionStart(CARetransmission_t *context)
static int CACreateAcceptSocket(int family, CASocket_t *sock);
static void CAAcceptConnection(CATransportFlags_t flag, CASocket_t *sock);
static void CAFindReadyMessage();
-static void CASelectReturned(fd_set *readFds, int ret);
+static void CASelectReturned(fd_set *readFds);
static void CAReceiveMessage(int fd);
static void CAReceiveHandler(void *data);
static int CATCPCreateSocket(int family, CATCPSessionInfo_t *tcpServerInfo);
return;
}
- CASelectReturned(&readFds, ret);
+ CASelectReturned(&readFds);
}
-static void CASelectReturned(fd_set *readFds, int ret)
+static void CASelectReturned(fd_set *readFds)
{
VERIFY_NON_NULL_VOID(readFds, TAG, "readFds is NULL");