diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-12-12 02:56:23 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-12-12 02:56:23 +0000 |
commit | e53bca15e7fd66aea802d657030e14ad5eb3b0d5 (patch) | |
tree | 61054e871584b0382a4cca6f89a43a4e227ae7b8 /src | |
parent | c58d9494dfff0a404c8b86b89733277915c279ff (diff) | |
download | tor-e53bca15e7fd66aea802d657030e14ad5eb3b0d5.tar.gz tor-e53bca15e7fd66aea802d657030e14ad5eb3b0d5.zip |
r11492@Kushana: nickm | 2006-12-11 12:30:23 -0500
Implement dns server reply retry logic.
svn:r9081
Diffstat (limited to 'src')
-rw-r--r-- | src/or/eventdns.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/or/eventdns.c b/src/or/eventdns.c index da4f952a4e..8fd09a1a15 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -1243,8 +1243,19 @@ server_port_read(struct evdns_server_port *s) { static void server_port_flush(struct evdns_server_port *port) { - // XXXX Writeme. - (void)port; + while (port->pending_replies) { + struct server_request *req = port->pending_replies; + int r = sendto(port->socket, req->response, req->response_len, 0, + (struct sockaddr*) &req->addr, req->addrlen); + if (r < 0) // handle errror XXXX + return; + evdns_server_request_free(req); + } + + (void) event_del(&port->event); + event_set(&port->event, port->socket, EV_READ | EV_PERSIST, + server_port_ready_callback, port); + event_add(&port->event, NULL); // handle error. XXXX } // set if we are waiting for the ability to write to this server. @@ -1671,34 +1682,43 @@ int evdns_request_respond(struct evdns_server_request *_req, int flags) { struct server_request *req = TO_SERVER_REQUEST(_req); + struct evdns_server_port *port = req->port; int r; if (!req->response) { if ((r = evdns_request_response_format(req, flags))<0) return r; } - r = sendto(req->port->socket, req->response, req->response_len, 0, + r = sendto(port->socket, req->response, req->response_len, 0, (struct sockaddr*) &req->addr, req->addrlen); if (r<0) { - int err = last_error(req->port->socket); + int err = last_error(port->socket); if (! error_is_eagain(err)) return -1; - if (req->port->pending_replies) { - req->prev_pending = req->port->pending_replies->prev_pending; - req->next_pending = req->port->pending_replies; + if (port->pending_replies) { + req->prev_pending = port->pending_replies->prev_pending; + req->next_pending = port->pending_replies; req->prev_pending->next_pending = req->next_pending->prev_pending = req; } else { req->prev_pending = req->next_pending = req; - req->port->pending_replies = req; - req->port->choaked = 1; + port->pending_replies = req; + port->choaked = 1; + + (void) event_del(&port->event); + event_set(&port->event, port->socket, EV_READ | EV_WRITE | EV_PERSIST, server_port_ready_callback, port); + + event_add(&port->event, NULL); // handle error. XXXX } - return 0; - } - // XXXX process pending replies. + return 1; + } evdns_server_request_free(req); + + if (req->port->pending_replies) + server_port_flush(port); + return 0; } |