CAResult_t CAStartIP()
{
+ //Initializing the Globals
+ CAInitializeIPGlobals();
+
// Specific the port number received from application.
caglobals.ip.u6.port = caglobals.ports.udp.u6;
caglobals.ip.u6s.port = caglobals.ports.udp.u6s;
CAIPStopNetworkMonitor(CA_ADAPTER_IP);
CAIPStopServer();
- //Re-initializing the Globals to start them again
- CAInitializeIPGlobals();
return CA_STATUS_OK;
}
CAIPSetPacketReceiveCallback(NULL);
#ifndef SINGLE_THREAD
- CADeInitializeIPGlobals();
CAIPDeinitializeQueueHandles();
#endif
static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags);
+static void CACloseFDs()
+{
+#if !defined(WSA_WAIT_EVENT_0)
+ if (caglobals.ip.shutdownFds[0] != -1)
+ {
+ close(caglobals.ip.shutdownFds[0]);
+ caglobals.ip.shutdownFds[0] = -1;
+ }
+#endif
+ CADeInitializeIPGlobals();
+}
+
static void CAReceiveHandler(void *data)
{
(void)data;
{
CAFindReadyMessage();
}
+ CACloseFDs();
}
#define CLOSE_SOCKET(TYPE) \
void CAIPStopServer()
{
- caglobals.ip.started = false;
caglobals.ip.terminate = true;
#if !defined(WSA_WAIT_EVENT_0)
if (caglobals.ip.shutdownFds[1] != -1)
{
close(caglobals.ip.shutdownFds[1]);
+ caglobals.ip.shutdownFds[1] = -1;
// receive thread will stop immediately
}
else
OIC_LOG_V(DEBUG, TAG, "set shutdown event failed: %d", WSAGetLastError());
}
#endif
+
+ if (!caglobals.ip.started)
+ { // Close fd's since receive handler was not started
+ CACloseFDs();
+ }
+ caglobals.ip.started = false;
}
void CAWakeUpForChange()