(void)data;
OIC_LOG(DEBUG, TAG, "IN - CAReceiveHandler");
- while (!caglobals.tcp.terminate)
+ while (true)
{
+ oc_mutex_lock(g_mutexObjectList);
+ if (caglobals.tcp.terminate)
+ {
+ oc_mutex_unlock(g_mutexObjectList);
+ break;
+ }
+ oc_mutex_unlock(g_mutexObjectList);
CAFindReadyMessage();
}
int ret = select(caglobals.tcp.maxfd + 1, &readFds, NULL, NULL, &timeout);
+ oc_mutex_lock(g_mutexObjectList);
if (caglobals.tcp.terminate)
{
+ oc_mutex_unlock(g_mutexObjectList);
OIC_LOG_V(INFO, TAG, "Packet receiver Stop request received.");
return;
}
+ oc_mutex_unlock(g_mutexObjectList);
if (0 >= ret)
{
if (0 > ret)
unsigned char *inBuffer = *data;
size_t inLen = *dataLength;
- OIC_LOG_V(DEBUG, TAG, "before-datalength : %u", *dataLength);
+ OIC_LOG_V(DEBUG, TAG, "before-datalength : %zd", *dataLength);
if (NULL == svritem->data && inLen > 0)
{
*data = inBuffer;
*dataLength = inLen;
- OIC_LOG_V(DEBUG, TAG, "after-datalength : %u", *dataLength);
+ OIC_LOG_V(DEBUG, TAG, "after-datalength : %zd", *dataLength);
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return CA_STATUS_OK;
}
//[3][4] bytes in tls header are tls payload length
tlsLength = TLS_HEADER_SIZE +
(size_t)((svritem->tlsdata[3] << 8) | svritem->tlsdata[4]);
- OIC_LOG_V(DEBUG, TAG, "total tls length = %u", tlsLength);
+ OIC_LOG_V(DEBUG, TAG, "total tls length = %zd", tlsLength);
if (tlsLength > TLS_DATA_MAX_SIZE)
{
OIC_LOG_V(ERROR, TAG, "total tls length is too big (buffer size : %u)",
else
{
svritem->tlsLen += len;
- OIC_LOG_V(DEBUG, TAG, "nb_read : %u bytes , recv() : %d bytes, svritem->tlsLen : %u bytes",
+ OIC_LOG_V(DEBUG, TAG, "nb_read : %zd bytes , recv() : %d bytes, svritem->tlsLen : %zd bytes",
nbRead, len, svritem->tlsLen);
if (tlsLength > 0 && tlsLength == svritem->tlsLen)
{
#endif
}
+#ifndef DISABLE_TCP_SERVER
#define NEWSOCKET(FAMILY, NAME) \
caglobals.tcp.NAME.fd = CACreateAcceptSocket(FAMILY, &caglobals.tcp.NAME); \
if (caglobals.tcp.NAME.fd == -1) \
caglobals.tcp.ipv6s.fd, caglobals.tcp.ipv6s.port);
#endif
}
+#endif // DISABLE_TCP_SERVER
CAResult_t CATCPStartServer(const ca_thread_pool_t threadPool)
{
caglobals.tcp.svrlist = u_arraylist_create();
}
+#ifndef DISABLE_TCP_SERVER
if (caglobals.server)
{
CATCPInitializeSocket();
}
+#endif
+
#ifndef __TIZENRT__
// create pipe for fast shutdown
CAInitializePipe(caglobals.tcp.shutdownFds);
CLOSE_SOCKET(ipv6s);
#endif
- close(caglobals.tcp.connectionFds[1]);
- close(caglobals.tcp.connectionFds[0]);
- caglobals.tcp.connectionFds[1] = OC_INVALID_SOCKET;
- caglobals.tcp.connectionFds[0] = OC_INVALID_SOCKET;
+ if (caglobals.tcp.connectionFds[1] != OC_INVALID_SOCKET)
+ {
+ close(caglobals.tcp.connectionFds[1]);
+ caglobals.tcp.connectionFds[1] = OC_INVALID_SOCKET;
+ }
+ if (caglobals.tcp.connectionFds[0] != OC_INVALID_SOCKET)
+ {
+ close(caglobals.tcp.connectionFds[0]);
+ caglobals.tcp.connectionFds[0] = OC_INVALID_SOCKET;
+ }
#ifndef __TIZENRT__
if (caglobals.tcp.shutdownFds[1] != OC_INVALID_SOCKET)
{
oc_cond_wait_for(g_condSend, g_mutexSend, waitTime);
oc_mutex_unlock(g_mutexSend);
+ oc_mutex_lock(g_mutexObjectList);
if (caglobals.tcp.terminate)
{
+ oc_mutex_unlock(g_mutexObjectList);
return len;
}
+ oc_mutex_unlock(g_mutexObjectList);
sendRetryTime = (sendRetryTime << 1);
OIC_LOG(DEBUG, TAG, "data is removed from session list");
+#ifndef DISABLE_TCP_SERVER
if (caglobals.server && MAX_CONNECTION_COUNTS == u_arraylist_length(caglobals.tcp.svrlist) + 1)
{
CATCPInitializeSocket();
}
+#endif
+
return CA_STATUS_OK;
}