- Timestamp:
- Jan 23, 2013 9:53:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
r4317 r4333 181 181 unsigned char udp_tx_pkt[UDPSZ];/**< UDP receive buffer. */ 182 182 pj_ssize_t udp_len; /**< Length of received packet. */ 183 pj_ioqueue_op_key_t udp_op_key; /**< UDP read operation key. */ 183 pj_ioqueue_op_key_t udp_op_rx_key; /**< UDP read operation key. */ 184 pj_ioqueue_op_key_t udp_op_tx_key; /**< UDP write operation key. */ 184 185 pj_sockaddr_in udp_src_addr; /**< Source address of packet */ 185 186 int udp_addr_len; /**< Source address length. */ … … 264 265 return status; 265 266 266 pj_ioqueue_op_key_init(&resv->udp_op_key, sizeof(resv->udp_op_key)); 267 pj_ioqueue_op_key_init(&resv->udp_op_rx_key, sizeof(resv->udp_op_rx_key)); 268 pj_ioqueue_op_key_init(&resv->udp_op_tx_key, sizeof(resv->udp_op_tx_key)); 267 269 268 270 /* Start asynchronous read to the UDP socket */ 269 271 resv->udp_len = sizeof(resv->udp_rx_pkt); 270 272 resv->udp_addr_len = sizeof(resv->udp_src_addr); 271 status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_ key,273 status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_rx_key, 272 274 resv->udp_rx_pkt, &resv->udp_len, 273 275 PJ_IOQUEUE_ALWAYS_ASYNC, … … 584 586 pj_status_t status; 585 587 586 /* Create DNS query packet */587 pkt_size = sizeof(resolver->udp_tx_pkt);588 name = pj_str(q->key.name);589 status = pj_dns_make_query(resolver->udp_tx_pkt, &pkt_size,590 q->id, q->key.qtype, &name);591 if (status != PJ_SUCCESS) {592 return status;593 }594 595 588 /* Select which nameserver(s) to send requests to. */ 596 589 server_cnt = PJ_ARRAY_SIZE(servers); … … 618 611 } 619 612 613 /* Check if the socket is available for sending */ 614 if (pj_ioqueue_is_pending(resolver->udp_key, &resolver->udp_op_tx_key)) { 615 ++q->transmit_cnt; 616 PJ_LOG(4,(resolver->name.ptr, 617 "Socket busy in transmitting DNS %s query for %s%s", 618 pj_dns_get_type_name(q->key.qtype), 619 q->key.name, 620 (q->transmit_cnt < resolver->settings.qretr_count? 621 ", will try again later":""))); 622 return PJ_SUCCESS; 623 } 624 625 /* Create DNS query packet */ 626 pkt_size = sizeof(resolver->udp_tx_pkt); 627 name = pj_str(q->key.name); 628 status = pj_dns_make_query(resolver->udp_tx_pkt, &pkt_size, 629 q->id, q->key.qtype, &name); 630 if (status != PJ_SUCCESS) { 631 pj_timer_heap_cancel(resolver->timer, &q->timer_entry); 632 return status; 633 } 634 620 635 /* Get current time. */ 621 636 pj_gettimeofday(&now); … … 626 641 struct nameserver *ns = &resolver->ns[servers[i]]; 627 642 628 status = pj_sock_sendto(resolver->udp_sock, resolver->udp_tx_pkt, 629 &sent, 0, &resolver->ns[servers[i]].addr, 630 sizeof(pj_sockaddr_in)); 631 632 #if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 633 PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 634 /* Re-init dead UDP sockets, see ticket #1107 & #1603. 635 * Note: PJ_STATUS_FROM_OS(EPIPE) == PJ_ERRNO_START_SYS + 32. 636 */ 637 if (status == PJ_ERRNO_START_SYS + 32) { 638 close_sock(resolver); 639 status = init_sock(resolver); 640 if (status != PJ_SUCCESS) { 641 PJ_PERROR(1,(THIS_FILE, status, "Error reinit UDP socket")); 642 return status; 643 } 644 645 PJ_LOG(3,(THIS_FILE, "UDP socket reinitialized.")); 646 647 /* Try to send again */ 648 status = pj_sock_sendto(resolver->udp_sock, resolver->udp_tx_pkt, 649 &sent, 0, &resolver->ns[servers[i]].addr, 650 sizeof(pj_sockaddr_in)); 651 } 652 #endif 643 status = pj_ioqueue_sendto(resolver->udp_key, 644 &resolver->udp_op_tx_key, 645 resolver->udp_tx_pkt, &sent, 0, 646 &resolver->ns[servers[i]].addr, 647 sizeof(pj_sockaddr_in)); 653 648 654 649 PJ_PERROR(4,(resolver->name.ptr, status,
Note: See TracChangeset
for help on using the changeset viewer.