start working on test

This commit is contained in:
Bert Belder 2012-08-29 05:14:00 +02:00
parent 39e68401ce
commit 0d07f24236
2 changed files with 46 additions and 0 deletions

View File

@ -37,6 +37,9 @@ typedef union wpoll_data {
int fd;
uint32_t u32;
uint64_t u64;
/* Windows-specific extensions. */
SOCKET sock;
HANDLE hnd;
} wpoll_data_t;
struct wpoll_event {

View File

@ -3,8 +3,51 @@
#include <WS2tcpip.h>
#include <Windows.h>
#include <assert.h>s
#include <wpoll.h>
int main(int argc, char* argv[]) {
wpoll_t wpoll_hnd;
SOCKET sock;
WSADATA wsa_data;
int r;
u_long one = 1;
struct addrinfo hints;
struct addrinfo* addrinfo;
struct sockaddr_in addr;
struct wpoll_event event;
r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
assert(r == 0);
wpoll_hnd = wpoll_create();
assert(wpoll_hnd);
sock = socket(AF_INET, SOCK_STREAM, 0);
r = ioctlsocket(sock, FIONBIO, &one);
assert(r == 0);
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_IP;
r = getaddrinfo("www.google.com", NULL, &hints, &addrinfo);
assert(r == 0);
memset(&addr, 0, sizeof addr);
addr.sin_addr = *(IN_ADDR*) &addrinfo->ai_addr;
addr.sin_family = addrinfo->ai_family;
addr.sin_port = htons(80);
freeaddrinfo(addrinfo);
r = connect(sock, (sockaddr*) &addr, sizeof addr);\
assert(r == 0 || WSAGetLastError() == WSAEINPROGRESS);
event.events = WPOLLOUT | WPOLLERR;
event.data.sock = sock;
r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_ADD, sock, &event);
}