mirror of https://github.com/getdnsapi/getdns.git
Bug fix in get_os_defaults, clean up code in winsock_event, add code to handle event handling differences in Winsock2
This commit is contained in:
parent
2d58ed465c
commit
22a8550caa
|
@ -803,10 +803,9 @@ set_os_defaults_windows(struct getdns_context *context)
|
||||||
hints.ai_addr = NULL;
|
hints.ai_addr = NULL;
|
||||||
hints.ai_next = NULL;
|
hints.ai_next = NULL;
|
||||||
|
|
||||||
//g
|
|
||||||
FIXED_INFO *info;
|
FIXED_INFO *info;
|
||||||
ULONG buflen = sizeof(*info);
|
ULONG buflen = sizeof(*info);
|
||||||
IP_ADDR_STRING *ptr;
|
IP_ADDR_STRING *ptr = 0;
|
||||||
|
|
||||||
info = (FIXED_INFO *)malloc(sizeof(FIXED_INFO));
|
info = (FIXED_INFO *)malloc(sizeof(FIXED_INFO));
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
|
@ -821,7 +820,7 @@ set_os_defaults_windows(struct getdns_context *context)
|
||||||
|
|
||||||
if (GetNetworkParams(info, &buflen) == NO_ERROR) {
|
if (GetNetworkParams(info, &buflen) == NO_ERROR) {
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
ptr = &(info->DnsServerList);
|
ptr = info->DnsServerList.Next;
|
||||||
*domain = 0;
|
*domain = 0;
|
||||||
while (ptr) {
|
while (ptr) {
|
||||||
for (size_t i = 0; i < GETDNS_UPSTREAM_TRANSPORTS; i++) {
|
for (size_t i = 0; i < GETDNS_UPSTREAM_TRANSPORTS; i++) {
|
||||||
|
@ -843,7 +842,6 @@ set_os_defaults_windows(struct getdns_context *context)
|
||||||
free(info);
|
free(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
(void)getdns_list_get_length(context->suffix, &length);
|
(void)getdns_list_get_length(context->suffix, &length);
|
||||||
if (length == 0 && *domain != 0) {
|
if (length == 0 && *domain != 0) {
|
||||||
bindata.data = (uint8_t *)domain;
|
bindata.data = (uint8_t *)domain;
|
||||||
|
@ -994,7 +992,7 @@ getdns_context_create_with_extended_memory_functions(
|
||||||
result->fchg_resolvconf = NULL;
|
result->fchg_resolvconf = NULL;
|
||||||
result->fchg_hosts = NULL;
|
result->fchg_hosts = NULL;
|
||||||
|
|
||||||
//g resolv.conf does not exist on Windows, handle differently
|
// resolv.conf does not exist on Windows, handle differently
|
||||||
#ifndef USE_WINSOCK
|
#ifndef USE_WINSOCK
|
||||||
if (set_from_os && (r = set_os_defaults(result)))
|
if (set_from_os && (r = set_os_defaults(result)))
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -2358,18 +2356,24 @@ _getdns_context_prepare_for_resolution(struct getdns_context *context,
|
||||||
/* Create client context, use TLS v1.2 only for now */
|
/* Create client context, use TLS v1.2 only for now */
|
||||||
context->tls_ctx = SSL_CTX_new(TLSv1_2_client_method());
|
context->tls_ctx = SSL_CTX_new(TLSv1_2_client_method());
|
||||||
if (context->tls_ctx == NULL)
|
if (context->tls_ctx == NULL)
|
||||||
printf("ERROR! Bad TLS context!");
|
#ifndef USE_WINSOCK
|
||||||
//g return GETDNS_RETURN_BAD_CONTEXT;
|
return GETDNS_RETURN_BAD_CONTEXT;
|
||||||
|
#else
|
||||||
|
printf("Warning! Bad TLS context, check openssl version on Windows!\n");;
|
||||||
|
#endif
|
||||||
/* Be strict and only use the cipher suites recommended in RFC7525
|
/* Be strict and only use the cipher suites recommended in RFC7525
|
||||||
Unless we later fallback to opportunistic. */
|
Unless we later fallback to opportunistic. */
|
||||||
const char* const PREFERRED_CIPHERS = "EECDH+aRSA+AESGCM:EECDH+aECDSA+AESGCM:EDH+aRSA+AESGCM";
|
const char* const PREFERRED_CIPHERS = "EECDH+aRSA+AESGCM:EECDH+aECDSA+AESGCM:EDH+aRSA+AESGCM";
|
||||||
if (!SSL_CTX_set_cipher_list(context->tls_ctx, PREFERRED_CIPHERS))
|
if (!SSL_CTX_set_cipher_list(context->tls_ctx, PREFERRED_CIPHERS)) {
|
||||||
return GETDNS_RETURN_BAD_CONTEXT;
|
return GETDNS_RETURN_BAD_CONTEXT;
|
||||||
if (!SSL_CTX_set_default_verify_paths(context->tls_ctx))
|
}
|
||||||
|
if (!SSL_CTX_set_default_verify_paths(context->tls_ctx)) {
|
||||||
return GETDNS_RETURN_BAD_CONTEXT;
|
return GETDNS_RETURN_BAD_CONTEXT;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (tls_only_is_in_transports_list(context) == 1)
|
if (tls_only_is_in_transports_list(context) == 1) {
|
||||||
return GETDNS_RETURN_BAD_CONTEXT;
|
return GETDNS_RETURN_BAD_CONTEXT;
|
||||||
|
}
|
||||||
/* A null tls_ctx will make TLS fail and fallback to the other
|
/* A null tls_ctx will make TLS fail and fallback to the other
|
||||||
transports will kick-in.*/
|
transports will kick-in.*/
|
||||||
#endif
|
#endif
|
||||||
|
|
21
src/stub.c
21
src/stub.c
|
@ -50,6 +50,7 @@
|
||||||
#define EINPROGRESS 112
|
#define EINPROGRESS 112
|
||||||
#define EWOULDBLOCK 140
|
#define EWOULDBLOCK 140
|
||||||
typedef u_short sa_family_t;
|
typedef u_short sa_family_t;
|
||||||
|
#include "util/winsock_event.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STUB_OUT_OF_OPTIONS -5 /* upstream options exceeded MAXIMUM_UPSTREAM_OPTION_SPACE */
|
#define STUB_OUT_OF_OPTIONS -5 /* upstream options exceeded MAXIMUM_UPSTREAM_OPTION_SPACE */
|
||||||
|
@ -623,7 +624,7 @@ stub_tls_timeout_cb(void *userarg)
|
||||||
/****************************/
|
/****************************/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf)
|
stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf, getdns_eventloop_event* event)
|
||||||
{
|
{
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
|
@ -640,10 +641,24 @@ stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf)
|
||||||
}
|
}
|
||||||
read = recv(fd, tcp->read_pos, tcp->to_read, 0);
|
read = recv(fd, tcp->read_pos, tcp->to_read, 0);
|
||||||
if (read == -1) {
|
if (read == -1) {
|
||||||
|
#ifdef USE_WINSOCK
|
||||||
|
printf("read (in tcp ) %s\n",
|
||||||
|
wsa_strerror(WSAGetLastError()));
|
||||||
|
if (WSAGetLastError() == WSAECONNRESET)
|
||||||
|
return STUB_TCP_AGAIN;
|
||||||
|
if (WSAGetLastError() == WSAEINPROGRESS)
|
||||||
|
return STUB_TCP_AGAIN;
|
||||||
|
if (WSAGetLastError() == WSAEWOULDBLOCK) {
|
||||||
|
winsock_tcp_wouldblock(event, EV_READ);
|
||||||
|
return STUB_TCP_AGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
return STUB_TCP_AGAIN;
|
return STUB_TCP_AGAIN;
|
||||||
else
|
else
|
||||||
return STUB_TCP_ERROR;
|
return STUB_TCP_ERROR;
|
||||||
|
#endif
|
||||||
} else if (read == 0) {
|
} else if (read == 0) {
|
||||||
/* Remote end closed the socket */
|
/* Remote end closed the socket */
|
||||||
/* TODO: Try to reconnect */
|
/* TODO: Try to reconnect */
|
||||||
|
@ -1359,7 +1374,7 @@ stub_tcp_read_cb(void *userarg)
|
||||||
int q;
|
int q;
|
||||||
|
|
||||||
switch ((q = stub_tcp_read(netreq->fd, &netreq->tcp,
|
switch ((q = stub_tcp_read(netreq->fd, &netreq->tcp,
|
||||||
&dnsreq->context->mf))) {
|
&dnsreq->context->mf, &netreq->event))) {
|
||||||
|
|
||||||
case STUB_TCP_AGAIN:
|
case STUB_TCP_AGAIN:
|
||||||
return;
|
return;
|
||||||
|
@ -1437,7 +1452,7 @@ upstream_read_cb(void *userarg)
|
||||||
&upstream->upstreams->mf);
|
&upstream->upstreams->mf);
|
||||||
else
|
else
|
||||||
q = stub_tcp_read(upstream->fd, &upstream->tcp,
|
q = stub_tcp_read(upstream->fd, &upstream->tcp,
|
||||||
&upstream->upstreams->mf);
|
&upstream->upstreams->mf, &netreq->event);
|
||||||
|
|
||||||
switch (q) {
|
switch (q) {
|
||||||
case STUB_TCP_AGAIN:
|
case STUB_TCP_AGAIN:
|
||||||
|
|
|
@ -36,10 +36,11 @@
|
||||||
* \file
|
* \file
|
||||||
* Implementation of the getdns WinSock2 API event notification handler
|
* Implementation of the getdns WinSock2 API event notification handler
|
||||||
* for the getdns Windows port.
|
* for the getdns Windows port.
|
||||||
|
* Code is originally from the Unbound source for Windows.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef USE_WINSOCK
|
#ifdef USE_WINSOCK // only included for Windows builds
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#ifdef HAVE_TIME_H
|
#ifdef HAVE_TIME_H
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -61,6 +62,7 @@ log_err(const char *format, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* wsa_strerror(DWORD err)
|
char* wsa_strerror(DWORD err)
|
||||||
{
|
{
|
||||||
static char unknown[32];
|
static char unknown[32];
|
||||||
|
@ -200,7 +202,7 @@ settime(struct _getdns_event_base* base)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNBOUND_DEBUG
|
#ifdef WINSOCK_DEBUG
|
||||||
/**
|
/**
|
||||||
* Find a fd in the list of items.
|
* Find a fd in the list of items.
|
||||||
* Note that not all items have a fd associated (those are -1).
|
* Note that not all items have a fd associated (those are -1).
|
||||||
|
@ -258,14 +260,15 @@ void *_getdns_event_init(time_t* time_secs, struct timeval* time_tv)
|
||||||
_getdns_event_base_free(base);
|
_getdns_event_base_free(base);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
base->signals = (struct _getdns_event**)calloc(MAX_SIG, sizeof(struct _getdns_event*));
|
base->signals = (struct _getdns_event**)calloc(MAX_SIG,
|
||||||
|
sizeof(struct _getdns_event*));
|
||||||
if(!base->signals) {
|
if(!base->signals) {
|
||||||
_getdns_event_base_free(base);
|
_getdns_event_base_free(base);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
base->tcp_stickies = 0;
|
base->tcp_stickies = 0;
|
||||||
base->tcp_reinvigorated = 0;
|
base->tcp_reinvigorated = 0;
|
||||||
//verbose(VERB_CLIENT, "winsock_event inited");
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +282,6 @@ const char *_getdns_event_get_method(void)
|
||||||
return "WSAWaitForMultipleEvents";
|
return "WSAWaitForMultipleEvents";
|
||||||
}
|
}
|
||||||
|
|
||||||
//gowri remove static
|
|
||||||
/** call timeouts handlers, and return how long to wait for next one or -1 */
|
/** call timeouts handlers, and return how long to wait for next one or -1 */
|
||||||
void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* now,
|
void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* now,
|
||||||
struct timeval* wait)
|
struct timeval* wait)
|
||||||
|
@ -288,7 +290,6 @@ void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* no
|
||||||
#ifndef S_SPLINT_S
|
#ifndef S_SPLINT_S
|
||||||
wait->tv_sec = (time_t)-1;
|
wait->tv_sec = (time_t)-1;
|
||||||
#endif
|
#endif
|
||||||
//verbose(VERB_CLIENT, "winsock_event handle_timeouts");
|
|
||||||
|
|
||||||
while((_getdns_rbnode_t*)(p = (struct _getdns_event*)_getdns_rbtree_first(base->times))
|
while((_getdns_rbnode_t*)(p = (struct _getdns_event*)_getdns_rbtree_first(base->times))
|
||||||
!=RBTREE_NULL) {
|
!=RBTREE_NULL) {
|
||||||
|
@ -306,8 +307,6 @@ void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* no
|
||||||
wait->tv_usec = p->ev_timeout.tv_usec
|
wait->tv_usec = p->ev_timeout.tv_usec
|
||||||
- now->tv_usec;
|
- now->tv_usec;
|
||||||
}
|
}
|
||||||
//verbose(VERB_CLIENT, "winsock_event wait=" ARG_LL "d.%6.6d",
|
|
||||||
// (long long)wait->tv_sec, (int)wait->tv_usec);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -317,7 +316,6 @@ void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* no
|
||||||
fptr_ok(fptr_whitelist_event(p->ev_callback));
|
fptr_ok(fptr_whitelist_event(p->ev_callback));
|
||||||
(*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg);
|
(*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg);
|
||||||
}
|
}
|
||||||
//verbose(VERB_CLIENT, "winsock_event wait=(-1)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** handle is_signal events and see if signalled */
|
/** handle is_signal events and see if signalled */
|
||||||
|
@ -380,7 +378,8 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
eventlist[numwait] = base->items[i];
|
eventlist[numwait] = base->items[i];
|
||||||
base->waitfor[numwait++] = base->items[i]->hEvent;
|
base->waitfor[numwait++] = base->items[i]->hEvent;
|
||||||
printf("winsock_event bmax=%d numwait=%d wait=%x "
|
printf("winsock_event bmax=%d numwait=%d wait=%x "
|
||||||
"timeout=%d hEvent %d\n", base->max, numwait, (int)wait, (int)timeout, base->items[i]->hEvent);
|
"timeout=%d hEvent %d\n", base->max, numwait, (int)wait,
|
||||||
|
(int)timeout, base->items[i]->hEvent);
|
||||||
if (numwait == WSK_MAX_ITEMS)
|
if (numwait == WSK_MAX_ITEMS)
|
||||||
break; /* sanity check */
|
break; /* sanity check */
|
||||||
}
|
}
|
||||||
|
@ -398,19 +397,19 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
//gv: do not schedule udp write
|
//gv: do not schedule udp write
|
||||||
for (i = 0; i<base->max; i++) {
|
for (i = 0; i<base->max; i++) {
|
||||||
if (!base->items[i]->is_tcp && base->items[i]->ev_events&EV_WRITE) {
|
if (!base->items[i]->is_tcp && base->items[i]->ev_events&EV_WRITE) {
|
||||||
//gprintf("skip UDP sched\n");
|
printf("skip UDP sched\n");
|
||||||
(*eventlist[i]->ev_callback)(eventlist[i]->ev_fd,
|
(*eventlist[i]->ev_callback)(eventlist[i]->ev_fd,
|
||||||
EV_WRITE & eventlist[i]->ev_events,
|
EV_WRITE & eventlist[i]->ev_events,
|
||||||
eventlist[i]->ev_arg);
|
eventlist[i]->ev_arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//gprintf("before wait %d\n", base->items[0]->ev_events);
|
printf("before wait %d\n", base->items[0]->ev_events);
|
||||||
ret = WSAWaitForMultipleEvents(numwait, base->waitfor,
|
ret = WSAWaitForMultipleEvents(numwait, base->waitfor,
|
||||||
0 /* do not wait for all, just one will do */,
|
0 /* do not wait for all, just one will do */,
|
||||||
wait?timeout:WSA_INFINITE,
|
wait?timeout:WSA_INFINITE,
|
||||||
0); /* we are not alertable (IO completion events) */
|
0); /* we are not alertable (IO completion events) */
|
||||||
//gprintf("after wait %d %d\n", ret, numwait);
|
printf("after wait %d %d\n", ret, numwait);
|
||||||
if(ret == WSA_WAIT_IO_COMPLETION) {
|
if(ret == WSA_WAIT_IO_COMPLETION) {
|
||||||
//printf("getdns: WSAWaitForMultipleEvents failed: WSA_WAIT_IO_COMPLETION");
|
//printf("getdns: WSAWaitForMultipleEvents failed: WSA_WAIT_IO_COMPLETION");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -419,7 +418,7 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
// wsa_strerror(WSAGetLastError()));
|
// wsa_strerror(WSAGetLastError()));
|
||||||
return -1;
|
return -1;
|
||||||
} else if(ret == WSA_WAIT_TIMEOUT) {
|
} else if(ret == WSA_WAIT_TIMEOUT) {
|
||||||
//printf("timeout\n");
|
printf("timeout\n");
|
||||||
was_timeout = 1;
|
was_timeout = 1;
|
||||||
} else
|
} else
|
||||||
startidx = ret - WSA_WAIT_EVENT_0;
|
startidx = ret - WSA_WAIT_EVENT_0;
|
||||||
|
@ -510,12 +509,12 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
printf("FD_CLOSE_BIT\n");
|
printf("FD_CLOSE_BIT\n");
|
||||||
}
|
}
|
||||||
if(eventlist[i]->is_tcp && eventlist[i]->stick_events) {
|
if(eventlist[i]->is_tcp && eventlist[i]->stick_events) {
|
||||||
/*
|
|
||||||
printf("winsock %d pass sticky %s%s\n",
|
printf("winsock %d pass sticky %s%s\n",
|
||||||
eventlist[i]->ev_fd,
|
eventlist[i]->ev_fd,
|
||||||
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
||||||
(eventlist[i]->old_events&EV_WRITE)?"EV_WRITE":"");
|
(eventlist[i]->old_events&EV_WRITE)?"EV_WRITE":"");
|
||||||
*/
|
|
||||||
bits |= eventlist[i]->old_events;
|
bits |= eventlist[i]->old_events;
|
||||||
}
|
}
|
||||||
if(eventlist[i]->is_tcp && bits) {
|
if(eventlist[i]->is_tcp && bits) {
|
||||||
|
@ -524,12 +523,12 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
if((eventlist[i]->ev_events & bits)) {
|
if((eventlist[i]->ev_events & bits)) {
|
||||||
newstickies = 1;
|
newstickies = 1;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
printf("winsock %d store sticky %s%s",
|
printf("winsock %d store sticky %s%s",
|
||||||
eventlist[i]->ev_fd,
|
eventlist[i]->ev_fd,
|
||||||
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
||||||
(eventlist[i]->old_events&EV_WRITE)?"EV_WRITE":"");
|
(eventlist[i]->old_events&EV_WRITE) ? "EV_WRITE" : "");
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
if((bits & eventlist[i]->ev_events)) {
|
if((bits & eventlist[i]->ev_events)) {
|
||||||
printf( "winsock event callback %p fd=%d "
|
printf( "winsock event callback %p fd=%d "
|
||||||
|
@ -552,13 +551,13 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
|
||||||
bits & eventlist[i]->ev_events,
|
bits & eventlist[i]->ev_events,
|
||||||
eventlist[i]->ev_arg);
|
eventlist[i]->ev_arg);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if(eventlist[i]->is_tcp && bits)
|
if(eventlist[i]->is_tcp && bits)
|
||||||
printf( "winsock %d got sticky %s%s\n",
|
printf( "winsock %d got sticky %s%s\n",
|
||||||
eventlist[i]->ev_fd,
|
eventlist[i]->ev_fd,
|
||||||
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
(eventlist[i]->old_events&EV_READ)?"EV_READ":"",
|
||||||
(eventlist[i]->old_events&EV_WRITE)?"EV_WRITE":"");
|
(eventlist[i]->old_events&EV_WRITE)?"EV_WRITE":"");
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
//verbose(VERB_CLIENT, "winsock_event net");
|
//verbose(VERB_CLIENT, "winsock_event net");
|
||||||
if(base->tcp_reinvigorated) {
|
if(base->tcp_reinvigorated) {
|
||||||
|
@ -595,14 +594,12 @@ int _getdns_event_base_dispatch(struct _getdns_event_base *base)
|
||||||
int _getdns_event_base_loopexit(struct _getdns_event_base *base,
|
int _getdns_event_base_loopexit(struct _getdns_event_base *base,
|
||||||
struct timeval * ATTR_UNUSED(tv))
|
struct timeval * ATTR_UNUSED(tv))
|
||||||
{
|
{
|
||||||
//verbose(VERB_CLIENT, "winsock_event loopexit");
|
|
||||||
base->need_to_exit = 1;
|
base->need_to_exit = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getdns_event_base_free(struct _getdns_event_base *base)
|
void _getdns_event_base_free(struct _getdns_event_base *base)
|
||||||
{
|
{
|
||||||
//verbose(VERB_CLIENT, "winsock_event event_base_free");
|
|
||||||
if(!base)
|
if(!base)
|
||||||
return;
|
return;
|
||||||
if(base->items)
|
if(base->items)
|
||||||
|
@ -718,8 +715,6 @@ int _getdns_event_add(struct _getdns_event *ev, struct timeval *tv)
|
||||||
/* automatically sets fd to nonblocking mode.
|
/* automatically sets fd to nonblocking mode.
|
||||||
* nonblocking cannot be disabled, until wsaES(fd, NULL, 0) */
|
* nonblocking cannot be disabled, until wsaES(fd, NULL, 0) */
|
||||||
printf("\nWSAEventSelect %d events %d hEvent %d\n", ev->ev_fd, events, ev->hEvent);
|
printf("\nWSAEventSelect %d events %d hEvent %d\n", ev->ev_fd, events, ev->hEvent);
|
||||||
//gg if (WSAEventSelect(ev->ev_fd, ev->hEvent, FD_ACCEPT | FD_CONNECT | FD_READ | FD_CLOSE | FD_WRITE) != 0) {
|
|
||||||
//if (WSAEventSelect(ev->ev_fd, ev->hEvent,FD_READ | FD_WRITE) != 0) {
|
|
||||||
if (WSAEventSelect(ev->ev_fd, ev->hEvent, events) != 0) {
|
if (WSAEventSelect(ev->ev_fd, ev->hEvent, events) != 0) {
|
||||||
log_err("getdns: WSAEventSelect in getdns failed: %s",
|
log_err("getdns: WSAEventSelect in getdns failed: %s",
|
||||||
wsa_strerror(WSAGetLastError()));
|
wsa_strerror(WSAGetLastError()));
|
||||||
|
@ -727,11 +722,14 @@ int _getdns_event_add(struct _getdns_event *ev, struct timeval *tv)
|
||||||
if(ev->is_tcp && ev->stick_events &&
|
if(ev->is_tcp && ev->stick_events &&
|
||||||
(ev->ev_events & ev->old_events)) {
|
(ev->ev_events & ev->old_events)) {
|
||||||
/* go to processing the sticky event right away */
|
/* go to processing the sticky event right away */
|
||||||
|
printf("\nWSAEventSelect sticky %d events %d hEvent %d\n", ev->ev_fd, events, ev->hEvent);
|
||||||
ev->ev_base->tcp_reinvigorated = 1;
|
ev->ev_base->tcp_reinvigorated = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tv && (ev->ev_events&EV_TIMEOUT)) {
|
if(tv && (ev->ev_events&EV_TIMEOUT)) {
|
||||||
|
printf("\nWSAEventSelect timeout %d hEvent %d\n", ev->ev_fd, ev->hEvent);
|
||||||
|
|
||||||
#ifndef S_SPLINT_S
|
#ifndef S_SPLINT_S
|
||||||
struct timeval *now = ev->ev_base->time_tv;
|
struct timeval *now = ev->ev_base->time_tv;
|
||||||
ev->ev_timeout.tv_sec = tv->tv_sec + now->tv_sec;
|
ev->ev_timeout.tv_sec = tv->tv_sec + now->tv_sec;
|
||||||
|
@ -823,8 +821,8 @@ int _getdns_signal_del(struct _getdns_event *ev)
|
||||||
|
|
||||||
void winsock_tcp_wouldblock(struct _getdns_event* ev, int eventbits)
|
void winsock_tcp_wouldblock(struct _getdns_event* ev, int eventbits)
|
||||||
{
|
{
|
||||||
//verbose(VERB_ALGO, "winsock: tcp wouldblock %s",
|
printf("winsock: tcp wouldblock %s\n",
|
||||||
//eventbits==EV_READ?"EV_READ":"EV_WRITE");
|
eventbits==EV_READ?"EV_READ":"EV_WRITE");
|
||||||
ev->old_events &= (~eventbits);
|
ev->old_events &= (~eventbits);
|
||||||
if(ev->old_events == 0)
|
if(ev->old_events == 0)
|
||||||
ev->stick_events = 0;
|
ev->stick_events = 0;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
* This file contains interface functions with the WinSock2 API on Windows.
|
* This file contains interface functions with the WinSock2 API on Windows.
|
||||||
* It uses the winsock WSAWaitForMultipleEvents interface on a number of
|
* It uses the winsock WSAWaitForMultipleEvents interface on a number of
|
||||||
* sockets.
|
* sockets.
|
||||||
|
* Code is originally from the Unbound source for Windows.
|
||||||
*
|
*
|
||||||
* Note that windows can only wait for max 64 events at one time.
|
* Note that windows can only wait for max 64 events at one time.
|
||||||
*
|
*
|
||||||
|
@ -267,7 +268,7 @@ int getdns_mini_ev_cmp(const void* a, const void* b);
|
||||||
* retesting the event.
|
* retesting the event.
|
||||||
* Pass if EV_READ or EV_WRITE gave wouldblock.
|
* Pass if EV_READ or EV_WRITE gave wouldblock.
|
||||||
*/
|
*/
|
||||||
static void winsock_tcp_wouldblock(struct _getdns_event* ev, int eventbit);
|
void winsock_tcp_wouldblock(struct _getdns_event* ev, int eventbit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Routine for windows only. where you pass a signal WSAEvent that
|
* Routine for windows only. where you pass a signal WSAEvent that
|
||||||
|
|
Loading…
Reference in New Issue