Changeset 98abd40 in mainline for uspace/lib/c/generic/dnsr.c
- Timestamp:
- 2013-07-06T21:57:22Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c8bb1633, cdc8a391
- Parents:
- b8e72fd1 (diff), 507c6f3 (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/lib/c/generic/dnsr.c
rb8e72fd1 r98abd40 44 44 static async_exch_t *dnsr_exchange_begin(void) 45 45 { 46 async_sess_t *sess;47 service_id_t dnsr_svc;48 49 46 fibril_mutex_lock(&dnsr_sess_mutex); 50 47 51 48 if (dnsr_sess == NULL) { 49 service_id_t dnsr_svc; 50 52 51 (void) loc_service_get_id(SERVICE_NAME_DNSR, &dnsr_svc, 53 52 IPC_FLAG_BLOCKING); 54 53 55 54 dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc, 56 55 IPC_FLAG_BLOCKING); 57 56 } 58 59 sess = dnsr_sess;57 58 async_sess_t *sess = dnsr_sess; 60 59 fibril_mutex_unlock(&dnsr_sess_mutex); 61 60 62 61 return async_exchange_begin(sess); 63 62 } … … 70 69 int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo) 71 70 { 71 dnsr_hostinfo_t *info = calloc(1, sizeof(dnsr_hostinfo_t)); 72 if (info == NULL) 73 return ENOMEM; 74 72 75 async_exch_t *exch = dnsr_exchange_begin(); 73 char cname_buf[DNSR_NAME_MAX_SIZE + 1]; 74 ipc_call_t cnreply; 75 size_t act_size; 76 dnsr_hostinfo_t *info; 77 76 78 77 ipc_call_t answer; 79 78 aid_t req = async_send_0(exch, DNSR_NAME2HOST, &answer); 80 sysarg_t retval = async_data_write_start(exch, name, str_size(name)); 81 aid_t cnreq = async_data_read(exch, cname_buf, DNSR_NAME_MAX_SIZE, 82 &cnreply); 83 79 80 int rc = async_data_write_start(exch, name, str_size(name)); 81 if (rc != EOK) { 82 async_exchange_end(exch); 83 async_forget(req); 84 return rc; 85 } 86 87 ipc_call_t answer_addr; 88 aid_t req_addr = async_data_read(exch, &info->addr, 89 sizeof(inet_addr_t), &answer_addr); 90 91 sysarg_t retval_addr; 92 async_wait_for(req_addr, &retval_addr); 93 94 if (retval_addr != EOK) { 95 async_exchange_end(exch); 96 async_forget(req); 97 return (int) retval_addr; 98 } 99 100 ipc_call_t answer_cname; 101 char cname_buf[DNSR_NAME_MAX_SIZE + 1]; 102 aid_t req_cname = async_data_read(exch, cname_buf, DNSR_NAME_MAX_SIZE, 103 &answer_cname); 104 84 105 dnsr_exchange_end(exch); 85 86 if (retval != EOK) { 106 107 sysarg_t retval_cname; 108 async_wait_for(req_cname, &retval_cname); 109 110 if (retval_cname != EOK) { 87 111 async_forget(req); 88 async_forget(cnreq); 89 return retval; 112 return (int) retval_cname; 90 113 } 91 114 115 sysarg_t retval; 92 116 async_wait_for(req, &retval); 93 if (retval != EOK) { 94 async_forget(cnreq); 95 return EIO; 96 } 97 98 async_wait_for(cnreq, &retval); 117 99 118 if (retval != EOK) 100 return EIO; 101 102 info = calloc(1, sizeof(dnsr_hostinfo_t)); 103 if (info == NULL) 104 return ENOMEM; 105 106 act_size = IPC_GET_ARG2(cnreply); 119 return (int) retval; 120 121 size_t act_size = IPC_GET_ARG2(answer_cname); 107 122 assert(act_size <= DNSR_NAME_MAX_SIZE); 123 108 124 cname_buf[act_size] = '\0'; 109 125 110 126 info->cname = str_dup(cname_buf); 111 info->addr.ipv4 = IPC_GET_ARG1(answer); 112 127 113 128 *rinfo = info; 114 129 return EOK; … … 119 134 if (info == NULL) 120 135 return; 121 136 122 137 free(info->cname); 123 138 free(info); … … 126 141 int dnsr_get_srvaddr(inet_addr_t *srvaddr) 127 142 { 128 sysarg_t addr;129 143 async_exch_t *exch = dnsr_exchange_begin(); 130 131 int rc = async_req_0_1(exch, DNSR_GET_SRVADDR, &addr); 132 dnsr_exchange_end(exch); 133 134 if (rc != EOK) 144 145 ipc_call_t answer; 146 aid_t req = async_send_0(exch, DNSR_GET_SRVADDR, &answer); 147 int rc = async_data_read_start(exch, srvaddr, sizeof(inet_addr_t)); 148 149 loc_exchange_end(exch); 150 151 if (rc != EOK) { 152 async_forget(req); 135 153 return rc; 136 137 srvaddr->ipv4 = addr; 138 return EOK; 154 } 155 156 sysarg_t retval; 157 async_wait_for(req, &retval); 158 159 return (int) retval; 139 160 } 140 161 … … 142 163 { 143 164 async_exch_t *exch = dnsr_exchange_begin(); 144 145 int rc = async_req_1_0(exch, DNSR_SET_SRVADDR, srvaddr->ipv4); 146 dnsr_exchange_end(exch); 147 148 if (rc != EOK) 165 166 ipc_call_t answer; 167 aid_t req = async_send_0(exch, DNSR_SET_SRVADDR, &answer); 168 int rc = async_data_write_start(exch, srvaddr, sizeof(inet_addr_t)); 169 170 loc_exchange_end(exch); 171 172 if (rc != EOK) { 173 async_forget(req); 149 174 return rc; 150 151 return EOK; 175 } 176 177 sysarg_t retval; 178 async_wait_for(req, &retval); 179 180 return (int) retval; 152 181 } 153 182
Note:
See TracChangeset
for help on using the changeset viewer.