misc fixes:

fixed all bugs from the review
checking all WaitFor*Object/s calls
This commit is contained in:
Martin Haimberger 2015-07-30 06:49:21 -07:00
parent c605e32b6b
commit 65fd259610
34 changed files with 898 additions and 210 deletions

View File

@ -111,6 +111,7 @@ static WIN32ERROR audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, in
BYTE* encoded_data; BYTE* encoded_data;
int rbytes_per_frame; int rbytes_per_frame;
int tbytes_per_frame; int tbytes_per_frame;
int status;
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel; rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel; tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
@ -134,7 +135,16 @@ static WIN32ERROR audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, in
while (frames > 0) while (frames > 0)
{ {
if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0) status = WaitForSingleObject(alsa->stopEvent, 0);
if (status == WAIT_FAILED)
{
ret = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
break;
}
if (status == WAIT_OBJECT_0)
break; break;
cframes = alsa->frames_per_packet - alsa->buffer_frames; cframes = alsa->frames_per_packet - alsa->buffer_frames;
@ -170,7 +180,16 @@ static WIN32ERROR audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, in
encoded_size = alsa->buffer_frames * tbytes_per_frame; encoded_size = alsa->buffer_frames * tbytes_per_frame;
} }
if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0) status = WaitForSingleObject(alsa->stopEvent, 0);
if (status == WAIT_FAILED)
{
ret = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
break;
}
if (status == WAIT_OBJECT_0)
break; break;
else else
{ {
@ -201,6 +220,7 @@ static void* audin_alsa_thread_func(void* arg)
int tbytes_per_frame; int tbytes_per_frame;
snd_pcm_t* capture_handle = NULL; snd_pcm_t* capture_handle = NULL;
AudinALSADevice* alsa = (AudinALSADevice*) arg; AudinALSADevice* alsa = (AudinALSADevice*) arg;
DWORD status;
DEBUG_DVC("in"); DEBUG_DVC("in");
@ -210,57 +230,66 @@ static void* audin_alsa_thread_func(void* arg)
if (!buffer) if (!buffer)
{ {
WLog_ERR(TAG, "calloc failed!"); WLog_ERR(TAG, "calloc failed!");
error = CHANNEL_RC_NO_MEMORY;
if (alsa->rdpcontext) if (alsa->rdpcontext)
setChannelError(alsa->rdpcontext, CHANNEL_RC_NO_MEMORY, "calloc failed!"); setChannelError(alsa->rdpcontext, error, "calloc failed!");
ExitThread((DWORD)CHANNEL_RC_NO_MEMORY); goto out;
return NULL;
} }
freerdp_dsp_context_reset_adpcm(alsa->dsp_context); freerdp_dsp_context_reset_adpcm(alsa->dsp_context);
do if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0)
{ {
if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0) WLog_ERR(TAG, "snd_pcm_open (%s)", snd_strerror(error));
{ goto out;
WLog_ERR(TAG, "snd_pcm_open (%s)", snd_strerror(error)); }
break;
}
if (!audin_alsa_set_params(alsa, capture_handle)) if (!audin_alsa_set_params(alsa, capture_handle))
{ {
break; WLog_ERR(TAG, "audin_alsa_set_params failed");
} goto out;
}
while (!(WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0)) while(1)
{ {
error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet); status = WaitForSingleObject(alsa->stopEvent, 0);
if (error == -EPIPE) if (status == WAIT_FAILED)
{ {
snd_pcm_recover(capture_handle, error, 0); error = GetLastError();
continue; WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
} break;
else if (error < 0) }
{
WLog_ERR(TAG, "snd_pcm_readi (%s)", snd_strerror(error));
break;
}
if ((error = audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame))) if (status == WAIT_OBJECT_0)
{ break;
WLog_ERR(TAG, "audin_alsa_thread_receive failed with error %lu", error);
break;
}
} error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet);
}
while (0); if (error == -EPIPE)
{
snd_pcm_recover(capture_handle, error, 0);
continue;
}
else if (error < 0)
{
WLog_ERR(TAG, "snd_pcm_readi (%s)", snd_strerror(error));
break;
}
if ((error = audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame)))
{
WLog_ERR(TAG, "audin_alsa_thread_receive failed with error %lu", error);
break;
}
}
free(buffer); free(buffer);
if (capture_handle) if (capture_handle)
snd_pcm_close(capture_handle); snd_pcm_close(capture_handle);
out:
DEBUG_DVC("out"); DEBUG_DVC("out");
if (error && alsa->rdpcontext) if (error && alsa->rdpcontext)
setChannelError(alsa->rdpcontext, error, "audin_alsa_thread_func reported an error"); setChannelError(alsa->rdpcontext, error, "audin_alsa_thread_func reported an error");
@ -389,12 +418,18 @@ error_out:
static WIN32ERROR audin_alsa_close(IAudinDevice* device) static WIN32ERROR audin_alsa_close(IAudinDevice* device)
{ {
WIN32ERROR error = CHANNEL_RC_OK;
AudinALSADevice* alsa = (AudinALSADevice*) device; AudinALSADevice* alsa = (AudinALSADevice*) device;
if (alsa->stopEvent) if (alsa->stopEvent)
{ {
SetEvent(alsa->stopEvent); SetEvent(alsa->stopEvent);
WaitForSingleObject(alsa->thread, INFINITE); if (WaitForSingleObject(alsa->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(alsa->stopEvent); CloseHandle(alsa->stopEvent);
alsa->stopEvent = NULL; alsa->stopEvent = NULL;
@ -409,7 +444,7 @@ static WIN32ERROR audin_alsa_close(IAudinDevice* device)
alsa->receive = NULL; alsa->receive = NULL;
alsa->user_data = NULL; alsa->user_data = NULL;
return CHANNEL_RC_OK; return error;
} }
COMMAND_LINE_ARGUMENT_A audin_alsa_args[] = COMMAND_LINE_ARGUMENT_A audin_alsa_args[] =

View File

@ -83,6 +83,7 @@ static void* audin_opensles_thread_func(void* arg)
const size_t raw_size = opensles->frames_per_packet * opensles->bytes_per_channel; const size_t raw_size = opensles->frames_per_packet * opensles->bytes_per_channel;
int rc = CHANNEL_RC_OK; int rc = CHANNEL_RC_OK;
WIN32ERROR error = CHANNEL_RC_OK; WIN32ERROR error = CHANNEL_RC_OK;
DWORD status;
DEBUG_DVC("opensles=%p", opensles); DEBUG_DVC("opensles=%p", opensles);
@ -95,18 +96,31 @@ static void* audin_opensles_thread_func(void* arg)
buffer.v = calloc(1, raw_size); buffer.v = calloc(1, raw_size);
if (!buffer.v) if (!buffer.v)
{ {
error = CHANNEL_RC_NO_MEMORY;
WLog_ERR(TAG, "calloc failed!"); WLog_ERR(TAG, "calloc failed!");
if (opensles->rdpcontext) if (opensles->rdpcontext)
setChannelError(opensles->rdpcontext, CHANNEL_RC_NO_MEMORY, "audin_opensles_thread_func reported an error"); setChannelError(opensles->rdpcontext, CHANNEL_RC_NO_MEMORY, "audin_opensles_thread_func reported an error");
ExitThread((DWORD)CHANNEL_RC_NO_MEMORY); goto out;
return NULL;
} }
freerdp_dsp_context_reset_adpcm(opensles->dsp_context); freerdp_dsp_context_reset_adpcm(opensles->dsp_context);
while (WAIT_OBJECT_0 != WaitForSingleObject(opensles->stopEvent, 0)) while (1)
{ {
size_t encoded_size;
status = WaitForSingleObject(opensles->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
break;
size_t encoded_size;
void *encoded_data; void *encoded_data;
rc = android_RecIn(opensles->stream, buffer.s, raw_size); rc = android_RecIn(opensles->stream, buffer.s, raw_size);
@ -154,7 +168,7 @@ static void* audin_opensles_thread_func(void* arg)
} }
free(buffer.v); free(buffer.v);
out:
DEBUG_DVC("thread shutdown."); DEBUG_DVC("thread shutdown.");
if (error && opensles->rdpcontext) if (error && opensles->rdpcontext)
@ -348,6 +362,7 @@ error_out:
static WIN32ERROR audin_opensles_close(IAudinDevice* device) static WIN32ERROR audin_opensles_close(IAudinDevice* device)
{ {
WIN32ERROR error;
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device; AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
DEBUG_DVC("device=%p", device); DEBUG_DVC("device=%p", device);
@ -367,7 +382,12 @@ static WIN32ERROR audin_opensles_close(IAudinDevice* device)
assert(opensles->stream); assert(opensles->stream);
SetEvent(opensles->stopEvent); SetEvent(opensles->stopEvent);
WaitForSingleObject(opensles->thread, INFINITE); if (WaitForSingleObject(opensles->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(opensles->stopEvent); CloseHandle(opensles->stopEvent);
CloseHandle(opensles->thread); CloseHandle(opensles->thread);

View File

@ -339,6 +339,7 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
{ {
queue_element *e; queue_element *e;
int rc; int rc;
DWORD status;
assert(p); assert(p);
assert(buffer); assert(buffer);
@ -366,7 +367,15 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
/* Wait for queue to be filled... */ /* Wait for queue to be filled... */
if (!Queue_Count(p->queue)) if (!Queue_Count(p->queue))
WaitForSingleObject(p->queue->event, INFINITE); {
status = WaitForSingleObject(p->queue->event, INFINITE);
if (status == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", GetLastError());
return -1;
}
}
e = Queue_Dequeue(p->queue); e = Queue_Dequeue(p->queue);
if (!e) if (!e)
@ -383,6 +392,6 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
free(e->data); free(e->data);
free(e); free(e);
return rc; return rc;
} }

View File

@ -173,8 +173,9 @@ static void* audin_oss_thread_func(void* arg)
int tmp, buffer_size, encoded_size; int tmp, buffer_size, encoded_size;
AudinOSSDevice* oss = (AudinOSSDevice*)arg; AudinOSSDevice* oss = (AudinOSSDevice*)arg;
WIN32ERROR error; WIN32ERROR error;
DWORD status;
if (arg == NULL) if (arg == NULL)
{ {
error = ERROR_INVALID_PARAMETER; error = ERROR_INVALID_PARAMETER;
goto err_out; goto err_out;
@ -263,8 +264,20 @@ static void* audin_oss_thread_func(void* arg)
ZeroMemory(buffer, buffer_size); ZeroMemory(buffer, buffer_size);
freerdp_dsp_context_reset_adpcm(oss->dsp_context); freerdp_dsp_context_reset_adpcm(oss->dsp_context);
while (WaitForSingleObject(oss->stopEvent, 0) != WAIT_OBJECT_0) while (1)
{ {
status = WaitForSingleObject(oss->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
goto err_out;
}
if (status == WAIT_OBJECT_0)
break;
tmp = read(pcm_handle, buffer, buffer_size); tmp = read(pcm_handle, buffer, buffer_size);
/* Error happen. */ /* Error happen. */
@ -353,6 +366,7 @@ static WIN32ERROR audin_oss_open(IAudinDevice *device, AudinReceive receive, voi
static WIN32ERROR audin_oss_close(IAudinDevice *device) static WIN32ERROR audin_oss_close(IAudinDevice *device)
{ {
WIN32ERROR error;
AudinOSSDevice *oss = (AudinOSSDevice*)device; AudinOSSDevice *oss = (AudinOSSDevice*)device;
if (device == NULL) if (device == NULL)
@ -361,7 +375,12 @@ static WIN32ERROR audin_oss_close(IAudinDevice *device)
if (oss->stopEvent != NULL) if (oss->stopEvent != NULL)
{ {
SetEvent(oss->stopEvent); SetEvent(oss->stopEvent);
WaitForSingleObject(oss->thread, INFINITE); if (WaitForSingleObject(oss->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(oss->stopEvent); CloseHandle(oss->stopEvent);
oss->stopEvent = NULL; oss->stopEvent = NULL;
CloseHandle(oss->thread); CloseHandle(oss->thread);

View File

@ -100,6 +100,7 @@ static DWORD audin_winmm_thread_func(void* arg)
char *buffer; char *buffer;
int size, i; int size, i;
WAVEHDR waveHdr[4]; WAVEHDR waveHdr[4];
DWORD status;
if (!winmm->hWaveIn) if (!winmm->hWaveIn)
{ {
@ -136,7 +137,14 @@ static DWORD audin_winmm_thread_func(void* arg)
} }
waveInStart(winmm->hWaveIn); waveInStart(winmm->hWaveIn);
WaitForSingleObject(winmm->stopEvent, INFINITE); status = WaitForSingleObject(winmm->stopEvent, INFINITE);
if (status == WAIT_FAILED)
{
DEBUG_DVC("WaitForSingleObject failed.");
if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
}
waveInStop(winmm->hWaveIn); waveInStop(winmm->hWaveIn);
@ -176,11 +184,20 @@ static WIN32ERROR audin_winmm_free(IAudinDevice* device)
static WIN32ERROR audin_winmm_close(IAudinDevice* device) static WIN32ERROR audin_winmm_close(IAudinDevice* device)
{ {
DWORD status;
WIN32ERROR error = CHANNEL_RC_OK;
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device; AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
SetEvent(winmm->stopEvent); SetEvent(winmm->stopEvent);
WaitForSingleObject(winmm->thread, INFINITE); status = WaitForSingleObject(winmm->thread, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(winmm->thread); CloseHandle(winmm->thread);
CloseHandle(winmm->stopEvent); CloseHandle(winmm->stopEvent);
@ -190,7 +207,7 @@ static WIN32ERROR audin_winmm_close(IAudinDevice* device)
winmm->receive = NULL; winmm->receive = NULL;
winmm->user_data = NULL; winmm->user_data = NULL;
return CHANNEL_RC_OK; return error;
} }
static WIN32ERROR audin_winmm_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket) static WIN32ERROR audin_winmm_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket)

View File

@ -215,6 +215,8 @@ static WIN32ERROR audin_server_recv_formats(audin_server* audin, wStream* s, UIN
} }
IFCALLRET(audin->context.Opening, success, &audin->context); IFCALLRET(audin->context.Opening, success, &audin->context);
if (success)
WLog_ERR(TAG, "context.Opening failed with error %lu", success);
return success; return success;
} }
@ -267,6 +269,9 @@ static WIN32ERROR audin_server_recv_open_reply(audin_server* audin, wStream* s,
IFCALLRET(audin->context.OpenResult, success, &audin->context, Result); IFCALLRET(audin->context.OpenResult, success, &audin->context, Result);
if (success)
WLog_ERR(TAG, "context.OpenResult failed with error %lu", success);
return success; return success;
} }
@ -330,7 +335,10 @@ static WIN32ERROR audin_server_recv_data(audin_server* audin, wStream* s, UINT32
IFCALLRET(audin->context.ReceiveSamples, success, &audin->context, src, frames); IFCALLRET(audin->context.ReceiveSamples, success, &audin->context, src, frames);
return success; if (success)
WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", success);
return success;
} }
static void* audin_server_thread_func(void* arg) static void* audin_server_thread_func(void* arg)
@ -345,6 +353,7 @@ static void* audin_server_thread_func(void* arg)
DWORD BytesReturned = 0; DWORD BytesReturned = 0;
audin_server* audin = (audin_server*) arg; audin_server* audin = (audin_server*) arg;
WIN32ERROR error = CHANNEL_RC_OK; WIN32ERROR error = CHANNEL_RC_OK;
DWORD status;
buffer = NULL; buffer = NULL;
BytesReturned = 0; BytesReturned = 0;
@ -372,9 +381,16 @@ static void* audin_server_thread_func(void* arg)
while (1) while (1)
{ {
if (WaitForMultipleObjects(nCount, events, FALSE, 100) == WAIT_OBJECT_0) if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0)
goto out; goto out;
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
goto out;
}
if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &BytesReturned) == FALSE) if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &BytesReturned) == FALSE)
{ {
WLog_ERR(TAG, "WTSVirtualChannelQuery failed"); WLog_ERR(TAG, "WTSVirtualChannelQuery failed");
@ -410,9 +426,16 @@ static void* audin_server_thread_func(void* arg)
while (ready) while (ready)
{ {
if (WaitForMultipleObjects(nCount, events, FALSE, INFINITE) == WAIT_OBJECT_0) if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
break; break;
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
goto out;
}
Stream_SetPosition(s, 0); Stream_SetPosition(s, 0);
if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned)) if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned))
@ -559,7 +582,12 @@ static BOOL audin_server_close(audin_server_context* context)
if (audin->thread) if (audin->thread)
{ {
SetEvent(audin->stopEvent); SetEvent(audin->stopEvent);
WaitForSingleObject(audin->thread, INFINITE); if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", GetLastError());
return FALSE;
}
CloseHandle(audin->thread); CloseHandle(audin->thread);
CloseHandle(audin->stopEvent); CloseHandle(audin->stopEvent);
audin->thread = NULL; audin->thread = NULL;

View File

@ -860,7 +860,7 @@ WIN32ERROR cliprdr_add_init_handle_data(void* pInitHandle, void* pUserData)
WLog_ERR(TAG, "ListDictionary_Add failed!"); WLog_ERR(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* cliprdr_get_init_handle_data(void* pInitHandle) void* cliprdr_get_init_handle_data(void* pInitHandle)
@ -899,7 +899,7 @@ WIN32ERROR cliprdr_add_open_handle_data(DWORD openHandle, void* pUserData)
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* cliprdr_get_open_handle_data(DWORD openHandle) void* cliprdr_get_open_handle_data(DWORD openHandle)
@ -1096,8 +1096,12 @@ static WIN32ERROR cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* clip
{ {
UINT rc; UINT rc;
if (MessageQueue_PostQuit(cliprdr->queue, 0)) if (MessageQueue_PostQuit(cliprdr->queue, 0) && (WaitForSingleObject(cliprdr->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(cliprdr->thread, INFINITE); {
rc = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc);
return rc;
}
MessageQueue_Free(cliprdr->queue); MessageQueue_Free(cliprdr->queue);
CloseHandle(cliprdr->thread); CloseHandle(cliprdr->thread);

View File

@ -106,7 +106,7 @@ WIN32ERROR cliprdr_server_packet_send(CliprdrServerPrivate* cliprdr, wStream* s)
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return status ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
} }
static WIN32ERROR cliprdr_server_capabilities(CliprdrServerContext* context, CLIPRDR_CAPABILITIES* capabilities) static WIN32ERROR cliprdr_server_capabilities(CliprdrServerContext* context, CLIPRDR_CAPABILITIES* capabilities)
@ -1022,6 +1022,7 @@ WIN32ERROR cliprdr_server_read(CliprdrServerContext* context)
CLIPRDR_HEADER header; CLIPRDR_HEADER header;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
WIN32ERROR error; WIN32ERROR error;
DWORD status;
s = cliprdr->s; s = cliprdr->s;
@ -1030,8 +1031,17 @@ WIN32ERROR cliprdr_server_read(CliprdrServerContext* context)
BytesReturned = 0; BytesReturned = 0;
BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s); BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s);
if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0) status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
return ERROR_SUCCESS;
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
if (status == WAIT_TIMEOUT)
return CHANNEL_RC_OK;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned)) (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
@ -1065,8 +1075,17 @@ WIN32ERROR cliprdr_server_read(CliprdrServerContext* context)
BytesReturned = 0; BytesReturned = 0;
BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s); BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s);
if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0) status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
return ERROR_SUCCESS;
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
if (status == WAIT_TIMEOUT)
return CHANNEL_RC_OK;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned)) (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
@ -1094,8 +1113,17 @@ WIN32ERROR cliprdr_server_read(CliprdrServerContext* context)
/* check for trailing zero bytes */ /* check for trailing zero bytes */
if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0) status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
return ERROR_SUCCESS;
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
if (status == WAIT_TIMEOUT)
return CHANNEL_RC_OK;
BytesReturned = 0; BytesReturned = 0;
BytesToRead = 4; BytesToRead = 4;
@ -1154,10 +1182,35 @@ static void* cliprdr_server_thread(void* arg)
{ {
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(cliprdr->StopEvent, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
goto out;
}
status = WaitForSingleObject(cliprdr->StopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
goto out;
}
if (status == WAIT_OBJECT_0)
break; break;
if (WaitForSingleObject(ChannelEvent, 0) == WAIT_OBJECT_0) status = WaitForSingleObject(ChannelEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
goto out;
}
if (status == WAIT_OBJECT_0)
{ {
if ((error = context->CheckEventHandle(context))) if ((error = context->CheckEventHandle(context)))
{ {
@ -1265,12 +1318,18 @@ static WIN32ERROR cliprdr_server_start(CliprdrServerContext* context)
static WIN32ERROR cliprdr_server_stop(CliprdrServerContext* context) static WIN32ERROR cliprdr_server_stop(CliprdrServerContext* context)
{ {
WIN32ERROR error = CHANNEL_RC_OK;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle; CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (cliprdr->StopEvent) if (cliprdr->StopEvent)
{ {
SetEvent(cliprdr->StopEvent); SetEvent(cliprdr->StopEvent);
WaitForSingleObject(cliprdr->Thread, INFINITE); if (WaitForSingleObject(cliprdr->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(cliprdr->Thread); CloseHandle(cliprdr->Thread);
CloseHandle(cliprdr->StopEvent); CloseHandle(cliprdr->StopEvent);
} }
@ -1278,7 +1337,7 @@ static WIN32ERROR cliprdr_server_stop(CliprdrServerContext* context)
if (cliprdr->ChannelHandle) if (cliprdr->ChannelHandle)
return context->Close(context); return context->Close(context);
return CHANNEL_RC_OK; return error;
} }
static HANDLE cliprdr_server_get_event_handle(CliprdrServerContext* context) static HANDLE cliprdr_server_get_event_handle(CliprdrServerContext* context)

View File

@ -437,6 +437,9 @@ WIN32ERROR dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32
context = dvcman->drdynvc->context; context = dvcman->drdynvc->context;
IFCALLRET(context->OnChannelConnected, error, context, ChannelName, listener->iface.pInterface); IFCALLRET(context->OnChannelConnected, error, context, ChannelName, listener->iface.pInterface);
if (error)
WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", error);
return error; return error;
} }
else else
@ -475,12 +478,11 @@ WIN32ERROR dvcman_open_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 Ch
if (channel->status == CHANNEL_RC_OK) if (channel->status == CHANNEL_RC_OK)
{ {
pCallback = channel->channel_callback; pCallback = channel->channel_callback;
if (pCallback->OnOpen) if ((pCallback->OnOpen) && (error = pCallback->OnOpen(pCallback)))
if ((error = pCallback->OnOpen(pCallback))) {
{ WLog_ERR(TAG, "OnOpen failed with eror %lu!", error);
WLog_ERR(TAG, "OnOpen failed with eror %lu!", error); return error;
return error; }
}
WLog_DBG(TAG, "open_channel: ChannelId %d", ChannelId); WLog_DBG(TAG, "open_channel: ChannelId %d", ChannelId);
} }
@ -518,12 +520,11 @@ WIN32ERROR dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 C
ichannel = (IWTSVirtualChannel*) channel; ichannel = (IWTSVirtualChannel*) channel;
if (ichannel->Close) if ((ichannel->Close) && (error = ichannel->Close(ichannel)))
if ((error = ichannel->Close(ichannel))) {
{ WLog_ERR(TAG, "Close failed with eror %lu!", error);
WLog_ERR(TAG, "Close failed with eror %lu!", error); return error;
return error; }
}
} }
ArrayList_Remove(dvcman->channels, channel); ArrayList_Remove(dvcman->channels, channel);
@ -1038,7 +1039,7 @@ WIN32ERROR drdynvc_add_init_handle_data(void* pInitHandle, void* pUserData)
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* drdynvc_get_init_handle_data(void* pInitHandle) void* drdynvc_get_init_handle_data(void* pInitHandle)
@ -1077,7 +1078,7 @@ WIN32ERROR drdynvc_add_open_handle_data(DWORD openHandle, void* pUserData)
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* drdynvc_get_open_handle_data(DWORD openHandle) void* drdynvc_get_open_handle_data(DWORD openHandle)
@ -1309,8 +1310,12 @@ static WIN32ERROR drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdy
{ {
WIN32ERROR status; WIN32ERROR status;
if (MessageQueue_PostQuit(drdynvc->queue, 0)) if (MessageQueue_PostQuit(drdynvc->queue, 0) && (WaitForSingleObject(drdynvc->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(drdynvc->thread, INFINITE); {
status = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", status);
return status;
}
MessageQueue_Free(drdynvc->queue); MessageQueue_Free(drdynvc->queue);
CloseHandle(drdynvc->thread); CloseHandle(drdynvc->thread);

View File

@ -142,9 +142,15 @@ static WIN32ERROR drdynvc_server_start(DrdynvcServerContext* context)
static WIN32ERROR drdynvc_server_stop(DrdynvcServerContext* context) static WIN32ERROR drdynvc_server_stop(DrdynvcServerContext* context)
{ {
WIN32ERROR error;
SetEvent(context->priv->StopEvent); SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE); if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(context->priv->Thread); CloseHandle(context->priv->Thread);
return CHANNEL_RC_OK; return CHANNEL_RC_OK;

View File

@ -671,12 +671,17 @@ static WIN32ERROR drive_irp_request(DEVICE* device, IRP* irp)
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
static void drive_free(DEVICE* device) static WIN32ERROR drive_free(DEVICE* device)
{ {
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device; DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
WIN32ERROR error = CHANNEL_RC_OK;
if (MessageQueue_PostQuit(drive->IrpQueue, 0)) if (MessageQueue_PostQuit(drive->IrpQueue, 0) && (WaitForSingleObject(drive->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(drive->thread, INFINITE); {
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(drive->thread); CloseHandle(drive->thread);
@ -686,6 +691,7 @@ static void drive_free(DEVICE* device)
Stream_Free(drive->device.data, TRUE); Stream_Free(drive->device.data, TRUE);
free(drive); free(drive);
return error;
} }
WIN32ERROR drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path) WIN32ERROR drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)

View File

@ -76,7 +76,12 @@ static WIN32ERROR echo_server_open_channel(echo_server* echo)
while (echo->echo_channel == NULL) while (echo->echo_channel == NULL)
{ {
WaitForSingleObject(hEvent, 1000); if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED)
{
Error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", Error);
return Error;
}
echo->echo_channel = WTSVirtualChannelOpenEx(echo->SessionId, echo->echo_channel = WTSVirtualChannelOpenEx(echo->SessionId,
"ECHO", WTS_CHANNEL_OPTION_DYNAMIC); "ECHO", WTS_CHANNEL_OPTION_DYNAMIC);
@ -106,6 +111,7 @@ static void* echo_server_thread_func(void* arg)
DWORD BytesReturned = 0; DWORD BytesReturned = 0;
echo_server* echo = (echo_server*) arg; echo_server* echo = (echo_server*) arg;
WIN32ERROR error; WIN32ERROR error;
DWORD status;
if ((error = echo_server_open_channel(echo))) if ((error = echo_server_open_channel(echo)))
{ {
@ -134,7 +140,16 @@ static void* echo_server_thread_func(void* arg)
while (1) while (1)
{ {
if (WaitForMultipleObjects(nCount, events, FALSE, 100) == WAIT_OBJECT_0) status = WaitForMultipleObjects(nCount, events, FALSE, 100);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
break;
}
if (status == WAIT_OBJECT_0)
{ {
IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_CLOSED); IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_CLOSED);
if (error) if (error)
@ -174,7 +189,16 @@ static void* echo_server_thread_func(void* arg)
while (ready) while (ready)
{ {
if (WaitForMultipleObjects(nCount, events, FALSE, INFINITE) == WAIT_OBJECT_0) status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
break;
}
if (status == WAIT_OBJECT_0)
break; break;
Stream_SetPosition(s, 0); Stream_SetPosition(s, 0);
@ -240,18 +264,26 @@ static WIN32ERROR echo_server_open(echo_server_context* context)
static WIN32ERROR echo_server_close(echo_server_context* context) static WIN32ERROR echo_server_close(echo_server_context* context)
{ {
WIN32ERROR error = CHANNEL_RC_OK;
echo_server* echo = (echo_server*) context; echo_server* echo = (echo_server*) context;
if (echo->thread) if (echo->thread)
{ {
SetEvent(echo->stopEvent); SetEvent(echo->stopEvent);
WaitForSingleObject(echo->thread, INFINITE);
if (WaitForSingleObject(echo->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(echo->thread); CloseHandle(echo->thread);
CloseHandle(echo->stopEvent); CloseHandle(echo->stopEvent);
echo->thread = NULL; echo->thread = NULL;
echo->stopEvent = NULL; echo->stopEvent = NULL;
} }
return CHANNEL_RC_OK; return error;
} }
static BOOL echo_server_request(echo_server_context* context, const BYTE* buffer, UINT32 length) static BOOL echo_server_request(echo_server_context* context, const BYTE* buffer, UINT32 length)

View File

@ -1105,8 +1105,12 @@ static WIN32ERROR encomsp_virtual_channel_event_disconnected(encomspPlugin* enco
{ {
UINT rc; UINT rc;
if (MessageQueue_PostQuit(encomsp->queue, 0)) if (MessageQueue_PostQuit(encomsp->queue, 0) && (WaitForSingleObject(encomsp->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(encomsp->thread, INFINITE); {
rc = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc);
return rc;
}
MessageQueue_Free(encomsp->queue); MessageQueue_Free(encomsp->queue);
CloseHandle(encomsp->thread); CloseHandle(encomsp->thread);

View File

@ -168,6 +168,7 @@ static void* encomsp_server_thread(void* arg)
ENCOMSP_ORDER_HEADER* header; ENCOMSP_ORDER_HEADER* header;
EncomspServerContext* context; EncomspServerContext* context;
WIN32ERROR error = CHANNEL_RC_OK; WIN32ERROR error = CHANNEL_RC_OK;
DWORD status;
context = (EncomspServerContext*) arg; context = (EncomspServerContext*) arg;
@ -197,9 +198,25 @@ static void* encomsp_server_thread(void* arg)
while (1) while (1)
{ {
WaitForMultipleObjects(nCount, events, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
break;
}
status = WaitForSingleObject(context->priv->StopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
break;
}
if (status == WAIT_OBJECT_0)
{ {
break; break;
} }
@ -275,12 +292,18 @@ static WIN32ERROR encomsp_server_start(EncomspServerContext* context)
static WIN32ERROR encomsp_server_stop(EncomspServerContext* context) static WIN32ERROR encomsp_server_stop(EncomspServerContext* context)
{ {
WIN32ERROR error = CHANNEL_RC_OK;
SetEvent(context->priv->StopEvent); SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE); if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(context->priv->Thread); CloseHandle(context->priv->Thread);
return CHANNEL_RC_OK; return error;
} }
EncomspServerContext* encomsp_server_context_new(HANDLE vcm) EncomspServerContext* encomsp_server_context_new(HANDLE vcm)

View File

@ -332,18 +332,24 @@ static WIN32ERROR parallel_irp_request(DEVICE* device, IRP* irp)
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
static void parallel_free(DEVICE* device) static WIN32ERROR parallel_free(DEVICE* device)
{ {
WIN32ERROR error;
PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device;
if (MessageQueue_PostQuit(parallel->queue, 0)) if (MessageQueue_PostQuit(parallel->queue, 0) && (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(parallel->thread, INFINITE); {
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(parallel->thread); CloseHandle(parallel->thread);
Stream_Free(parallel->device.data, TRUE); Stream_Free(parallel->device.data, TRUE);
MessageQueue_Free(parallel->queue); MessageQueue_Free(parallel->queue);
free(parallel); free(parallel);
return CHANNEL_RC_OK;
} }
#ifdef STATIC_CHANNELS #ifdef STATIC_CHANNELS

View File

@ -204,6 +204,12 @@ static void* printer_thread_func(void* arg)
while (1) while (1)
{ {
DWORD rc = WaitForMultipleObjects(2, obj, FALSE, INFINITE); DWORD rc = WaitForMultipleObjects(2, obj, FALSE, INFINITE);
if (rc == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
if (rc == WAIT_OBJECT_0 + 1) if (rc == WAIT_OBJECT_0 + 1)
break; break;
@ -245,13 +251,19 @@ static WIN32ERROR printer_irp_request(DEVICE* device, IRP* irp)
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
static void printer_free(DEVICE* device) static WIN32ERROR printer_free(DEVICE* device)
{ {
IRP* irp; IRP* irp;
PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device; PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device;
WIN32ERROR error;
SetEvent(printer_dev->stopEvent); SetEvent(printer_dev->stopEvent);
WaitForSingleObject(printer_dev->thread, INFINITE); if (WaitForSingleObject(printer_dev->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
while ((irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL) while ((irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL)
irp->Discard(irp); irp->Discard(irp);
@ -268,6 +280,7 @@ static void printer_free(DEVICE* device)
free(printer_dev->device.name); free(printer_dev->device.name);
free(printer_dev); free(printer_dev);
return CHANNEL_RC_OK;
} }
WIN32ERROR printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer) WIN32ERROR printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer)

View File

@ -596,11 +596,15 @@ static WIN32ERROR rail_virtual_channel_event_connected(railPlugin* rail, LPVOID
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
static void rail_virtual_channel_event_disconnected(railPlugin* rail) static WIN32ERROR rail_virtual_channel_event_disconnected(railPlugin* rail)
{ {
UINT rc; UINT rc;
if (MessageQueue_PostQuit(rail->queue, 0)) if (MessageQueue_PostQuit(rail->queue, 0) && (WaitForSingleObject(rail->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(rail->thread, INFINITE); {
rc = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc);
return rc;
}
MessageQueue_Free(rail->queue); MessageQueue_Free(rail->queue);
CloseHandle(rail->thread); CloseHandle(rail->thread);
@ -613,6 +617,7 @@ static void rail_virtual_channel_event_disconnected(railPlugin* rail)
{ {
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]", WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
WTSErrorToString(rc), rc); WTSErrorToString(rc), rc);
return rc;
} }
if (rail->data_in) if (rail->data_in)
@ -622,6 +627,7 @@ static void rail_virtual_channel_event_disconnected(railPlugin* rail)
} }
rail_remove_open_handle_data(rail->OpenHandle); rail_remove_open_handle_data(rail->OpenHandle);
return CHANNEL_RC_OK;
} }
static void rail_virtual_channel_event_terminated(railPlugin* rail) static void rail_virtual_channel_event_terminated(railPlugin* rail)
@ -647,14 +653,12 @@ static VOID VCAPITYPE rail_virtual_channel_init_event(LPVOID pInitHandle, UINT e
{ {
case CHANNEL_EVENT_CONNECTED: case CHANNEL_EVENT_CONNECTED:
if ((error = rail_virtual_channel_event_connected(rail, pData, dataLength))) if ((error = rail_virtual_channel_event_connected(rail, pData, dataLength)))
{
WLog_ERR(TAG, "rail_virtual_channel_event_connected failed with error %lu!", error); WLog_ERR(TAG, "rail_virtual_channel_event_connected failed with error %lu!", error);
return;
}
break; break;
case CHANNEL_EVENT_DISCONNECTED: case CHANNEL_EVENT_DISCONNECTED:
rail_virtual_channel_event_disconnected(rail); if ((error = rail_virtual_channel_event_disconnected(rail)))
WLog_ERR(TAG, "rail_virtual_channel_event_disconnected failed with error %lu!", error);
break; break;
case CHANNEL_EVENT_TERMINATED: case CHANNEL_EVENT_TERMINATED:

View File

@ -213,14 +213,17 @@ WIN32ERROR rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec)
Stream_Write_UINT16(s, exec->arguments.length); /* argumentsLength (2 bytes) */ Stream_Write_UINT16(s, exec->arguments.length); /* argumentsLength (2 bytes) */
if ((error = rail_write_unicode_string_value(s, &exec->exeOrFile))) if ((error = rail_write_unicode_string_value(s, &exec->exeOrFile)))
{ {
WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %lu", error);
return error; return error;
} }
if ((error = rail_write_unicode_string_value(s, &exec->workingDir))) if ((error = rail_write_unicode_string_value(s, &exec->workingDir)))
{ {
WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %lu", error);
return error; return error;
} }
if ((error = rail_write_unicode_string_value(s, &exec->arguments))) if ((error = rail_write_unicode_string_value(s, &exec->arguments)))
{ {
WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %lu", error);
return error; return error;
} }
return error; return error;
@ -347,7 +350,9 @@ WIN32ERROR rail_recv_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* han
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerHandshake, error, context, handshake); IFCALLRET(context->ServerHandshake, error, context, handshake);
} if (error)
WLog_ERR(TAG, "context.ServerHandshake failed with error %lu", error);
}
return error; return error;
} }
@ -366,7 +371,10 @@ WIN32ERROR rail_recv_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDE
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ClientHandshakeEx, error, context, handshakeEx); IFCALLRET(context->ClientHandshakeEx, error, context, handshakeEx);
} if (error)
WLog_ERR(TAG, "context.ClientHandshakeEx failed with error %lu", error);
}
return error; return error;
} }
@ -387,7 +395,10 @@ WIN32ERROR rail_recv_exec_result_order(railPlugin* rail, RAIL_EXEC_RESULT_ORDER*
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerExecuteResult, error, context, execResult); IFCALLRET(context->ServerExecuteResult, error, context, execResult);
} if (error)
WLog_ERR(TAG, "context.ServerExecuteResult failed with error %lu", error);
}
return error; return error;
} }
@ -406,7 +417,9 @@ WIN32ERROR rail_recv_server_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerSystemParam, error, context, sysparam); IFCALLRET(context->ServerSystemParam, error, context, sysparam);
} if (error)
WLog_ERR(TAG, "context.ServerSystemParam failed with error %lu", error);
}
return error; return error;
} }
@ -425,7 +438,9 @@ WIN32ERROR rail_recv_server_minmaxinfo_order(railPlugin* rail, RAIL_MINMAXINFO_O
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerMinMaxInfo, error, context, minMaxInfo); IFCALLRET(context->ServerMinMaxInfo, error, context, minMaxInfo);
} if (error)
WLog_ERR(TAG, "context.ServerMinMaxInfo failed with error %lu", error);
}
return error; return error;
} }
@ -444,7 +459,9 @@ WIN32ERROR rail_recv_server_localmovesize_order(railPlugin* rail, RAIL_LOCALMOVE
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerLocalMoveSize, error, context, localMoveSize); IFCALLRET(context->ServerLocalMoveSize, error, context, localMoveSize);
} if (error)
WLog_ERR(TAG, "context.ServerLocalMoveSize failed with error %lu", error);
}
return error; return error;
} }
@ -463,7 +480,9 @@ WIN32ERROR rail_recv_server_get_appid_resp_order(railPlugin* rail, RAIL_GET_APPI
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerGetAppIdResponse, error, context, getAppIdResp); IFCALLRET(context->ServerGetAppIdResponse, error, context, getAppIdResp);
} if (error)
WLog_ERR(TAG, "context.ServerGetAppIdResponse failed with error %lu", error);
}
return error; return error;
} }
@ -482,7 +501,9 @@ WIN32ERROR rail_recv_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORDE
if (context->custom) if (context->custom)
{ {
IFCALLRET(context->ServerLanguageBarInfo, error, context, langBarInfo); IFCALLRET(context->ServerLanguageBarInfo, error, context, langBarInfo);
} if (error)
WLog_ERR(TAG, "context.ServerLanguageBarInfo failed with error %lu", error);
}
return error; return error;
} }

View File

@ -101,7 +101,7 @@ static WIN32ERROR devman_register_device(DEVMAN* devman, DEVICE* device)
WLog_INFO(TAG, "ListDictionary_Add failed!"); WLog_INFO(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id) DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id)

View File

@ -488,14 +488,15 @@ static void* drive_hotplug_thread_func(void* arg)
struct timeval tv; struct timeval tv;
int rv; int rv;
WIN32ERROR error; WIN32ERROR error;
DWORD status;
rdpdr = (rdpdrPlugin*) arg; rdpdr = (rdpdrPlugin*) arg;
if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
{ {
WLog_ERR(TAG, "CreateEvent failed!"); WLog_ERR(TAG, "CreateEvent failed!");
ExitThread(ERROR_INTERNAL_ERROR); error = ERROR_INTERNAL_ERROR;
return NULL; goto out;
} }
mfd = open("/proc/mounts", O_RDONLY, 0); mfd = open("/proc/mounts", O_RDONLY, 0);
@ -503,8 +504,8 @@ static void* drive_hotplug_thread_func(void* arg)
if (mfd < 0) if (mfd < 0)
{ {
WLog_ERR(TAG, "ERROR: Unable to open /proc/mounts."); WLog_ERR(TAG, "ERROR: Unable to open /proc/mounts.");
ExitThread(ERROR_INTERNAL_ERROR); error = ERROR_INTERNAL_ERROR;
return NULL; goto out;
} }
FD_ZERO(&rfds); FD_ZERO(&rfds);
@ -515,13 +516,19 @@ static void* drive_hotplug_thread_func(void* arg)
if ((error = handle_hotplug(rdpdr))) if ((error = handle_hotplug(rdpdr)))
{ {
WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error); WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error);
ExitThread((DWORD)error); goto out;
return NULL;
} }
while ((rv = select(mfd+1, NULL, NULL, &rfds, &tv)) >= 0) while ((rv = select(mfd+1, NULL, NULL, &rfds, &tv)) >= 0)
{ {
if (WaitForSingleObject(rdpdr->stopEvent, 0) == WAIT_OBJECT_0) status = WaitForSingleObject(rdpdr->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_OBJECT_0)
break; break;
if (FD_ISSET(mfd, &rfds)) if (FD_ISSET(mfd, &rfds))
@ -530,8 +537,7 @@ static void* drive_hotplug_thread_func(void* arg)
if ((error = handle_hotplug(rdpdr))) if ((error = handle_hotplug(rdpdr)))
{ {
WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error); WLog_ERR(TAG, "handle_hotplug failed with error %lu!", error);
ExitThread((DWORD)error); goto out;
return NULL;
} }
} }
@ -541,20 +547,31 @@ static void* drive_hotplug_thread_func(void* arg)
tv.tv_usec = 0; tv.tv_usec = 0;
} }
ExitThread(CHANNEL_RC_OK); out:
return NULL; if (error && rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error, "drive_hotplug_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
} }
static void drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr) static WIN32ERROR drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
{ {
WIN32ERROR error;
if (rdpdr->hotplugThread) if (rdpdr->hotplugThread)
{ {
if (rdpdr->stopEvent) if (rdpdr->stopEvent)
SetEvent(rdpdr->stopEvent); SetEvent(rdpdr->stopEvent);
WaitForSingleObject(rdpdr->hotplugThread, INFINITE); if (WaitForSingleObject(rdpdr->hotplugThread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
rdpdr->hotplugThread = NULL; rdpdr->hotplugThread = NULL;
} }
return CHANNEL_RC_OK;
} }
#endif #endif
@ -793,7 +810,10 @@ static WIN32ERROR rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s)
IFCALLRET(irp->device->IRPRequest, error, irp->device, irp); IFCALLRET(irp->device->IRPRequest, error, irp->device, irp);
return error; if (error)
WLog_ERR(TAG, "device->IRPRequest failed with error %lu", error);
return error;
} }
static WIN32ERROR rdpdr_process_init(rdpdrPlugin* rdpdr) static WIN32ERROR rdpdr_process_init(rdpdrPlugin* rdpdr)
@ -934,7 +954,7 @@ static WIN32ERROR rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s)
} }
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
@ -961,7 +981,7 @@ WIN32ERROR rdpdr_add_init_handle_data(void* pInitHandle, void* pUserData)
WLog_ERR(TAG, "ListDictionary_Add failed!"); WLog_ERR(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* rdpdr_get_init_handle_data(void* pInitHandle) void* rdpdr_get_init_handle_data(void* pInitHandle)
@ -1001,7 +1021,7 @@ WIN32ERROR rdpdr_add_open_handle_data(DWORD openHandle, void* pUserData)
WLog_ERR(TAG, "ListDictionary_Add failed!"); WLog_ERR(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
} }
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
void* rdpdr_get_open_handle_data(DWORD openHandle) void* rdpdr_get_open_handle_data(DWORD openHandle)
@ -1061,7 +1081,7 @@ static WIN32ERROR rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr,
* ignored in client-to-server data." Thus it would be best practice to cease data * ignored in client-to-server data." Thus it would be best practice to cease data
* transmission. However, simply returning here avoids a crash. * transmission. However, simply returning here avoids a crash.
*/ */
return ERROR_SUCCESS; return CHANNEL_RC_OK;
} }
if (dataFlags & CHANNEL_FLAG_FIRST) if (dataFlags & CHANNEL_FLAG_FIRST)
@ -1193,19 +1213,19 @@ static WIN32ERROR rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr, LPVO
status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle, status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle,
&rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event); &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event);
if ((error = rdpdr_add_open_handle_data(rdpdr->OpenHandle, rdpdr))) if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WTSErrorToString(status), status);
return status;
}
if ((error = rdpdr_add_open_handle_data(rdpdr->OpenHandle, rdpdr)))
{ {
WLog_ERR(TAG, "rdpdr_add_open_handle_data failed with error %lu!", error); WLog_ERR(TAG, "rdpdr_add_open_handle_data failed with error %lu!", error);
return error; return error;
} }
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WTSErrorToString(status), status);
return status;
}
rdpdr->queue = MessageQueue_New(NULL); rdpdr->queue = MessageQueue_New(NULL);
if (!rdpdr->queue) if (!rdpdr->queue)
{ {
@ -1226,8 +1246,12 @@ static WIN32ERROR rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr)
{ {
WIN32ERROR error; WIN32ERROR error;
if (MessageQueue_PostQuit(rdpdr->queue, 0)) if (MessageQueue_PostQuit(rdpdr->queue, 0) && (WaitForSingleObject(rdpdr->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(rdpdr->thread, INFINITE); {
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
MessageQueue_Free(rdpdr->queue); MessageQueue_Free(rdpdr->queue);
CloseHandle(rdpdr->thread); CloseHandle(rdpdr->thread);
@ -1235,7 +1259,11 @@ static WIN32ERROR rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr)
rdpdr->queue = NULL; rdpdr->queue = NULL;
rdpdr->thread = NULL; rdpdr->thread = NULL;
drive_hotplug_thread_terminate(rdpdr); if ((error = drive_hotplug_thread_terminate(rdpdr)))
{
WLog_ERR(TAG, "drive_hotplug_thread_terminate failed with error %lu!", error);
return error;
}
error = rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle); error = rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle);
if (CHANNEL_RC_OK != error) if (CHANNEL_RC_OK != error)

View File

@ -95,7 +95,7 @@ static WIN32ERROR rdpdr_server_send_announce_request(RdpdrServerContext* context
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return status ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
} }
static WIN32ERROR rdpdr_server_receive_announce_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header) static WIN32ERROR rdpdr_server_receive_announce_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
@ -470,7 +470,7 @@ static WIN32ERROR rdpdr_server_send_core_capability_request(RdpdrServerContext*
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return status ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
} }
static WIN32ERROR rdpdr_server_receive_core_capability_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header) static WIN32ERROR rdpdr_server_receive_core_capability_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
@ -581,7 +581,7 @@ static WIN32ERROR rdpdr_server_send_client_id_confirm(RdpdrServerContext* contex
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return status ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
} }
static WIN32ERROR rdpdr_server_receive_device_list_announce_request(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header) static WIN32ERROR rdpdr_server_receive_device_list_announce_request(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
@ -805,7 +805,7 @@ static WIN32ERROR rdpdr_server_send_user_logged_on(RdpdrServerContext* context)
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return status ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
} }
static WIN32ERROR rdpdr_server_receive_pdu(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header) static WIN32ERROR rdpdr_server_receive_pdu(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
@ -973,7 +973,24 @@ static void* rdpdr_server_thread(void* arg)
BytesReturned = 0; BytesReturned = 0;
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
goto out_stream;
}
status = WaitForSingleObject(context->priv->StopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out_stream;
}
if (status == WAIT_OBJECT_0)
break; break;
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
@ -1041,10 +1058,16 @@ static WIN32ERROR rdpdr_server_start(RdpdrServerContext* context)
static WIN32ERROR rdpdr_server_stop(RdpdrServerContext* context) static WIN32ERROR rdpdr_server_stop(RdpdrServerContext* context)
{ {
WIN32ERROR error;
if (context->priv->StopEvent) if (context->priv->StopEvent)
{ {
SetEvent(context->priv->StopEvent); SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE); if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(context->priv->Thread); CloseHandle(context->priv->Thread);
context->priv->Thread = NULL; context->priv->Thread = NULL;
CloseHandle(context->priv->StopEvent); CloseHandle(context->priv->StopEvent);

View File

@ -182,6 +182,14 @@ static void* rdpei_schedule_thread(void* arg)
while (1) while (1)
{ {
status = WaitForMultipleObjects(2, hdl, FALSE, 20); status = WaitForMultipleObjects(2, hdl, FALSE, 20);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0 + 1) if (status == WAIT_OBJECT_0 + 1)
break; break;
@ -607,6 +615,7 @@ error_out:
static WIN32ERROR rdpei_plugin_terminated(IWTSPlugin* pPlugin) static WIN32ERROR rdpei_plugin_terminated(IWTSPlugin* pPlugin)
{ {
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin;
WIN32ERROR error;
if (!pPlugin) if (!pPlugin)
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
@ -614,7 +623,12 @@ static WIN32ERROR rdpei_plugin_terminated(IWTSPlugin* pPlugin)
SetEvent(rdpei->stopEvent); SetEvent(rdpei->stopEvent);
EnterCriticalSection(&rdpei->lock); EnterCriticalSection(&rdpei->lock);
WaitForSingleObject(rdpei->thread, INFINITE); if (WaitForSingleObject(rdpei->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(rdpei->stopEvent); CloseHandle(rdpei->stopEvent);
CloseHandle(rdpei->event); CloseHandle(rdpei->event);

View File

@ -293,8 +293,11 @@ int android_AudioOut(OPENSL_STREAM *p, const short *buffer,int size)
assert(size > 0); assert(size > 0);
/* Assure, that the queue is not full. */ /* Assure, that the queue is not full. */
if (p->queuesize <= Queue_Count(p->queue)) if (p->queuesize <= Queue_Count(p->queue) && WaitForSingleObject(p->queue->event, INFINITE) == WAIT_FAILED)
WaitForSingleObject(p->queue->event, INFINITE); {
DEBUG_SND("WaitForSingleObject failed!");
return -1;
}
void *data = calloc(size, sizeof(short)); void *data = calloc(size, sizeof(short));
if (!data) if (!data)

View File

@ -104,13 +104,46 @@ static void* rdpsnd_schedule_thread(void* arg)
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg; rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg;
HANDLE events[2]; HANDLE events[2];
WIN32ERROR error = CHANNEL_RC_OK; WIN32ERROR error = CHANNEL_RC_OK;
DWORD status;
events[0] = MessageQueue_Event(rdpsnd->MsgPipe->Out); events[0] = MessageQueue_Event(rdpsnd->MsgPipe->Out);
events[1] = rdpsnd->stopEvent; events[1] = rdpsnd->stopEvent;
while (WaitForMultipleObjects(2, events, FALSE, INFINITE) == WAIT_OBJECT_0) while (1)
{ {
if (!MessageQueue_Peek(rdpsnd->MsgPipe->Out, &message, TRUE)) status = WaitForMultipleObjects(2, events, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
status = WaitForSingleObject(rdpsnd->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
break;
status = WaitForSingleObject(events[0], 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (!MessageQueue_Peek(rdpsnd->MsgPipe->Out, &message, TRUE))
{ {
WLog_ERR(TAG, "MessageQueue_Peek failed!"); WLog_ERR(TAG, "MessageQueue_Peek failed!");
error = ERROR_INTERNAL_ERROR; error = ERROR_INTERNAL_ERROR;
@ -964,7 +997,11 @@ static void rdpsnd_process_disconnect(rdpsndPlugin* rdpsnd)
if (rdpsnd->ScheduleThread) if (rdpsnd->ScheduleThread)
{ {
SetEvent(rdpsnd->stopEvent); SetEvent(rdpsnd->stopEvent);
WaitForSingleObject(rdpsnd->ScheduleThread, INFINITE); if (WaitForSingleObject(rdpsnd->ScheduleThread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
return;
}
CloseHandle(rdpsnd->ScheduleThread); CloseHandle(rdpsnd->ScheduleThread);
CloseHandle(rdpsnd->stopEvent); CloseHandle(rdpsnd->stopEvent);
} }
@ -1247,7 +1284,12 @@ static WIN32ERROR rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd
WIN32ERROR error; WIN32ERROR error;
MessagePipe_PostQuit(rdpsnd->MsgPipe, 0); MessagePipe_PostQuit(rdpsnd->MsgPipe, 0);
WaitForSingleObject(rdpsnd->thread, INFINITE); if (WaitForSingleObject(rdpsnd->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(rdpsnd->thread); CloseHandle(rdpsnd->thread);
rdpsnd->thread = NULL; rdpsnd->thread = NULL;

View File

@ -239,7 +239,24 @@ static void* rdpsnd_server_thread(void* arg)
{ {
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
status = WaitForSingleObject(context->priv->StopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
break; break;
if ((error = rdpsnd_server_handle_messages(context))) if ((error = rdpsnd_server_handle_messages(context)))
@ -598,13 +615,19 @@ out_close:
static WIN32ERROR rdpsnd_server_stop(RdpsndServerContext* context) static WIN32ERROR rdpsnd_server_stop(RdpsndServerContext* context)
{ {
WIN32ERROR error = CHANNEL_RC_OK;
if (context->priv->ownThread) if (context->priv->ownThread)
{ {
if (context->priv->StopEvent) if (context->priv->StopEvent)
{ {
SetEvent(context->priv->StopEvent); SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE); if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(context->priv->Thread); CloseHandle(context->priv->Thread);
CloseHandle(context->priv->StopEvent); CloseHandle(context->priv->StopEvent);
} }
@ -613,7 +636,7 @@ static WIN32ERROR rdpsnd_server_stop(RdpsndServerContext* context)
if (context->priv->rdpsnd_pdu) if (context->priv->rdpsnd_pdu)
Stream_Free(context->priv->rdpsnd_pdu, TRUE); Stream_Free(context->priv->rdpsnd_pdu, TRUE);
return CHANNEL_RC_OK; return error;
} }
RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm) RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm)

View File

@ -919,8 +919,12 @@ static WIN32ERROR remdesk_virtual_channel_event_disconnected(remdeskPlugin* remd
{ {
UINT rc; UINT rc;
if (MessageQueue_PostQuit(remdesk->queue, 0)) if (MessageQueue_PostQuit(remdesk->queue, 0) && (WaitForSingleObject(remdesk->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(remdesk->thread, INFINITE); {
rc = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc);
return rc;
}
MessageQueue_Free(remdesk->queue); MessageQueue_Free(remdesk->queue);
CloseHandle(remdesk->thread); CloseHandle(remdesk->thread);

View File

@ -575,7 +575,24 @@ static void* remdesk_server_thread(void* arg)
{ {
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
break;
}
status = WaitForSingleObject(context->priv->StopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
break;
}
if (status == WAIT_OBJECT_0)
{ {
break; break;
} }
@ -654,9 +671,16 @@ static WIN32ERROR remdesk_server_start(RemdeskServerContext* context)
static WIN32ERROR remdesk_server_stop(RemdeskServerContext* context) static WIN32ERROR remdesk_server_stop(RemdeskServerContext* context)
{ {
WIN32ERROR error;
SetEvent(context->priv->StopEvent); SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE); if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(context->priv->Thread); CloseHandle(context->priv->Thread);
return CHANNEL_RC_OK; return CHANNEL_RC_OK;

View File

@ -524,6 +524,7 @@ static void create_irp_thread(SERIAL_DEVICE *serial, IRP *irp)
/* FIXME: not quite sure a zero timeout is a good thing to check whether a thread is stil alived or not */ /* FIXME: not quite sure a zero timeout is a good thing to check whether a thread is stil alived or not */
waitResult = WaitForSingleObject(irpThread, 0); waitResult = WaitForSingleObject(irpThread, 0);
if (waitResult == WAIT_OBJECT_0) if (waitResult == WAIT_OBJECT_0)
{ {
/* terminating thread */ /* terminating thread */
@ -673,7 +674,11 @@ static void terminate_pending_irp_threads(SERIAL_DEVICE *serial)
TerminateThread(irpThread, 0); TerminateThread(irpThread, 0);
WaitForSingleObject(irpThread, INFINITE); if (WaitForSingleObject(irpThread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG,"WaitForSingleObject failed!");
continue;
}
CloseHandle(irpThread); CloseHandle(irpThread);
@ -750,14 +755,20 @@ static WIN32ERROR serial_irp_request(DEVICE* device, IRP* irp)
} }
static void serial_free(DEVICE* device) static WIN32ERROR serial_free(DEVICE* device)
{ {
WIN32ERROR error;
SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device; SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device;
WLog_Print(serial->log, WLOG_DEBUG, "freeing"); WLog_Print(serial->log, WLOG_DEBUG, "freeing");
MessageQueue_PostQuit(serial->MainIrpQueue, 0); MessageQueue_PostQuit(serial->MainIrpQueue, 0);
WaitForSingleObject(serial->MainThread, INFINITE); if (WaitForSingleObject(serial->MainThread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
CloseHandle(serial->MainThread); CloseHandle(serial->MainThread);
if (serial->hComm) if (serial->hComm)
@ -770,6 +781,7 @@ static void serial_free(DEVICE* device)
DeleteCriticalSection(&serial->TerminatingIrpThreadsLock); DeleteCriticalSection(&serial->TerminatingIrpThreadsLock);
free(serial); free(serial);
return CHANNEL_RC_OK;
} }
#endif /* __linux__ */ #endif /* __linux__ */

View File

@ -37,6 +37,7 @@ void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
{ {
DWORD nCount; DWORD nCount;
LONG status; LONG status;
DWORD waitStatus;
HANDLE hEvents[2]; HANDLE hEvents[2];
wMessage message; wMessage message;
SMARTCARD_DEVICE* smartcard; SMARTCARD_DEVICE* smartcard;
@ -50,9 +51,25 @@ void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
while (1) while (1)
{ {
status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE); waitStatus = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
if (WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0) == WAIT_OBJECT_0) if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
waitStatus = WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0);
if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (waitStatus == WAIT_OBJECT_0)
{ {
if (!MessageQueue_Peek(pContext->IrpQueue, &message, TRUE)) if (!MessageQueue_Peek(pContext->IrpQueue, &message, TRUE))
{ {
@ -151,14 +168,19 @@ void smartcard_context_free(SMARTCARD_CONTEXT* pContext)
free(pContext); free(pContext);
} }
static void smartcard_free(DEVICE* device) static WIN32ERROR smartcard_free(DEVICE* device)
{ {
WIN32ERROR error;
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
if (smartcard->IrpQueue) if (smartcard->IrpQueue)
{ {
if (MessageQueue_PostQuit(smartcard->IrpQueue, 0)) if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED))
WaitForSingleObject(smartcard->thread, INFINITE); {
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
MessageQueue_Free(smartcard->IrpQueue); MessageQueue_Free(smartcard->IrpQueue);
smartcard->IrpQueue = NULL; smartcard->IrpQueue = NULL;
@ -184,6 +206,8 @@ static void smartcard_free(DEVICE* device)
} }
free(device); free(device);
return CHANNEL_RC_OK;
} }
/** /**
@ -455,7 +479,23 @@ static void* smartcard_thread_func(void* arg)
{ {
status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE); status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
if (WaitForSingleObject(MessageQueue_Event(smartcard->IrpQueue), 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
status = WaitForSingleObject(MessageQueue_Event(smartcard->IrpQueue), 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
{ {
if (!MessageQueue_Peek(smartcard->IrpQueue, &message, TRUE)) if (!MessageQueue_Peek(smartcard->IrpQueue, &message, TRUE))
{ {
@ -467,15 +507,35 @@ static void* smartcard_thread_func(void* arg)
if (message.id == WMQ_QUIT) if (message.id == WMQ_QUIT)
{ {
while (WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0) == WAIT_OBJECT_0) while (1)
{ {
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue); status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_TIMEOUT)
break;
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
if (irp) if (irp)
{ {
if (irp->thread) if (irp->thread)
{ {
WaitForSingleObject(irp->thread, INFINITE); status = WaitForSingleObject(irp->thread, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
CloseHandle(irp->thread); CloseHandle(irp->thread);
irp->thread = NULL; irp->thread = NULL;
} }
@ -503,15 +563,33 @@ static void* smartcard_thread_func(void* arg)
} }
} }
if (WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0) == WAIT_OBJECT_0) status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
{
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue); if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
{
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
if (irp) if (irp)
{ {
if (irp->thread) if (irp->thread)
{ {
WaitForSingleObject(irp->thread, INFINITE); status = WaitForSingleObject(irp->thread, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
CloseHandle(irp->thread); CloseHandle(irp->thread);
irp->thread = NULL; irp->thread = NULL;
} }

View File

@ -492,6 +492,7 @@ WIN32ERROR tsmf_ifman_on_sample(TSMF_IFMAN* ifman)
UINT64 ThrottleDuration; UINT64 ThrottleDuration;
UINT32 SampleExtensions; UINT32 SampleExtensions;
UINT32 cbData; UINT32 cbData;
WIN32ERROR error;
if (Stream_GetRemainingLength(ifman->input) < 60) if (Stream_GetRemainingLength(ifman->input) < 60)
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
@ -537,7 +538,11 @@ WIN32ERROR tsmf_ifman_on_sample(TSMF_IFMAN* ifman)
return ERROR_OUTOFMEMORY; return ERROR_OUTOFMEMORY;
} }
tsmf_presentation_sync(presentation); if ((error = tsmf_presentation_sync(presentation)))
{
WLog_ERR(TAG, "tsmf_presentation_sync failed with error %lu", error);
return error;
}
ifman->output_pending = TRUE; ifman->output_pending = TRUE;
return CHANNEL_RC_OK; return CHANNEL_RC_OK;

View File

@ -610,6 +610,13 @@ static void* tsmf_stream_ack_func(void *arg)
{ {
DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, INFINITE); DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, INFINITE);
if (ev == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
if (ev == WAIT_OBJECT_0) if (ev == WAIT_OBJECT_0)
break; break;
@ -643,6 +650,7 @@ static void* tsmf_stream_playback_func(void *arg)
TSMF_STREAM* stream = (TSMF_STREAM *) arg; TSMF_STREAM* stream = (TSMF_STREAM *) arg;
TSMF_PRESENTATION* presentation = stream->presentation; TSMF_PRESENTATION* presentation = stream->presentation;
WIN32ERROR error = CHANNEL_RC_OK; WIN32ERROR error = CHANNEL_RC_OK;
DWORD status;
DEBUG_TSMF("in %d", stream->stream_id); DEBUG_TSMF("in %d", stream->stream_id);
@ -668,9 +676,30 @@ static void* tsmf_stream_playback_func(void *arg)
hdl[0] = stream->stopEvent; hdl[0] = stream->stopEvent;
hdl[1] = Queue_Event(stream->sample_list); hdl[1] = Queue_Event(stream->sample_list);
while (!(WaitForMultipleObjects(2, hdl, FALSE, INFINITE) == WAIT_OBJECT_0)) while (1)
{ {
sample = tsmf_stream_pop_sample(stream, 0); status = WaitForMultipleObjects(2, hdl, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
status = WaitForSingleObject(stream->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
break;
sample = tsmf_stream_pop_sample(stream, 0);
if (sample && !tsmf_sample_playback(sample)) if (sample && !tsmf_sample_playback(sample))
{ {
@ -825,10 +854,11 @@ BOOL tsmf_presentation_start(TSMF_PRESENTATION* presentation)
return ret; return ret;
} }
void tsmf_presentation_sync(TSMF_PRESENTATION* presentation) WIN32ERROR tsmf_presentation_sync(TSMF_PRESENTATION* presentation)
{ {
UINT32 index; UINT32 index;
UINT32 count; UINT32 count;
WIN32ERROR error;
ArrayList_Lock(presentation->stream_list); ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list); count = ArrayList_Count(presentation->stream_list);
@ -836,10 +866,16 @@ void tsmf_presentation_sync(TSMF_PRESENTATION* presentation)
for (index = 0; index < count; index++) for (index = 0; index < count; index++)
{ {
TSMF_STREAM* stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index); TSMF_STREAM* stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
WaitForSingleObject(stream->ready, 500); if (WaitForSingleObject(stream->ready, 500) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return error;
}
} }
ArrayList_Unlock(presentation->stream_list); ArrayList_Unlock(presentation->stream_list);
return CHANNEL_RC_OK;
} }
BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation) BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation)
@ -1041,10 +1077,12 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id,
error_add: error_add:
SetEvent(stream->stopEvent); SetEvent(stream->stopEvent);
WaitForSingleObject(stream->ack_thread, INFINITE); if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED)
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
error_ack_thread: error_ack_thread:
SetEvent(stream->stopEvent); SetEvent(stream->stopEvent);
WaitForSingleObject(stream->play_thread, INFINITE); if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED)
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
error_play_thread: error_play_thread:
Queue_Free(stream->sample_ack_list); Queue_Free(stream->sample_ack_list);
error_sample_ack_list: error_sample_ack_list:
@ -1160,14 +1198,23 @@ void _tsmf_stream_free(TSMF_STREAM* stream)
if (stream->play_thread) if (stream->play_thread)
{ {
WaitForSingleObject(stream->play_thread, INFINITE); if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
return;
}
CloseHandle(stream->play_thread); CloseHandle(stream->play_thread);
stream->play_thread = NULL; stream->play_thread = NULL;
} }
if (stream->ack_thread) if (stream->ack_thread)
{ {
WaitForSingleObject(stream->ack_thread, INFINITE); if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
return;
}
CloseHandle(stream->ack_thread); CloseHandle(stream->ack_thread);
stream->ack_thread = NULL; stream->ack_thread = NULL;
} }

View File

@ -40,7 +40,7 @@ TSMF_PRESENTATION *tsmf_presentation_new(const BYTE *guid, IWTSVirtualChannelCal
TSMF_PRESENTATION *tsmf_presentation_find_by_id(const BYTE *guid); TSMF_PRESENTATION *tsmf_presentation_find_by_id(const BYTE *guid);
BOOL tsmf_presentation_start(TSMF_PRESENTATION *presentation); BOOL tsmf_presentation_start(TSMF_PRESENTATION *presentation);
BOOL tsmf_presentation_stop(TSMF_PRESENTATION *presentation); BOOL tsmf_presentation_stop(TSMF_PRESENTATION *presentation);
void tsmf_presentation_sync(TSMF_PRESENTATION *presentation); WIN32ERROR tsmf_presentation_sync(TSMF_PRESENTATION *presentation);
BOOL tsmf_presentation_paused(TSMF_PRESENTATION *presentation); BOOL tsmf_presentation_paused(TSMF_PRESENTATION *presentation);
BOOL tsmf_presentation_restarted(TSMF_PRESENTATION *presentation); BOOL tsmf_presentation_restarted(TSMF_PRESENTATION *presentation);
BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION *presentation, UINT32 newVolume, UINT32 muted); BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION *presentation, UINT32 newVolume, UINT32 muted);

View File

@ -513,6 +513,8 @@ static void *urbdrc_search_usb_device(void *arg) {
int busnum, devnum; int busnum, devnum;
int action, success, error, found, on_close; int action, success, error, found, on_close;
struct sockaddr_un sun; struct sockaddr_un sun;
DWORD status;
UINT32 error;
WLog_DBG(TAG, "urbdrc_search_usb_device - devd: start"); WLog_DBG(TAG, "urbdrc_search_usb_device - devd: start");
@ -540,6 +542,19 @@ static void *urbdrc_search_usb_device(void *arg) {
while (WaitForMultipleObjects(2, listobj, FALSE, INFINITE) != WAIT_OBJECT_0) while (WaitForMultipleObjects(2, listobj, FALSE, INFINITE) != WAIT_OBJECT_0)
{ {
status = WaitForMultipleObjects(2, listobj, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
return 0;
}
if (status == WAIT_OBJECT_0)
break;
WLog_DBG(TAG, "======= SEARCH ======= "); WLog_DBG(TAG, "======= SEARCH ======= ");
/* !system=USB subsystem=DEVICE type=ATTACH ugen=ugen3.3 cdev=ugen3.3 vendor=0x046d product=0x082d devclass=0xef devsubclass=0x02 sernum="6E7D726F" release=0x0011 mode=host port=4 parent=ugen3.1 */ /* !system=USB subsystem=DEVICE type=ATTACH ugen=ugen3.3 cdev=ugen3.3 vendor=0x046d product=0x082d devclass=0xef devsubclass=0x02 sernum="6E7D726F" release=0x0011 mode=host port=4 parent=ugen3.1 */
@ -735,6 +750,7 @@ static void* urbdrc_search_usb_device(void* arg)
int success = 0, error, on_close = 0, found = 0; int success = 0, error, on_close = 0, found = 0;
WLog_VRB(TAG, ""); WLog_VRB(TAG, "");
channel_mgr = urbdrc->listener_callback->channel_mgr; channel_mgr = urbdrc->listener_callback->channel_mgr;
DWORD status;
/* init usb monitor */ /* init usb monitor */
struct udev* udev; struct udev* udev;
@ -774,15 +790,41 @@ static void* urbdrc_search_usb_device(void* arg)
listobj[1] = mon_fd; listobj[1] = mon_fd;
numobj = 2; numobj = 2;
WaitForMultipleObjects(numobj, listobj, FALSE, INFINITE); status = WaitForMultipleObjects(numobj, listobj, FALSE, INFINITE);
if (WaitForSingleObject(searchman->term_event, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
goto out;
}
status = WaitForSingleObject(searchman->term_event, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_OBJECT_0)
{ {
sem_post(&searchman->sem_term); sem_post(&searchman->sem_term);
return 0; goto out;
} }
if (WaitForSingleObject(mon_fd, 0) == WAIT_OBJECT_0) status = WaitForSingleObject(mon_fd, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_OBJECT_0)
{ {
dev = udev_monitor_receive_device(mon); dev = udev_monitor_receive_device(mon);
@ -856,9 +898,25 @@ static void* urbdrc_search_usb_device(void* arg)
numobj = 1; numobj = 1;
timeout = 4000; /* milliseconds */ timeout = 4000; /* milliseconds */
WaitForMultipleObjects(numobj, listobj, FALSE, timeout); status = WaitForMultipleObjects(numobj, listobj, FALSE, timeout);
if (WaitForSingleObject(searchman->term_event, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
goto out;
}
status = WaitForSingleObject(searchman->term_event, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
goto out;
}
if (status == WAIT_OBJECT_0)
{ {
CloseHandle(mon_fd); CloseHandle(mon_fd);
sem_post(&searchman->sem_term); sem_post(&searchman->sem_term);
@ -912,9 +970,25 @@ static void* urbdrc_search_usb_device(void* arg)
numobj = 1; numobj = 1;
timeout = 3000; /* milliseconds */ timeout = 3000; /* milliseconds */
WaitForMultipleObjects(numobj, listobj, FALSE, timeout); status = WaitForMultipleObjects(numobj, listobj, FALSE, timeout);
if (WaitForSingleObject(searchman->term_event, 0) == WAIT_OBJECT_0) if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
goto out;
}
status = WaitForSingleObject(searchman->term_event, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_OBJECT_0)
{ {
CloseHandle(mon_fd); CloseHandle(mon_fd);
sem_post(&searchman->sem_term); sem_post(&searchman->sem_term);
@ -936,7 +1010,7 @@ static void* urbdrc_search_usb_device(void* arg)
} }
} }
} }
out:
CloseHandle(mon_fd); CloseHandle(mon_fd);
fail_create_monfd_event: fail_create_monfd_event:

View File

@ -319,7 +319,7 @@ typedef struct _DEVMAN DEVMAN;
typedef WIN32ERROR (*pcIRPRequest)(DEVICE* device, IRP* irp); typedef WIN32ERROR (*pcIRPRequest)(DEVICE* device, IRP* irp);
typedef WIN32ERROR (*pcInitDevice)(DEVICE* device); typedef WIN32ERROR (*pcInitDevice)(DEVICE* device);
typedef void (*pcFreeDevice)(DEVICE* device); typedef WIN32ERROR (*pcFreeDevice)(DEVICE* device);
struct _DEVICE struct _DEVICE
{ {