Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsrsrv/transport.c

    r06fe3b6 r26de91a  
    5252
    5353/** Request timeout (microseconds) */
    54 #define REQ_TIMEOUT (5*1000*1000)
     54#define REQ_TIMEOUT (5 * 1000 * 1000)
    5555
    5656/** Maximum number of retries */
    5757#define REQ_RETRY_MAX 3
     58
     59inet_addr_t dns_server_addr;
    5860
    5961typedef struct {
     
    7274static fid_t recv_fid;
    7375static int transport_fd = -1;
    74 inet_addr_t dns_server_addr;
    7576
    7677/** Outstanding requests */
     
    157158        assert(fibril_mutex_is_locked(&treq_lock));
    158159
    159         list_foreach(treq_list, link) {
    160                 trans_req_t *treq = list_get_instance(link, trans_req_t, lreq);
    161 
     160        list_foreach(treq_list, lreq, trans_req_t, treq) {
    162161                if (treq->req->id == resp->id) {
    163162                        /* Match */
     
    182181int dns_request(dns_message_t *req, dns_message_t **rresp)
    183182{
    184         int rc;
     183        trans_req_t *treq = NULL;
     184        struct sockaddr *saddr = NULL;
     185        socklen_t saddrlen;
     186       
    185187        void *req_data;
    186188        size_t req_size;
    187         struct sockaddr_in addr;
    188         trans_req_t *treq;
    189         int ntry;
    190 
    191         req_data = NULL;
    192         treq = NULL;
    193 
    194         addr.sin_family = AF_INET;
    195         addr.sin_port = htons(DNS_SERVER_PORT);
    196         addr.sin_addr.s_addr = host2uint32_t_be(dns_server_addr.ipv4);
    197 
    198         rc = dns_message_encode(req, &req_data, &req_size);
     189        int rc = dns_message_encode(req, &req_data, &req_size);
    199190        if (rc != EOK)
    200191                goto error;
    201 
    202         ntry = 0;
    203 
     192       
     193        rc = inet_addr_sockaddr(&dns_server_addr, DNS_SERVER_PORT,
     194            &saddr, &saddrlen);
     195        if (rc != EOK) {
     196                assert(rc == ENOMEM);
     197                goto error;
     198        }
     199       
     200        size_t ntry = 0;
     201       
    204202        while (ntry < REQ_RETRY_MAX) {
    205203                rc = sendto(transport_fd, req_data, req_size, 0,
    206                     (struct sockaddr *)&addr, sizeof(addr));
     204                    saddr, saddrlen);
    207205                if (rc != EOK)
    208206                        goto error;
    209 
     207               
    210208                treq = treq_create(req);
    211209                if (treq == NULL) {
     
    213211                        goto error;
    214212                }
    215 
    216 
     213               
    217214                fibril_mutex_lock(&treq->done_lock);
    218215                while (treq->done != true) {
     
    224221                        }
    225222                }
    226 
     223               
    227224                fibril_mutex_unlock(&treq->done_lock);
    228 
     225               
    229226                if (rc != ETIMEOUT)
    230227                        break;
    231228        }
    232 
     229       
    233230        if (ntry >= REQ_RETRY_MAX) {
    234231                rc = EIO;
    235232                goto error;
    236233        }
    237 
     234       
    238235        if (treq->status != EOK) {
    239236                rc = treq->status;
    240237                goto error;
    241238        }
    242 
     239       
    243240        *rresp = treq->resp;
    244241        treq_destroy(treq);
    245242        free(req_data);
     243        free(saddr);
    246244        return EOK;
     245       
    247246error:
    248247        if (treq != NULL)
    249248                treq_destroy(treq);
     249       
    250250        free(req_data);
     251        free(saddr);
    251252        return rc;
    252253}
Note: See TracChangeset for help on using the changeset viewer.