Revision 5fafdf24 tap-win32.c

b/tap-win32.c
110 110

  
111 111
static tap_win32_overlapped_t tap_overlapped;
112 112

  
113
static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped) 
113
static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped)
114 114
{
115 115
    tun_buffer_t* buffer = NULL;
116 116
    WaitForSingleObject(overlapped->free_list_semaphore, INFINITE);
......
132 132
    ReleaseSemaphore(overlapped->free_list_semaphore, 1, NULL);
133 133
}
134 134

  
135
static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block) 
135
static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block)
136 136
{
137 137
    tun_buffer_t* buffer = NULL;
138 138
    DWORD result, timeout = block ? INFINITE : 0L;
139 139

  
140 140
    // Non-blocking call
141
    result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout); 
141
    result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout);
142 142

  
143
    switch (result) 
144
    { 
143
    switch (result)
144
    {
145 145
        // The semaphore object was signaled.
146
        case WAIT_OBJECT_0: 
146
        case WAIT_OBJECT_0:
147 147
            EnterCriticalSection(&overlapped->output_queue_cs);
148 148

  
149 149
            buffer = overlapped->output_queue_front;
......
154 154
            }
155 155

  
156 156
            LeaveCriticalSection(&overlapped->output_queue_cs);
157
            break; 
157
            break;
158 158

  
159 159
        // Semaphore was nonsignaled, so a time-out occurred.
160
        case WAIT_TIMEOUT: 
160
        case WAIT_TIMEOUT:
161 161
            // Cannot open another window.
162
            break; 
162
            break;
163 163
    }
164 164

  
165 165
    return buffer;
166 166
}
167 167

  
168
static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped) 
168
static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped)
169 169
{
170 170
    return get_buffer_from_output_queue(overlapped, 0);
171 171
}
......
332 332
            return -1;
333 333
        }
334 334

  
335
        snprintf(connection_string, 
335
        snprintf(connection_string,
336 336
             sizeof(connection_string),
337 337
             "%s\\%s\\Connection",
338 338
             NETWORK_CONNECTIONS_KEY, enum_name);
......
343 343
            0,
344 344
            KEY_READ,
345 345
            &connection_key);
346
        
346
       
347 347
        if (status == ERROR_SUCCESS) {
348 348
            len = sizeof (name_data);
349 349
            status = RegQueryValueEx(
......
416 416
    InitializeCriticalSection(&overlapped->output_queue_cs);
417 417
    InitializeCriticalSection(&overlapped->free_list_cs);
418 418

  
419
    overlapped->output_queue_semaphore = CreateSemaphore( 
419
    overlapped->output_queue_semaphore = CreateSemaphore(
420 420
        NULL,   // default security attributes
421 421
        0,   // initial count
422 422
        TUN_MAX_BUFFER_COUNT,   // maximum count
......
426 426
        fprintf(stderr, "error creating output queue semaphore!\n");
427 427
    }
428 428

  
429
    overlapped->free_list_semaphore = CreateSemaphore( 
429
    overlapped->free_list_semaphore = CreateSemaphore(
430 430
        NULL,   // default security attributes
431 431
        TUN_MAX_BUFFER_COUNT,   // initial count
432 432
        TUN_MAX_BUFFER_COUNT,   // maximum count
......
452 452
        fprintf(stderr, "error creating tap_semaphore.\n");
453 453
}
454 454

  
455
static int tap_win32_write(tap_win32_overlapped_t *overlapped, 
455
static int tap_win32_write(tap_win32_overlapped_t *overlapped,
456 456
                           const void *buffer, unsigned long size)
457 457
{
458 458
    unsigned long write_size;
......
467 467

  
468 468
    result = WriteFile(overlapped->handle, buffer, size,
469 469
                       &write_size, &overlapped->write_overlapped);
470
    
471
    if (!result) { 
470
   
471
    if (!result) {
472 472
        switch (error = GetLastError())
473
        { 
474
        case ERROR_IO_PENDING: 
473
        {
474
        case ERROR_IO_PENDING:
475 475
#ifndef TUN_ASYNCHRONOUS_WRITES
476 476
            WaitForSingleObject(overlapped->write_event, INFINITE);
477 477
#endif
478 478
            break;
479 479
        default:
480 480
            return -1;
481
        } 
481
        }
482 482
    }
483 483

  
484 484
    return 0;
......
539 539
    return 0;
540 540
}
541 541

  
542
static int tap_win32_read(tap_win32_overlapped_t *overlapped, 
542
static int tap_win32_read(tap_win32_overlapped_t *overlapped,
543 543
                          uint8_t **pbuf, int max_size)
544 544
{
545 545
    int size = 0;
......
557 557
    return size;
558 558
}
559 559

  
560
static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped, 
561
                                  char* pbuf) 
560
static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
561
                                  char* pbuf)
562 562
{
563 563
    tun_buffer_t* buffer = (tun_buffer_t*)pbuf;
564 564
    put_buffer_on_free_list(overlapped, buffer);
565 565
}
566 566

  
567
static int tap_win32_open(tap_win32_overlapped_t **phandle, 
567
static int tap_win32_open(tap_win32_overlapped_t **phandle,
568 568
                          const char *prefered_name)
569 569
{
570 570
    char device_path[256];
......
660 660
int tap_win32_init(VLANState *vlan, const char *ifname)
661 661
{
662 662
    TAPState *s;
663
    
663
   
664 664
    s = qemu_mallocz(sizeof(TAPState));
665 665
    if (!s)
666 666
        return -1;
......
670 670
    }
671 671

  
672 672
    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
673
    
673
   
674 674
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
675 675
             "tap: ifname=%s", ifname);
676 676

  

Also available in: Unified diff