mariadb/windows/tests/test-usleep-ws.c
Yoni Fogel 5f68cd8242 [t:2216] Merge/windows port of #2216
git-svn-id: file:///svn/toku/tokudb@18191 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:59:01 -04:00

46 lines
995 B
C

#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <fcntl.h>
#include <windows.h>
#include <winsock.h>
int usleep_socket(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);
}
int verbose;
int test_main(int argc, char *const argv[]) {
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);
printf("s=%"PRIu64"\n", s);
for (i=0; i<1000; i++) {
if (verbose) {
printf("usleep %d\n", i); fflush(stdout);
}
usleep_socket(s, n);
}
return 0;
}