Lines Matching refs:overlapped
99 OVERLAPPED read_overlapped;
100 OVERLAPPED write_overlapped;
109 static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped)
112 WaitForSingleObject(overlapped->free_list_semaphore, INFINITE);
113 EnterCriticalSection(&overlapped->free_list_cs);
114 buffer = overlapped->free_list;
116 overlapped->free_list = buffer->next;
117 LeaveCriticalSection(&overlapped->free_list_cs);
122 static void put_buffer_on_free_list(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
124 EnterCriticalSection(&overlapped->free_list_cs);
125 buffer->next = overlapped->free_list;
126 overlapped->free_list = buffer;
127 LeaveCriticalSection(&overlapped->free_list_cs);
128 ReleaseSemaphore(overlapped->free_list_semaphore, 1, NULL);
131 static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block)
137 result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout);
143 EnterCriticalSection(&overlapped->output_queue_cs);
145 buffer = overlapped->output_queue_front;
146 overlapped->output_queue_front = buffer->next;
148 if(overlapped->output_queue_front == NULL) {
149 overlapped->output_queue_back = NULL;
152 LeaveCriticalSection(&overlapped->output_queue_cs);
164 static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped)
166 return get_buffer_from_output_queue(overlapped, 0);
169 static void put_buffer_on_output_queue(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
171 EnterCriticalSection(&overlapped->output_queue_cs);
173 if(overlapped->output_queue_front == NULL && overlapped->output_queue_back == NULL) {
174 overlapped->output_queue_front = overlapped->output_queue_back = buffer;
177 overlapped->output_queue_back->next = buffer;
178 overlapped->output_queue_back = buffer;
181 LeaveCriticalSection(&overlapped->output_queue_cs);
183 ReleaseSemaphore(overlapped->output_queue_semaphore, 1, NULL);
397 static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped, const HANDLE handle)
399 overlapped->handle = handle;
401 overlapped->read_event = CreateEvent(NULL, FALSE, FALSE, NULL);
402 overlapped->write_event = CreateEvent(NULL, FALSE, FALSE, NULL);
404 overlapped->read_overlapped.Offset = 0;
405 overlapped->read_overlapped.OffsetHigh = 0;
406 overlapped->read_overlapped.hEvent = overlapped->read_event;
408 overlapped->write_overlapped.Offset = 0;
409 overlapped->write_overlapped.OffsetHigh = 0;
410 overlapped->write_overlapped.hEvent = overlapped->write_event;
412 InitializeCriticalSection(&overlapped->output_queue_cs);
413 InitializeCriticalSection(&overlapped->free_list_cs);
415 overlapped->output_queue_semaphore = CreateSemaphore(
421 if(!overlapped->output_queue_semaphore) {
425 overlapped->free_list_semaphore = CreateSemaphore(
431 if(!overlapped->free_list_semaphore) {
435 overlapped->free_list = overlapped->output_queue_front = overlapped->output_queue_back = NULL;
440 tun_buffer_t* element = &overlapped->buffers[index];
441 element->next = overlapped->free_list;
442 overlapped->free_list = element;
446 overlapped->tap_semaphore = CreateSemaphore(NULL, 0, TUN_MAX_BUFFER_COUNT, NULL);
447 if(!overlapped->tap_semaphore)
451 static int tap_win32_write(tap_win32_overlapped_t *overlapped,
458 result = GetOverlappedResult( overlapped->handle, &overlapped->write_overlapped,
462 WaitForSingleObject(overlapped->write_event, INFINITE);
464 result = WriteFile(overlapped->handle, buffer, size,
465 &write_size, &overlapped->write_overlapped);
472 WaitForSingleObject(overlapped->write_event, INFINITE);
485 tap_win32_overlapped_t *overlapped = (tap_win32_overlapped_t*)param;
489 tun_buffer_t* buffer = get_buffer_from_free_list(overlapped);
493 result = ReadFile(overlapped->handle,
497 &overlapped->read_overlapped);
501 WaitForSingleObject(overlapped->read_event, INFINITE);
502 result = GetOverlappedResult( overlapped->handle, &overlapped->read_overlapped,
529 put_buffer_on_output_queue(overlapped, buffer);
530 ReleaseSemaphore(overlapped->tap_semaphore, 1, NULL);
531 buffer = get_buffer_from_free_list(overlapped);
538 static int tap_win32_read(tap_win32_overlapped_t *overlapped,
543 tun_buffer_t* buffer = get_buffer_from_output_queue_immediate(overlapped);
556 static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
560 put_buffer_on_free_list(overlapped, buffer);