]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
use bgsend in send()
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 10 Jan 2006 13:58:31 +0000 (13:58 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 10 Jan 2006 13:58:31 +0000 (13:58 +0000)
ldns/net.h
net.c

index a74a86fccdbaa684f7c57bc64bd16a1fc7d01025..6e0335e04a6c48a2f2b51e44de2b723de3d92aef 100644 (file)
@@ -46,7 +46,7 @@ ldns_status ldns_udp_send(uint8_t **result, ldns_buffer *qbin, const struct sock
  * \return the socket used
  */
 
-int ldns_udp_sendbg(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
+int ldns_udp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
 
 /**
  * Send an tcp query and don't wait for an answer but return
@@ -57,7 +57,7 @@ int ldns_udp_sendbg(ldns_buffer *qbin, const struct sockaddr_storage *to, sockle
  * \param[in] timeout the timeout value for the network
  * \return the socket used
  */
-int ldns_tcp_sendbg(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
+int ldns_tcp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
 
 /**
  * Sends a buffer to an ip using tcp and return the respons as a ldns_pkt
diff --git a/net.c b/net.c
index 3dcecbea3be485cbb0b4e4c22567331b4c9915e2..2c41931fccea9a1d8cca6206b9622664d620bcb4 100644 (file)
--- a/net.c
+++ b/net.c
@@ -174,16 +174,12 @@ ldns_udp_send(uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage
        int sockfd;
        uint8_t *answer;
 
-       sockfd = ldns_udp_connect(to, timeout);
+       sockfd = ldns_udp_bgsend(qbin, to, tolen, timeout);
 
        if (sockfd == 0) {
                return LDNS_STATUS_ERR;
        }
 
-       if (ldns_udp_send_query(qbin, sockfd, to, tolen) == 0) {
-               return LDNS_STATUS_ERR;
-       }
-       
        /* wait for an response*/
        answer = ldns_udp_read_wire(sockfd, answer_size, NULL, NULL);
 
@@ -446,18 +442,19 @@ ldns_tcp_send(uint8_t **result,  ldns_buffer *qbin, const struct sockaddr_storag
        int sockfd;
        uint8_t *answer;
        
-       sockfd = ldns_tcp_connect(to, tolen, timeout);
+       sockfd = ldns_tcp_bgsend(qbin, to, tolen, timeout);
        
        if (sockfd == 0) {
                return LDNS_STATUS_ERR;
        }
        
-       if (ldns_tcp_send_query(qbin, sockfd, to, tolen) == 0) {
-               return LDNS_STATUS_ERR;
-       }
-       
        answer = ldns_tcp_read_wire(sockfd, answer_size);
 
+       if (*answer_size == 0) {
+               /* oops */
+               return LDNS_STATUS_NETWORK_ERR;
+       }
+
        /* resize accordingly */
        answer = (uint8_t*)LDNS_XREALLOC(answer, uint8_t *, (size_t)*answer_size);
        *result = answer;