Changeset f3386d7 in mainline for uspace/srv/net/dnsrsrv/transport.c
- Timestamp:
- 2013-07-15T20:44:54Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f8d3df3
- Parents:
- 273c976 (diff), a940f1d (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
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dnsrsrv/transport.c
r273c976 rf3386d7 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 */ … … 182 183 int dns_request(dns_message_t *req, dns_message_t **rresp) 183 184 { 184 int rc; 185 trans_req_t *treq = NULL; 186 185 187 void *req_data; 186 188 size_t req_size; 189 int rc = dns_message_encode(req, &req_data, &req_size); 190 if (rc != EOK) 191 goto error; 192 187 193 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); 199 if (rc != EOK) 200 goto error; 201 202 ntry = 0; 203 194 struct sockaddr_in6 addr6; 195 uint16_t af = 196 inet_addr_sockaddr_in(&dns_server_addr, &addr, &addr6); 197 198 struct sockaddr *address; 199 socklen_t addrlen; 200 201 switch (af) { 202 case AF_INET: 203 addr.sin_port = htons(DNS_SERVER_PORT); 204 address = (struct sockaddr *) &addr; 205 addrlen = sizeof(addr); 206 break; 207 case AF_INET6: 208 addr6.sin6_port = htons(DNS_SERVER_PORT); 209 address = (struct sockaddr *) &addr6; 210 addrlen = sizeof(addr6); 211 break; 212 default: 213 rc = EAFNOSUPPORT; 214 goto error; 215 } 216 217 size_t ntry = 0; 218 204 219 while (ntry < REQ_RETRY_MAX) { 205 220 rc = sendto(transport_fd, req_data, req_size, 0, 206 (struct sockaddr *) &addr, sizeof(addr));221 (struct sockaddr *) address, addrlen); 207 222 if (rc != EOK) 208 223 goto error; 209 224 210 225 treq = treq_create(req); 211 226 if (treq == NULL) { … … 213 228 goto error; 214 229 } 215 216 230 217 231 fibril_mutex_lock(&treq->done_lock); 218 232 while (treq->done != true) { … … 224 238 } 225 239 } 226 240 227 241 fibril_mutex_unlock(&treq->done_lock); 228 242 229 243 if (rc != ETIMEOUT) 230 244 break; 231 245 } 232 246 233 247 if (ntry >= REQ_RETRY_MAX) { 234 248 rc = EIO; 235 249 goto error; 236 250 } 237 251 238 252 if (treq->status != EOK) { 239 253 rc = treq->status; 240 254 goto error; 241 255 } 242 256 243 257 *rresp = treq->resp; 244 258 treq_destroy(treq); 245 259 free(req_data); 246 260 return EOK; 261 247 262 error: 248 263 if (treq != NULL) 249 264 treq_destroy(treq); 265 250 266 free(req_data); 251 267 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.