Changeset 7b616e2 in mainline for uspace/srv
- Timestamp:
- 2017-09-27T22:40:09Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d076f16
- Parents:
- 8d6bcc8c
- Location:
- uspace/srv/ns
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/clonable.c
r8d6bcc8c r7b616e2 31 31 */ 32 32 33 #include < ipc/ipc.h>33 #include <async.h> 34 34 #include <ipc/services.h> 35 35 #include <adt/list.h> … … 81 81 /* There was no pending connection request. */ 82 82 printf("%s: Unexpected clonable server.\n", NAME); 83 ipc_answer_0(callid, EBUSY);83 async_answer_0(callid, EBUSY); 84 84 return; 85 85 } … … 91 91 assert(csr->service == SERVICE_LOADER); 92 92 93 ipc_answer_0(callid, EOK);93 async_answer_0(callid, EOK); 94 94 95 ipc_forward_fast(csr->callid, phone, csr->iface, csr->arg3, 0, 95 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 96 if (sess == NULL) 97 async_answer_0(callid, EIO); 98 99 async_exch_t *exch = async_exchange_begin(sess); 100 async_forward_fast(csr->callid, exch, csr->iface, csr->arg3, 0, 96 101 IPC_FF_NONE); 102 async_exchange_end(exch); 97 103 98 104 free(csr); 99 ipc_hangup(phone);105 async_hangup(sess); 100 106 } 101 107 … … 117 123 cs_req_t *csr = malloc(sizeof(cs_req_t)); 118 124 if (csr == NULL) { 119 ipc_answer_0(callid, ENOMEM);125 async_answer_0(callid, ENOMEM); 120 126 return; 121 127 } … … 126 132 if (rc < 0) { 127 133 free(csr); 128 ipc_answer_0(callid, rc);134 async_answer_0(callid, rc); 129 135 return; 130 136 } -
uspace/srv/ns/ns.c
r8d6bcc8c r7b616e2 36 36 */ 37 37 38 #include <ipc/ipc.h> 38 #include <abi/ipc/methods.h> 39 #include <async.h> 39 40 #include <ipc/ns.h> 40 41 #include <ipc/services.h> … … 47 48 #include "clonable.h" 48 49 #include "task.h" 50 51 static void ns_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 52 { 53 ipc_call_t call; 54 ipc_callid_t callid; 55 iface_t iface; 56 service_t service; 57 58 iface = IPC_GET_ARG1(*icall); 59 service = IPC_GET_ARG2(*icall); 60 if (service != 0) { 61 /* 62 * Client requests to be connected to a service. 63 */ 64 if (service_clonable(service)) { 65 connect_to_clonable(service, iface, icall, iid); 66 } else { 67 connect_to_service(service, iface, icall, iid); 68 } 69 return; 70 } 71 72 async_answer_0(iid, EOK); 73 74 while (true) { 75 process_pending_conn(); 76 77 callid = async_get_call(&call); 78 if (!IPC_GET_IMETHOD(call)) 79 break; 80 81 task_id_t id; 82 sysarg_t retval; 83 84 service_t service; 85 sysarg_t phone; 86 87 switch (IPC_GET_IMETHOD(call)) { 88 case NS_REGISTER: 89 service = IPC_GET_ARG1(call); 90 phone = IPC_GET_ARG5(call); 91 92 /* 93 * Server requests service registration. 94 */ 95 if (service_clonable(service)) { 96 register_clonable(service, phone, &call, callid); 97 continue; 98 } else { 99 retval = register_service(service, phone, &call); 100 } 101 102 break; 103 case NS_PING: 104 retval = EOK; 105 break; 106 case NS_TASK_WAIT: 107 id = (task_id_t) 108 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 109 wait_for_task(id, &call, callid); 110 continue; 111 case NS_ID_INTRO: 112 retval = ns_task_id_intro(&call); 113 break; 114 case NS_RETVAL: 115 retval = ns_task_retval(&call); 116 break; 117 default: 118 printf("ns: method not supported\n"); 119 retval = ENOTSUP; 120 break; 121 } 122 123 async_answer_0(callid, retval); 124 } 125 126 (void) ns_task_disconnect(&call); 127 } 49 128 50 129 int main(int argc, char **argv) … … 64 143 return rc; 65 144 145 async_set_fallback_port_handler(ns_connection, NULL); 146 66 147 printf("%s: Accepting connections\n", NAME); 67 68 while (true) { 69 process_pending_conn(); 70 71 ipc_call_t call; 72 ipc_callid_t callid = ipc_wait_for_call(&call); 73 74 task_id_t id; 75 sysarg_t retval; 76 77 iface_t iface; 78 service_t service; 79 sysarg_t phone; 80 81 switch (IPC_GET_IMETHOD(call)) { 82 case IPC_M_PHONE_HUNGUP: 83 retval = ns_task_disconnect(&call); 84 break; 85 case IPC_M_CONNECT_TO_ME: 86 service = IPC_GET_ARG2(call); 87 phone = IPC_GET_ARG5(call); 88 89 /* 90 * Server requests service registration. 91 */ 92 if (service_clonable(service)) { 93 register_clonable(service, phone, &call, callid); 94 continue; 95 } else 96 retval = register_service(service, phone, &call); 97 98 break; 99 case IPC_M_CONNECT_ME_TO: 100 iface = IPC_GET_ARG1(call); 101 service = IPC_GET_ARG2(call); 102 103 /* 104 * Client requests to be connected to a service. 105 */ 106 if (service_clonable(service)) { 107 connect_to_clonable(service, iface, &call, callid); 108 continue; 109 } else { 110 connect_to_service(service, iface, &call, callid); 111 continue; 112 } 113 break; 114 case NS_PING: 115 retval = EOK; 116 break; 117 case NS_TASK_WAIT: 118 id = (task_id_t) 119 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 120 wait_for_task(id, &call, callid); 121 continue; 122 case NS_ID_INTRO: 123 retval = ns_task_id_intro(&call); 124 break; 125 case NS_RETVAL: 126 retval = ns_task_retval(&call); 127 break; 128 default: 129 retval = ENOENT; 130 break; 131 } 132 133 if (!(callid & IPC_CALLID_NOTIFICATION)) 134 ipc_answer_0(callid, retval); 135 } 148 async_manager(); 136 149 137 150 /* Not reached */ -
uspace/srv/ns/service.c
r8d6bcc8c r7b616e2 31 31 */ 32 32 33 #include <ipc/ipc.h>34 33 #include <adt/hash_table.h> 35 34 #include <assert.h> 35 #include <async.h> 36 36 #include <errno.h> 37 37 #include <stdio.h> … … 47 47 service_t service; 48 48 49 /** Phone registered with the interface */ 50 sysarg_t phone; 51 52 /** Incoming phone hash */ 53 sysarg_t in_phone_hash; 49 /** Session to the service */ 50 async_sess_t *sess; 54 51 } hashed_service_t; 55 52 … … 121 118 122 119 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 123 (void) ipc_forward_fast(pending->callid, hashed_service->phone, 124 pending->iface, pending->arg3, 0, IPC_FF_NONE); 120 async_exch_t *exch = async_exchange_begin(hashed_service->sess); 121 async_forward_fast(pending->callid, exch, pending->iface, 122 pending->arg3, 0, IPC_FF_NONE); 123 async_exchange_end(exch); 125 124 126 125 list_remove(&pending->link); … … 151 150 152 151 hashed_service->service = service; 153 hashed_service->phone = phone; 154 hashed_service->in_phone_hash = call->in_phone_hash; 152 hashed_service->sess = async_callback_receive(EXCHANGE_SERIALIZE); 153 if (hashed_service->sess == NULL) 154 return EIO; 155 155 156 156 hash_table_insert(&service_hash_table, &hashed_service->link); 157 158 157 return EOK; 159 158 } … … 202 201 203 202 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 204 (void) ipc_forward_fast(callid, hashed_service->phone, iface, arg3, 205 0, IPC_FF_NONE); 203 async_exch_t *exch = async_exchange_begin(hashed_service->sess); 204 async_forward_fast(callid, exch, iface, arg3, 0, IPC_FF_NONE); 205 async_exchange_end(exch); 206 206 return; 207 207 208 208 out: 209 if (!(callid & IPC_CALLID_NOTIFICATION)) 210 ipc_answer_0(callid, retval); 209 async_answer_0(callid, retval); 211 210 } 212 211 -
uspace/srv/ns/task.c
r8d6bcc8c r7b616e2 32 32 */ 33 33 34 #include <ipc/ipc.h>35 34 #include <adt/hash_table.h> 35 #include <async.h> 36 36 #include <stdbool.h> 37 37 #include <errno.h> … … 182 182 continue; 183 183 184 if (!(pr->callid & IPC_CALLID_NOTIFICATION)) { 185 texit = ht->have_rval ? TASK_EXIT_NORMAL : 186 TASK_EXIT_UNEXPECTED; 187 ipc_answer_2(pr->callid, EOK, texit, 188 ht->retval); 189 } 184 texit = ht->have_rval ? TASK_EXIT_NORMAL : 185 TASK_EXIT_UNEXPECTED; 186 async_answer_2(pr->callid, EOK, texit, ht->retval); 190 187 191 188 list_remove(&pr->link); … … 203 200 if (ht == NULL) { 204 201 /* No such task exists. */ 205 ipc_answer_0(callid, ENOENT);202 async_answer_0(callid, ENOENT); 206 203 return; 207 204 } … … 210 207 task_exit_t texit = ht->have_rval ? TASK_EXIT_NORMAL : 211 208 TASK_EXIT_UNEXPECTED; 212 ipc_answer_2(callid, EOK, texit, ht->retval);209 async_answer_2(callid, EOK, texit, ht->retval); 213 210 return; 214 211 } … … 218 215 (pending_wait_t *) malloc(sizeof(pending_wait_t)); 219 216 if (!pr) { 220 if (!(callid & IPC_CALLID_NOTIFICATION)) 221 ipc_answer_0(callid, ENOMEM); 217 async_answer_0(callid, ENOMEM); 222 218 return; 223 219 } … … 282 278 int ns_task_retval(ipc_call_t *call) 283 279 { 280 task_id_t id = call->in_task_id; 281 282 ht_link_t *link = hash_table_find(&task_hash_table, &id); 283 hashed_task_t *ht = (link != NULL) ? 284 hash_table_get_inst(link, hashed_task_t, link) : NULL; 285 286 if ((ht == NULL) || (ht->finished)) 287 return EINVAL; 288 289 ht->finished = true; 290 ht->have_rval = true; 291 ht->retval = IPC_GET_ARG1(*call); 292 293 process_pending_wait(); 294 295 return EOK; 296 } 297 298 int ns_task_disconnect(ipc_call_t *call) 299 { 284 300 task_id_t id; 285 301 int rc = get_id_by_phone(call->in_phone_hash, &id); … … 287 303 return rc; 288 304 289 ht_link_t *link = hash_table_find(&task_hash_table, &id);290 hashed_task_t *ht = (link != NULL) ?291 hash_table_get_inst(link, hashed_task_t, link) : NULL;292 293 if ((ht == NULL) || (ht->finished))294 return EINVAL;295 296 ht->finished = true;297 ht->have_rval = true;298 ht->retval = IPC_GET_ARG1(*call);299 300 process_pending_wait();301 302 return EOK;303 }304 305 int ns_task_disconnect(ipc_call_t *call)306 {307 task_id_t id;308 int rc = get_id_by_phone(call->in_phone_hash, &id);309 if (rc != EOK)310 return rc;311 312 305 /* Delete from phone-to-id map. */ 313 306 hash_table_remove(&phone_to_id, &call->in_phone_hash);
Note:
See TracChangeset
for help on using the changeset viewer.