+CASocketFd_t CAGetSocketFDFromEndpoint(const CAEndpoint_t *endpoint)
+{
+ VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint is NULL", OC_INVALID_SOCKET);
+
+ OIC_LOG_V(DEBUG, TAG, "Looking for [%s:%d]", endpoint->addr, endpoint->port);
+
+ // get connection info from list.
+ oc_mutex_lock(g_mutexObjectList);
+ uint32_t length = u_arraylist_length(caglobals.tcp.svrlist);
+ for (size_t i = 0; i < length; i++)
+ {
+ CATCPSessionInfo_t *svritem = (CATCPSessionInfo_t *) u_arraylist_get(
+ caglobals.tcp.svrlist, i);
+ if (!svritem)
+ {
+ continue;
+ }
+
+ if (!strncmp(svritem->sep.endpoint.addr, endpoint->addr,
+ sizeof(svritem->sep.endpoint.addr))
+ && (svritem->sep.endpoint.port == endpoint->port)
+ && (svritem->sep.endpoint.flags & endpoint->flags))
+ {
+ oc_mutex_unlock(g_mutexObjectList);
+ OIC_LOG(DEBUG, TAG, "Found in session list");
+ return svritem->fd;
+ }
+ }
+
+ oc_mutex_unlock(g_mutexObjectList);
+ OIC_LOG(DEBUG, TAG, "Session not found");
+ return OC_INVALID_SOCKET;
+}
+