Changes in uspace/lib/c/generic/inetping.c [9749e47:3e66428] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inetping.c
r9749e47 r3e66428 1 1 /* 2 * Copyright (c) 2013 Jiri Svoboda 3 * Copyright (c) 2013 Martin Decky 2 * Copyright (c) 2012 Jiri Svoboda 4 3 * All rights reserved. 5 4 * … … 50 49 51 50 assert(inetping_sess == NULL); 52 51 53 52 inetping_ev_ops = ev_ops; 54 53 55 54 rc = loc_service_get_id(SERVICE_NAME_INETPING, &inetping_svc, 56 55 IPC_FLAG_BLOCKING); 57 56 if (rc != EOK) 58 57 return ENOENT; 59 58 60 59 inetping_sess = loc_service_connect(EXCHANGE_SERIALIZE, inetping_svc, 61 60 IPC_FLAG_BLOCKING); 62 61 if (inetping_sess == NULL) 63 62 return ENOENT; 64 63 65 64 async_exch_t *exch = async_exchange_begin(inetping_sess); 66 65 67 66 rc = async_connect_to_me(exch, 0, 0, 0, inetping_cb_conn, NULL); 68 67 async_exchange_end(exch); 69 68 70 69 if (rc != EOK) { 71 70 async_hangup(inetping_sess); … … 73 72 return rc; 74 73 } 75 74 76 75 return EOK; 77 76 } … … 80 79 { 81 80 async_exch_t *exch = async_exchange_begin(inetping_sess); 82 81 83 82 ipc_call_t answer; 84 aid_t req = async_send_1(exch, INETPING_SEND, sdu->seq_no, &answer); 85 86 int rc = async_data_write_start(exch, &sdu->src, sizeof(sdu->src)); 87 if (rc != EOK) { 88 async_exchange_end(exch); 83 aid_t req = async_send_3(exch, INETPING_SEND, (sysarg_t) sdu->src, 84 (sysarg_t) sdu->dest, sdu->seq_no, &answer); 85 sysarg_t retval = async_data_write_start(exch, sdu->data, sdu->size); 86 87 async_exchange_end(exch); 88 89 if (retval != EOK) { 89 90 async_forget(req); 90 return r c;91 return retval; 91 92 } 92 93 rc = async_data_write_start(exch, &sdu->dest, sizeof(sdu->dest)); 94 if (rc != EOK) { 95 async_exchange_end(exch); 96 async_forget(req); 97 return rc; 98 } 99 100 rc = async_data_write_start(exch, sdu->data, sdu->size); 101 102 async_exchange_end(exch); 103 104 if (rc != EOK) { 105 async_forget(req); 106 return rc; 107 } 108 109 sysarg_t retval; 93 110 94 async_wait_for(req, &retval); 111 112 return (int) retval; 95 return retval; 113 96 } 114 97 115 int inetping_get_srcaddr( const inet_addr_t *remote, inet_addr_t *local)98 int inetping_get_srcaddr(uint32_t remote, uint32_t *local) 116 99 { 117 100 async_exch_t *exch = async_exchange_begin(inetping_sess); 118 119 ipc_call_t answer;120 aid_t req = async_send_0(exch, INETPING_GET_SRCADDR, &answer);121 122 int rc = async_data_write_start(exch, remote, sizeof(*remote));123 if (rc != EOK) {124 async_exchange_end(exch);125 async_forget(req);101 102 sysarg_t local_addr; 103 int rc = async_req_1_1(exch, INETPING_GET_SRCADDR, (sysarg_t) remote, 104 &local_addr); 105 106 async_exchange_end(exch); 107 108 if (rc != EOK) 126 109 return rc; 127 } 128 129 ipc_call_t answer_local; 130 aid_t req_local = async_data_read(exch, local, sizeof(*local), 131 &answer_local); 132 133 async_exchange_end(exch); 134 135 sysarg_t retval_local; 136 async_wait_for(req_local, &retval_local); 137 138 if (retval_local != EOK) { 139 async_forget(req); 140 return (int) retval_local; 141 } 142 143 sysarg_t retval; 144 async_wait_for(req, &retval); 145 146 return (int) retval; 110 111 *local = (uint32_t) local_addr; 112 return EOK; 147 113 } 148 114 149 static void inetping_ev_recv(ipc_callid_t iid, ipc_call_t *icall)115 static void inetping_ev_recv(ipc_callid_t callid, ipc_call_t *call) 150 116 { 151 117 inetping_sdu_t sdu; 152 153 sdu.s eq_no = IPC_GET_ARG1(*icall);154 155 ipc_callid_t callid;156 size_t size;157 i f (!async_data_write_receive(&callid, &size)) {158 async_answer_0(callid, EREFUSED);159 async_answer_0( iid, EREFUSED);118 119 sdu.src = IPC_GET_ARG1(*call); 120 sdu.dest = IPC_GET_ARG2(*call); 121 sdu.seq_no = IPC_GET_ARG3(*call); 122 123 int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 124 if (rc != EOK) { 125 async_answer_0(callid, rc); 160 126 return; 161 127 } 162 163 if (size != sizeof(sdu.src)) { 164 async_answer_0(callid, EINVAL); 165 async_answer_0(iid, EINVAL); 166 return; 167 } 168 169 int rc = async_data_write_finalize(callid, &sdu.src, size); 170 if (rc != EOK) { 171 async_answer_0(callid, rc); 172 async_answer_0(iid, rc); 173 return; 174 } 175 176 if (!async_data_write_receive(&callid, &size)) { 177 async_answer_0(callid, EREFUSED); 178 async_answer_0(iid, EREFUSED); 179 return; 180 } 181 182 if (size != sizeof(sdu.dest)) { 183 async_answer_0(callid, EINVAL); 184 async_answer_0(iid, EINVAL); 185 return; 186 } 187 188 rc = async_data_write_finalize(callid, &sdu.dest, size); 189 if (rc != EOK) { 190 async_answer_0(callid, rc); 191 async_answer_0(iid, rc); 192 return; 193 } 194 195 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 196 if (rc != EOK) { 197 async_answer_0(iid, rc); 198 return; 199 } 200 128 201 129 rc = inetping_ev_ops->recv(&sdu); 202 130 free(sdu.data); 203 async_answer_0( iid, rc);131 async_answer_0(callid, rc); 204 132 } 205 133
Note:
See TracChangeset
for help on using the changeset viewer.