static int mqttClient_close(mqttClient_t* clientData) { int rc = LE_OK; LE_ASSERT(clientData); if (clientData->session.sock != MQTT_CLIENT_INVALID_SOCKET) { le_fdMonitor_Delete(clientData->session.sockFdMonitor); rc = close(clientData->session.sock); if (rc == -1) { LE_ERROR("close() failed(%d)", errno); rc = LE_FAULT; goto cleanup; } clientData->session.sock = MQTT_CLIENT_INVALID_SOCKET; } else { LE_WARN("socket already closed"); } cleanup: return rc; }
//-------------------------------------------------------------------------------------------------- LE_SHARED le_result_t le_comm_Delete (void* handle) { HandleRecord_t* connectionRecordPtr = (HandleRecord_t*) handle; LE_INFO("Deleting AF_INET socket, fd %d .........", connectionRecordPtr->fd); if (FdMonitorRef != NULL) { // Delete FD monitor le_fdMonitor_Delete(FdMonitorRef); FdMonitorRef = NULL; } // Remove the Handle record le_hashmap_Remove(HandleRecordByFileDescriptor, (void*)(intptr_t) connectionRecordPtr->fd); // Shut-down the open socket shutdown(connectionRecordPtr->fd, SHUT_RDWR); // Close Socket Handle close(connectionRecordPtr->fd); connectionRecordPtr->fd = -1; // Free the Handle Record memory le_mem_Release(connectionRecordPtr); connectionRecordPtr = NULL; // Reset the Network IP Address and TCP Port memset(NetworkSocketIpAddress, 0, sizeof(NetworkSocketIpAddress)); NetworkSocketTCPListeningPort = 0; return LE_OK; }
//-------------------------------------------------------------------------------------------------- static void StopParsing ( Parser_t* parserPtr ) //-------------------------------------------------------------------------------------------------- { if (NotStopped(parserPtr)) { parserPtr->next = EXPECT_NOTHING; if (parserPtr->fdMonitor != NULL) { le_fdMonitor_Delete(parserPtr->fdMonitor); parserPtr->fdMonitor = NULL; } } }
//-------------------------------------------------------------------------------------------------- void le_sig_DeleteAll ( void ) { // Get the monitor object for this thread. MonitorObj_t* monitorObjPtr = pthread_getspecific(SigMonKey); if (monitorObjPtr != NULL) { // Delete the monitor. le_fdMonitor_Delete(monitorObjPtr->monitorRef); // Close the file descriptor. while(1) { int n = close(monitorObjPtr->fd); if (n == 0) { break; } else if (errno != EINTR) { LE_FATAL("Could not close file descriptor."); } } // Remove all handler objects from the list and free them. le_dls_Link_t* handlerLinkPtr = le_dls_Pop(&(monitorObjPtr->handlerObjList)); while (handlerLinkPtr != NULL) { le_mem_Release( CONTAINER_OF(handlerLinkPtr, HandlerObj_t, link) ); handlerLinkPtr = le_dls_Pop(&(monitorObjPtr->handlerObjList)); } // Release the monitor object. le_mem_Release(monitorObjPtr); } }