int TestMessageQueue(int argc, char* argv[]) { HANDLE thread; wMessageQueue* queue; if (!(queue = MessageQueue_New(NULL))) { printf("failed to create message queue\n"); return 1; } if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL))) { printf("failed to create thread\n"); MessageQueue_Free(queue); return 1; } if (!MessageQueue_Post(queue, NULL, 123, NULL, NULL) || !MessageQueue_Post(queue, NULL, 456, NULL, NULL) || !MessageQueue_Post(queue, NULL, 789, NULL, NULL) || !MessageQueue_PostQuit(queue, 0) || WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0) return -1; MessageQueue_Free(queue); CloseHandle(thread); return 0; }
void MessagePipe_Free(wMessagePipe* pipe) { if (pipe) { MessageQueue_Free(pipe->In); MessageQueue_Free(pipe->Out); free(pipe); } }
SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard, SCARDCONTEXT hContext) { SMARTCARD_CONTEXT* pContext; pContext = (SMARTCARD_CONTEXT*) calloc(1, sizeof(SMARTCARD_CONTEXT)); if (!pContext) return pContext; pContext->smartcard = smartcard; pContext->hContext = hContext; pContext->IrpQueue = MessageQueue_New(NULL); if (!pContext->IrpQueue) goto error_irpqueue; pContext->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_context_thread, pContext, 0, NULL); if (!pContext->thread) goto error_thread; return pContext; error_thread: MessageQueue_Free(pContext->IrpQueue); error_irpqueue: free(pContext); return NULL; }
static void smartcard_free(DEVICE* device) { SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; if (smartcard->IrpQueue) { if (MessageQueue_PostQuit(smartcard->IrpQueue, 0)) WaitForSingleObject(smartcard->thread, INFINITE); MessageQueue_Free(smartcard->IrpQueue); smartcard->IrpQueue = NULL; CloseHandle(smartcard->thread); smartcard->thread = NULL; } if (smartcard->device.data) { Stream_Free(smartcard->device.data, TRUE); smartcard->device.data = NULL; } ListDictionary_Free(smartcard->rgSCardContextList); ListDictionary_Free(smartcard->rgOutstandingMessages); Queue_Free(smartcard->CompletedIrpQueue); if (smartcard->StartedEvent) { SCardReleaseStartedEvent(); smartcard->StartedEvent = NULL; } free(device); }
void update_free(rdpUpdate* update) { if (update != NULL) { OFFSCREEN_DELETE_LIST* deleteList; deleteList = &(update->altsec->create_offscreen_bitmap.deleteList); free(deleteList->indices); free(update->bitmap_update.rectangles); free(update->pointer->pointer_color.andMaskData); free(update->pointer->pointer_color.xorMaskData); free(update->pointer->pointer_new.colorPtrAttr.andMaskData); free(update->pointer->pointer_new.colorPtrAttr.xorMaskData); free(update->pointer); free(update->primary->polyline.points); free(update->primary->polygon_sc.points); if (update->primary->fast_glyph.glyphData.aj) free(update->primary->fast_glyph.glyphData.aj); free(update->primary); free(update->secondary); free(update->altsec); free(update->window); if (update->asynchronous) update_message_proxy_free(update->proxy); MessageQueue_Free(update->queue); free(update); } }
static void rail_virtual_channel_event_disconnected(railPlugin* rail) { UINT rc; if (MessageQueue_PostQuit(rail->queue, 0)) WaitForSingleObject(rail->thread, INFINITE); MessageQueue_Free(rail->queue); CloseHandle(rail->thread); rail->queue = NULL; rail->thread = NULL; rc = rail->channelEntryPoints.pVirtualChannelClose(rail->OpenHandle); if (CHANNEL_RC_OK != rc) { WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]", WTSErrorToString(rc), rc); } if (rail->data_in) { Stream_Free(rail->data_in, TRUE); rail->data_in = NULL; } rail_remove_open_handle_data(rail->OpenHandle); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData, UINT32 dataLength) { UINT status; status = rail->channelEntryPoints.pVirtualChannelOpenEx(rail->InitHandle, &rail->OpenHandle, rail->channelDef.name, rail_virtual_channel_open_event_ex); if (status != CHANNEL_RC_OK) { WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08"PRIX32"]", WTSErrorToString(status), status); return status; } rail->queue = MessageQueue_New(NULL); if (!rail->queue) { WLog_ERR(TAG, "MessageQueue_New failed!"); return CHANNEL_RC_NO_MEMORY; } if (!(rail->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); MessageQueue_Free(rail->queue); rail->queue = NULL; return ERROR_INTERNAL_ERROR; } return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT serial_free(DEVICE* device) { UINT error; SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device; WLog_Print(serial->log, WLOG_DEBUG, "freeing"); MessageQueue_PostQuit(serial->MainIrpQueue, 0); if (WaitForSingleObject(serial->MainThread, INFINITE) == WAIT_FAILED) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error); return error; } CloseHandle(serial->MainThread); if (serial->hComm) CloseHandle(serial->hComm); /* Clean up resources */ Stream_Free(serial->device.data, TRUE); MessageQueue_Free(serial->MainIrpQueue); ListDictionary_Free(serial->IrpThreads); DeleteCriticalSection(&serial->TerminatingIrpThreadsLock); free(serial); return CHANNEL_RC_OK; }
rdpChannels* freerdp_channels_new(void) { rdpChannels* channels; channels = (rdpChannels*) calloc(1, sizeof(rdpChannels)); if (!channels) return NULL; channels->queue = MessageQueue_New(NULL); if (!channels->queue) goto error_queue; if (!g_OpenHandles) { g_OpenHandles = HashTable_New(TRUE); if (!g_OpenHandles) goto error_open_handles; if (!InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000)) goto error_open_handles; } return channels; error_open_handles: MessageQueue_Free(channels->queue); error_queue: free(channels); return NULL; }
VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer) { int index; int count; rdpPeerChannel* channel; WTSVirtualChannelManager* vcm; vcm = (WTSVirtualChannelManager*) hServer; if (vcm) { HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR) vcm->SessionId); ArrayList_Lock(vcm->dynamicVirtualChannels); count = ArrayList_Count(vcm->dynamicVirtualChannels); for (index = 0; index < count; index++) { channel = (rdpPeerChannel*) ArrayList_GetItem(vcm->dynamicVirtualChannels, index); WTSVirtualChannelClose(channel); } ArrayList_Unlock(vcm->dynamicVirtualChannels); ArrayList_Free(vcm->dynamicVirtualChannels); if (vcm->drdynvc_channel) { WTSVirtualChannelClose(vcm->drdynvc_channel); vcm->drdynvc_channel = NULL; } MessageQueue_Free(vcm->queue); free(vcm); } }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_virtual_channel_event_disconnected(encomspPlugin* encomsp) { UINT rc; if (MessageQueue_PostQuit(encomsp->queue, 0) && (WaitForSingleObject(encomsp->thread, INFINITE) == WAIT_FAILED)) { rc = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc); return rc; } MessageQueue_Free(encomsp->queue); CloseHandle(encomsp->thread); encomsp->queue = NULL; encomsp->thread = NULL; rc = encomsp->channelEntryPoints.pVirtualChannelClose(encomsp->OpenHandle); if (CHANNEL_RC_OK != rc) { WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]", WTSErrorToString(rc), rc); return rc; } if (encomsp->data_in) { Stream_Free(encomsp->data_in, TRUE); encomsp->data_in = NULL; } encomsp_remove_open_handle_data(encomsp->OpenHandle); return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rail_virtual_channel_event_disconnected(railPlugin* rail) { UINT rc; if (MessageQueue_PostQuit(rail->queue, 0) && (WaitForSingleObject(rail->thread, INFINITE) == WAIT_FAILED)) { rc = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"", rc); return rc; } MessageQueue_Free(rail->queue); CloseHandle(rail->thread); rail->queue = NULL; rail->thread = NULL; rc = rail->channelEntryPoints.pVirtualChannelCloseEx(rail->InitHandle, rail->OpenHandle); if (CHANNEL_RC_OK != rc) { WLog_ERR(TAG, "pVirtualChannelCloseEx failed with %s [%08"PRIX32"]", WTSErrorToString(rc), rc); return rc; } rail->OpenHandle = 0; if (rail->data_in) { Stream_Free(rail->data_in, TRUE); rail->data_in = NULL; } return CHANNEL_RC_OK; }
BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle) { wStream* s; rdpMcs* mcs; WTSVirtualChannelManager* vcm; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; BOOL ret = TRUE; if (channel) { vcm = channel->vcm; mcs = vcm->client->context->rdp->mcs; if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC) { if (channel->index < mcs->channelCount) mcs->channels[channel->index].handle = NULL; } else { ArrayList_Remove(vcm->dynamicVirtualChannels, channel); if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED) { ULONG written; s = Stream_New(NULL, 8); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); ret = FALSE; } else { wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId); ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written); Stream_Free(s, TRUE); } } } if (channel->receiveData) Stream_Free(channel->receiveData, TRUE); if (channel->queue) { MessageQueue_Free(channel->queue); channel->queue = NULL; } free(channel); } return ret; }
void freerdp_channels_free(rdpChannels* channels) { if (channels->queue) { MessageQueue_Free(channels->queue); channels->queue = NULL; } free(channels); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdynvc) { UINT status; if (drdynvc->OpenHandle == 0) return CHANNEL_RC_OK; if (!drdynvc) return CHANNEL_RC_BAD_CHANNEL_HANDLE; if (!MessageQueue_PostQuit(drdynvc->queue, 0)) { status = GetLastError(); WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_PostQuit failed with error %"PRIu32"", status); return status; } if (WaitForSingleObject(drdynvc->thread, INFINITE) != WAIT_OBJECT_0) { status = GetLastError(); WLog_Print(drdynvc->log, WLOG_ERROR, "WaitForSingleObject failed with error %"PRIu32"", status); return status; } MessageQueue_Free(drdynvc->queue); CloseHandle(drdynvc->thread); drdynvc->queue = NULL; drdynvc->thread = NULL; status = drdynvc->channelEntryPoints.pVirtualChannelCloseEx(drdynvc->InitHandle, drdynvc->OpenHandle); if (status != CHANNEL_RC_OK) { WLog_Print(drdynvc->log, WLOG_ERROR, "pVirtualChannelClose failed with %s [%08"PRIX32"]", WTSErrorToString(status), status); } drdynvc->OpenHandle = 0; if (drdynvc->data_in) { Stream_Free(drdynvc->data_in, TRUE); drdynvc->data_in = NULL; } if (drdynvc->channel_mgr) { dvcman_free(drdynvc, drdynvc->channel_mgr); drdynvc->channel_mgr = NULL; } return status; }
void input_free(rdpInput* input) { if (input != NULL) { if (input->asynchronous) input_message_proxy_free(input->proxy); MessageQueue_Free(input->queue); free(input); } }
void smartcard_context_free(SMARTCARD_CONTEXT* pContext) { if (!pContext) return; MessageQueue_PostQuit(pContext->IrpQueue, 0); WaitForSingleObject(pContext->thread, INFINITE); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT smartcard_free(DEVICE* device) { UINT error; SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; /** * Calling smartcard_release_all_contexts to unblock all operations waiting for transactions * to unlock. */ smartcard_release_all_contexts(smartcard); /* Stopping all threads and cancelling all IRPs */ if (smartcard->IrpQueue) { if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); return error; } MessageQueue_Free(smartcard->IrpQueue); smartcard->IrpQueue = NULL; CloseHandle(smartcard->thread); smartcard->thread = NULL; } if (smartcard->device.data) { Stream_Free(smartcard->device.data, TRUE); smartcard->device.data = NULL; } ListDictionary_Free(smartcard->rgSCardContextList); ListDictionary_Free(smartcard->rgOutstandingMessages); Queue_Free(smartcard->CompletedIrpQueue); if (smartcard->StartedEvent) { SCardReleaseStartedEvent(); smartcard->StartedEvent = NULL; } free(device); return CHANNEL_RC_OK; }
static void parallel_free(DEVICE* device) { PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; DEBUG_SVC("freeing device"); MessageQueue_PostQuit(parallel->queue, 0); WaitForSingleObject(parallel->thread, INFINITE); CloseHandle(parallel->thread); Stream_Free(parallel->device.data, TRUE); MessageQueue_Free(parallel->queue); free(parallel); }
void smartcard_context_free(SMARTCARD_CONTEXT* pContext) { if (!pContext) return; /* cancel blocking calls like SCardGetStatusChange */ SCardCancel(pContext->hContext); if (MessageQueue_PostQuit(pContext->IrpQueue, 0)) WaitForSingleObject(pContext->thread, INFINITE); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); }
void smartcard_context_free(SMARTCARD_CONTEXT* pContext) { if (!pContext) return; /* cancel blocking calls like SCardGetStatusChange */ SCardCancel(pContext->hContext); if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED)) WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); }
static void drive_free(DEVICE* device) { DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device; MessageQueue_PostQuit(drive->IrpQueue, 0); WaitForSingleObject(drive->thread, INFINITE); CloseHandle(drive->thread); ListDictionary_Free(drive->files); MessageQueue_Free(drive->IrpQueue); Stream_Free(drive->device.data, TRUE); free(drive); }
void freerdp_channels_free(rdpChannels* channels) { int index; int nkeys; ULONG_PTR* pKeys = NULL; CHANNEL_OPEN_DATA* pChannelOpenData; if (!channels) return; if (channels->queue) { MessageQueue_Free(channels->queue); channels->queue = NULL; } for (index = 0; index < channels->clientDataCount; index++) { pChannelOpenData = &channels->openDataList[index]; if (pChannelOpenData->pInterface) { free(pChannelOpenData->pInterface); pChannelOpenData->pInterface = NULL; } HashTable_Remove(g_OpenHandles, (void*) (UINT_PTR)pChannelOpenData->OpenHandle); } if (g_OpenHandles) { nkeys = HashTable_GetKeys(g_OpenHandles, &pKeys); if (nkeys == 0) { HashTable_Free(g_OpenHandles); DeleteCriticalSection(&g_channels_lock); g_OpenHandles = NULL; } free(pKeys); } free(channels); }
void freerdp_channels_free(rdpChannels* channels) { if (!channels) return; DeleteCriticalSection(&channels->channelsLock); if (channels->queue) { MessageQueue_Free(channels->queue); channels->queue = NULL; } if (channels->openHandles) HashTable_Free(channels->openHandles); free(channels); }
static void smartcard_free(DEVICE* device) { SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; MessageQueue_PostQuit(smartcard->IrpQueue, 0); WaitForSingleObject(smartcard->thread, INFINITE); CloseHandle(smartcard->thread); Stream_Free(smartcard->device.data, TRUE); MessageQueue_Free(smartcard->IrpQueue); ListDictionary_Free(smartcard->rgSCardContextList); ListDictionary_Free(smartcard->rgOutstandingMessages); Queue_Free(smartcard->CompletedIrpQueue); free(device); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVOID pData, UINT32 dataLength) { UINT32 status; UINT error; status = remdesk->channelEntryPoints.pVirtualChannelOpen(remdesk->InitHandle, &remdesk->OpenHandle, remdesk->channelDef.name, remdesk_virtual_channel_open_event); if (status != CHANNEL_RC_OK) { WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]", WTSErrorToString(status), status); return status; } if ((error = remdesk_add_open_handle_data(remdesk->OpenHandle, remdesk))) { WLog_ERR(TAG, "remdesk_add_open_handle_data failed with error %lu", error); return error; } remdesk->queue = MessageQueue_New(NULL); if (!remdesk->queue) { WLog_ERR(TAG, "MessageQueue_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } remdesk->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk, 0, NULL); if (!remdesk->thread) { WLog_ERR(TAG, "CreateThread failed"); error = ERROR_INTERNAL_ERROR; goto error_out; } return CHANNEL_RC_OK; error_out: remdesk_remove_open_handle_data(remdesk->OpenHandle); MessageQueue_Free(remdesk->queue); remdesk->queue = NULL; return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT parallel_free(DEVICE* device) { UINT error; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; if (MessageQueue_PostQuit(parallel->queue, 0) && (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); return error; } CloseHandle(parallel->thread); Stream_Free(parallel->device.data, TRUE); MessageQueue_Free(parallel->queue); free(parallel); return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVOID pData, UINT32 dataLength) { UINT32 status; UINT error; status = remdesk->channelEntryPoints.pVirtualChannelOpenEx(remdesk->InitHandle, &remdesk->OpenHandle, remdesk->channelDef.name, remdesk_virtual_channel_open_event_ex); if (status != CHANNEL_RC_OK) { WLog_ERR(TAG, "pVirtualChannelOpenEx failed with %s [%08"PRIX32"]", WTSErrorToString(status), status); return status; } remdesk->queue = MessageQueue_New(NULL); if (!remdesk->queue) { WLog_ERR(TAG, "MessageQueue_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } remdesk->thread = CreateThread(NULL, 0, remdesk_virtual_channel_client_thread, (void*) remdesk, 0, NULL); if (!remdesk->thread) { WLog_ERR(TAG, "CreateThread failed"); error = ERROR_INTERNAL_ERROR; goto error_out; } return CHANNEL_RC_OK; error_out: MessageQueue_Free(remdesk->queue); remdesk->queue = NULL; return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_free(DEVICE* device) { DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device; UINT error = CHANNEL_RC_OK; if (MessageQueue_PostQuit(drive->IrpQueue, 0) && (WaitForSingleObject(drive->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %u", error); return error; } CloseHandle(drive->thread); ListDictionary_Free(drive->files); MessageQueue_Free(drive->IrpQueue); Stream_Free(drive->device.data, TRUE); free(drive); return error; }
int TestMessageQueue(int argc, char* argv[]) { HANDLE thread; wMessageQueue* queue; queue = MessageQueue_New(NULL); thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL); MessageQueue_Post(queue, NULL, 123, NULL, NULL); MessageQueue_Post(queue, NULL, 456, NULL, NULL); MessageQueue_Post(queue, NULL, 789, NULL, NULL); MessageQueue_PostQuit(queue, 0); WaitForSingleObject(thread, INFINITE); MessageQueue_Free(queue); return 0; }