Last active
January 3, 2018 11:51
-
-
Save justinjoy/408704230baab6ba002037b7f93e16e6 to your computer and use it in GitHub Desktop.
SRT epoll-like feature test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <srt.h> | |
#include <windows.h> | |
#include <tchar.h> | |
#include <strsafe.h> | |
DWORD WINAPI SrtSendEvent( LPVOID lpParam ) | |
{ | |
HANDLE handle = (HANDLE) lpParam; | |
printf ("Waiting 3 seconds before event firing.\n"); | |
Sleep (3000); | |
SetEvent (handle); | |
printf ("Set event!\n"); | |
return 0; | |
} | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
HANDLE poll_handle, thread_handle; | |
DWORD tid; | |
int poll_id = srt_epoll_create (); | |
poll_handle = CreateEvent (NULL, TRUE, FALSE, NULL); | |
srt_epoll_add_ssock (poll_id, poll_handle, &(int) { SRT_EPOLL_IN }); | |
printf ("Test poll handle %d\n", poll_handle); | |
thread_handle = CreateThread( | |
NULL, // default security attributes | |
0, // use default stack size | |
SrtSendEvent, // thread function name | |
poll_handle, // argument to thread function | |
0, // use default creation flags | |
&tid); // returns the thread identifier | |
SRTSOCKET ready[2]; | |
int result = -1; | |
if ( ( result = srt_epoll_wait( poll_id, | |
ready, &(int) { 2 }, NULL, 0, 10 * 1000, | |
&(int) { poll_handle }, &(int) { 1 }, NULL, 0 ) ) == -1 ) | |
{ | |
printf ("error\n"); | |
} | |
printf ("released poll wait (result: %d)\n", result); | |
WaitForSingleObject(thread_handle, INFINITE); | |
srt_epoll_release (poll_id); | |
CloseHandle (poll_handle); | |
CloseHandle (thread_handle); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment