Changeset 8b863a62 in mainline for uspace/srv/net/dnsrsrv/transport.c
- Timestamp:
- 2014-04-16T17:14:06Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f857e8b
- Parents:
- dba3e2c (diff), 70b570c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
uspace/srv/net/dnsrsrv/transport.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dnsrsrv/transport.c
rdba3e2c r8b863a62 52 52 53 53 /** Request timeout (microseconds) */ 54 #define REQ_TIMEOUT (5 *1000*1000)54 #define REQ_TIMEOUT (5 * 1000 * 1000) 55 55 56 56 /** Maximum number of retries */ 57 57 #define REQ_RETRY_MAX 3 58 59 inet_addr_t dns_server_addr; 58 60 59 61 typedef struct { … … 72 74 static fid_t recv_fid; 73 75 static int transport_fd = -1; 74 inet_addr_t dns_server_addr;75 76 76 77 /** Outstanding requests */ … … 157 158 assert(fibril_mutex_is_locked(&treq_lock)); 158 159 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) { 162 161 if (treq->req->id == resp->id) { 163 162 /* Match */ … … 182 181 int dns_request(dns_message_t *req, dns_message_t **rresp) 183 182 { 184 int rc; 183 trans_req_t *treq = NULL; 184 struct sockaddr *saddr = NULL; 185 socklen_t saddrlen; 186 185 187 void *req_data; 186 188 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); 199 190 if (rc != EOK) 200 191 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 204 202 while (ntry < REQ_RETRY_MAX) { 205 203 rc = sendto(transport_fd, req_data, req_size, 0, 206 (struct sockaddr *)&addr, sizeof(addr));204 saddr, saddrlen); 207 205 if (rc != EOK) 208 206 goto error; 209 207 210 208 treq = treq_create(req); 211 209 if (treq == NULL) { … … 213 211 goto error; 214 212 } 215 216 213 217 214 fibril_mutex_lock(&treq->done_lock); 218 215 while (treq->done != true) { … … 224 221 } 225 222 } 226 223 227 224 fibril_mutex_unlock(&treq->done_lock); 228 225 229 226 if (rc != ETIMEOUT) 230 227 break; 231 228 } 232 229 233 230 if (ntry >= REQ_RETRY_MAX) { 234 231 rc = EIO; 235 232 goto error; 236 233 } 237 234 238 235 if (treq->status != EOK) { 239 236 rc = treq->status; 240 237 goto error; 241 238 } 242 239 243 240 *rresp = treq->resp; 244 241 treq_destroy(treq); 245 242 free(req_data); 243 free(saddr); 246 244 return EOK; 245 247 246 error: 248 247 if (treq != NULL) 249 248 treq_destroy(treq); 249 250 250 free(req_data); 251 free(saddr); 251 252 return rc; 252 253 }
Note:
See TracChangeset
for help on using the changeset viewer.
