test-usleep-ws.c 975 Bytes
Newer Older
1 2
#include <stdio.h>
#include <stdlib.h>
3
#include <toku_assert.h>
4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <fcntl.h>
#include <windows.h>
#include <winsock.h>

int usleep(SOCKET s, unsigned int useconds) {
    fd_set dummy;
    struct timeval tv;
    FD_ZERO(&dummy);
    FD_SET(s, &dummy);
    tv.tv_sec = useconds / 1000000;
    tv.tv_usec = useconds % 1000000;
    return select(0, 0, 0, &dummy, &tv);
}

Yoni Fogel's avatar
Yoni Fogel committed
18 19 20 21
#include <test.h>
int verbose;

int test_main(int argc, char *argv[]) {
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    int i;
    int n = 1;
    WSADATA wsadata;
    SOCKET s;

    for (i=1; i<argc; i++) {
        char *arg = argv[i];
        if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
            verbose++;
        n = atoi(arg);
    }

    WSAStartup(MAKEWORD(1, 0), &wsadata);
    s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
36
    printf("s=%"PRIu64"\n", s);
37 38 39 40 41 42 43 44 45 46

    for (i=0; i<1000; i++) {
        if (verbose) {
            printf("usleep %d\n", i); fflush(stdout);
        }
        usleep(s, n);
    }

    return 0;
}