Changeset 01c3bb4 in mainline for uspace/lib/c/generic/async.c
- Timestamp:
- 2017-11-25T15:43:25Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce4a21a0
- Parents:
- 98cb5e0d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r98cb5e0d r01c3bb4 77 77 * } 78 78 * 79 * port_handler(ic allid, *icall)79 * port_handler(ichandle, *icall) 80 80 * { 81 81 * if (want_refuse) { 82 * async_answer_0(ic allid, ELIMIT);82 * async_answer_0(ichandle, ELIMIT); 83 83 * return; 84 84 * } 85 * async_answer_0(ic allid, EOK);86 * 87 * c allid= async_get_call(&call);88 * somehow_handle_the_call(c allid, call);89 * async_answer_2(c allid, 1, 2, 3);90 * 91 * c allid= async_get_call(&call);85 * async_answer_0(ichandle, EOK); 86 * 87 * chandle = async_get_call(&call); 88 * somehow_handle_the_call(chandle, call); 89 * async_answer_2(chandle, 1, 2, 3); 90 * 91 * chandle = async_get_call(&call); 92 92 * ... 93 93 * } … … 185 185 link_t link; 186 186 187 ipc_callid_t callid;187 cap_handle_t chandle; 188 188 ipc_call_t call; 189 189 } msg_t; … … 237 237 238 238 /** Identification of the opening call. */ 239 ipc_callid_t callid;239 cap_handle_t chandle; 240 240 241 241 /** Call data of the opening call. */ … … 243 243 244 244 /** Identification of the closing call. */ 245 ipc_callid_t close_callid;245 cap_handle_t close_chandle; 246 246 247 247 /** Fibril function that will be used to handle the connection. */ … … 374 374 /** Default fallback fibril function. 375 375 * 376 * This fallback fibril function gets called on incomming 377 * connections that donot have a specific handler defined.378 * 379 * @param c allid Hashof the incoming call.380 * @param call Data of the incoming call.381 * @param arg Local argument382 * 383 */ 384 static void default_fallback_port_handler( ipc_callid_t callid, ipc_call_t *call,385 void *arg)386 { 387 ipc_answer_0(c allid, ENOENT);376 * This fallback fibril function gets called on incomming connections that do 377 * not have a specific handler defined. 378 * 379 * @param chandle Handle of the incoming call. 380 * @param call Data of the incoming call. 381 * @param arg Local argument 382 * 383 */ 384 static void default_fallback_port_handler(cap_handle_t chandle, 385 ipc_call_t *call, void *arg) 386 { 387 ipc_answer_0(chandle, ENOENT); 388 388 } 389 389 … … 715 715 client_t *client = async_client_get(fibril_connection->in_task_id, true); 716 716 if (!client) { 717 ipc_answer_0(fibril_connection->c allid, ENOMEM);717 ipc_answer_0(fibril_connection->chandle, ENOMEM); 718 718 return 0; 719 719 } … … 724 724 * Call the connection handler function. 725 725 */ 726 fibril_connection->handler(fibril_connection->c allid,726 fibril_connection->handler(fibril_connection->chandle, 727 727 &fibril_connection->call, fibril_connection->data); 728 728 … … 751 751 752 752 list_remove(&msg->link); 753 ipc_answer_0(msg->c allid, EHANGUP);753 ipc_answer_0(msg->chandle, EHANGUP); 754 754 free(msg); 755 755 } … … 759 759 * i.e. IPC_M_PHONE_HUNGUP. 760 760 */ 761 if (fibril_connection->close_c allid)762 ipc_answer_0(fibril_connection->close_c allid, EOK);761 if (fibril_connection->close_chandle) 762 ipc_answer_0(fibril_connection->close_chandle, EOK); 763 763 764 764 free(fibril_connection); … … 768 768 /** Create a new fibril for a new connection. 769 769 * 770 * Create new fibril for connection, fill in connection structures 771 * and insert it into the hash table, so that later we can easily772 * do routing of messages toparticular fibrils.773 * 774 * @param in_task_id Identification of the incoming connection.775 * @param in_phone_hash Identification of the incoming connection.776 * @param c allid Hashof the opening IPC_M_CONNECT_ME_TO call.777 * If callid is zero, the connection was opened by778 * accepting the IPC_M_CONNECT_TO_ME call and this779 * function is called directly by the server.780 * @param call Call data of the opening call.781 * @param handler Connection handler.782 * @param data Client argument to pass to the connection handler.783 * 784 * @return New fibril id or NULL on failure.770 * Create new fibril for connection, fill in connection structures and insert it 771 * into the hash table, so that later we can easily do routing of messages to 772 * particular fibrils. 773 * 774 * @param in_task_id Identification of the incoming connection. 775 * @param in_phone_hash Identification of the incoming connection. 776 * @param chandle Handle of the opening IPC_M_CONNECT_ME_TO call. 777 * If chandle is CAP_NIL, the connection was opened by 778 * accepting the IPC_M_CONNECT_TO_ME call and this 779 * function is called directly by the server. 780 * @param call Call data of the opening call. 781 * @param handler Connection handler. 782 * @param data Client argument to pass to the connection handler. 783 * 784 * @return New fibril id or NULL on failure. 785 785 * 786 786 */ 787 787 static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 788 ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler,788 cap_handle_t chandle, ipc_call_t *call, async_port_handler_t handler, 789 789 void *data) 790 790 { 791 791 connection_t *conn = malloc(sizeof(*conn)); 792 792 if (!conn) { 793 if (c allid)794 ipc_answer_0(c allid, ENOMEM);793 if (chandle != CAP_NIL) 794 ipc_answer_0(chandle, ENOMEM); 795 795 796 796 return (uintptr_t) NULL; … … 800 800 conn->in_phone_hash = in_phone_hash; 801 801 list_initialize(&conn->msg_queue); 802 conn->c allid = callid;803 conn->close_c allid = 0;802 conn->chandle = chandle; 803 conn->close_chandle = CAP_NIL; 804 804 conn->handler = handler; 805 805 conn->data = data; … … 815 815 free(conn); 816 816 817 if (c allid)818 ipc_answer_0(c allid, ENOMEM);817 if (chandle != CAP_NIL) 818 ipc_answer_0(chandle, ENOMEM); 819 819 820 820 return (uintptr_t) NULL; … … 892 892 893 893 fid_t fid = async_new_connection(answer.in_task_id, phone_hash, 894 0, NULL, handler, data);894 CAP_NIL, NULL, handler, data); 895 895 if (fid == (uintptr_t) NULL) 896 896 return ENOMEM; … … 961 961 * timeouts are unregistered. 962 962 * 963 * @param c allid Hashof the incoming call.964 * @param call Data of the incoming call.963 * @param chandle Handle of the incoming call. 964 * @param call Data of the incoming call. 965 965 * 966 966 * @return False if the call doesn't match any connection. … … 968 968 * 969 969 */ 970 static bool route_call( ipc_callid_t callid, ipc_call_t *call)970 static bool route_call(cap_handle_t chandle, ipc_call_t *call) 971 971 { 972 972 assert(call); … … 991 991 } 992 992 993 msg->c allid = callid;993 msg->chandle = chandle; 994 994 msg->call = *call; 995 995 list_append(&msg->link, &conn->msg_queue); 996 996 997 997 if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP) 998 conn->close_c allid = callid;998 conn->close_chandle = chandle; 999 999 1000 1000 /* If the connection fibril is waiting for an event, activate it */ … … 1017 1017 /** Process notification. 1018 1018 * 1019 * @param callid Hash of the incoming call.1020 1019 * @param call Data of the incoming call. 1021 1020 * 1022 1021 */ 1023 static void process_notification(ipc_call id_t callid, ipc_call_t *call)1022 static void process_notification(ipc_call_t *call) 1024 1023 { 1025 1024 async_notification_handler_t handler = NULL; … … 1042 1041 1043 1042 if (handler) 1044 handler(call id, call, data);1043 handler(call, data); 1045 1044 } 1046 1045 … … 1187 1186 /** Return new incoming message for the current (fibril-local) connection. 1188 1187 * 1189 * @param call Storage where the incoming call data will be stored. 1190 * @param usecs Timeout in microseconds. Zero denotes no timeout. 1191 * 1192 * @return If no timeout was specified, then a hash of the 1193 * incoming call is returned. If a timeout is specified, 1194 * then a hash of the incoming call is returned unless 1195 * the timeout expires prior to receiving a message. In 1196 * that case zero is returned. 1197 * 1198 */ 1199 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs) 1188 * @param call Storage where the incoming call data will be stored. 1189 * @param usecs Timeout in microseconds. Zero denotes no timeout. 1190 * 1191 * @return If no timeout was specified, then a handle of the incoming call is 1192 * returned. If a timeout is specified, then a handle of the incoming 1193 * call is returned unless the timeout expires prior to receiving a 1194 * message. In that case zero CAP_NIL is returned. 1195 */ 1196 cap_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs) 1200 1197 { 1201 1198 assert(call); … … 1220 1217 /* If nothing in queue, wait until something arrives */ 1221 1218 while (list_empty(&conn->msg_queue)) { 1222 if (conn->close_c allid) {1219 if (conn->close_chandle) { 1223 1220 /* 1224 1221 * Handle the case when the connection was already … … 1231 1228 IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP); 1232 1229 futex_up(&async_futex); 1233 return conn->close_c allid;1230 return conn->close_chandle; 1234 1231 } 1235 1232 … … 1256 1253 /* If we timed out -> exit */ 1257 1254 futex_up(&async_futex); 1258 return 0;1255 return CAP_NIL; 1259 1256 } 1260 1257 } … … 1264 1261 list_remove(&msg->link); 1265 1262 1266 ipc_callid_t callid = msg->callid;1263 cap_handle_t chandle = msg->chandle; 1267 1264 *call = msg->call; 1268 1265 free(msg); 1269 1266 1270 1267 futex_up(&async_futex); 1271 return c allid;1268 return chandle; 1272 1269 } 1273 1270 … … 1332 1329 * Otherwise the call is routed to its connection fibril. 1333 1330 * 1334 * @param c allid Hashof the incoming call.1335 * @param call Data of the incoming call.1336 * 1337 */ 1338 static void handle_call( ipc_callid_t callid, ipc_call_t *call)1331 * @param chandle Handle of the incoming call. 1332 * @param call Data of the incoming call. 1333 * 1334 */ 1335 static void handle_call(cap_handle_t chandle, ipc_call_t *call) 1339 1336 { 1340 1337 assert(call); 1341 1338 1342 1339 /* Kernel notification */ 1343 if ( call->flags & IPC_CALLID_NOTIFICATION) {1340 if ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_NOTIFICATION)) { 1344 1341 fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data; 1345 1342 unsigned oldsw = fibril->switches; 1346 1343 1347 process_notification(call id, call);1344 process_notification(call); 1348 1345 1349 1346 if (oldsw != fibril->switches) { … … 1371 1368 sysarg_t in_phone_hash = IPC_GET_ARG5(*call); 1372 1369 1373 async_ notification_handler_t handler = fallback_port_handler;1370 async_port_handler_t handler = fallback_port_handler; 1374 1371 void *data = fallback_port_data; 1375 1372 … … 1381 1378 } 1382 1379 1383 async_new_connection(call->in_task_id, in_phone_hash, c allid,1380 async_new_connection(call->in_task_id, in_phone_hash, chandle, 1384 1381 call, handler, data); 1385 1382 return; … … 1387 1384 1388 1385 /* Try to route the call through the connection hash table */ 1389 if (route_call(c allid, call))1386 if (route_call(chandle, call)) 1390 1387 return; 1391 1388 1392 1389 /* Unknown call from unknown phone - hang it up */ 1393 ipc_answer_0(c allid, EHANGUP);1390 ipc_answer_0(chandle, EHANGUP); 1394 1391 } 1395 1392 … … 1486 1483 1487 1484 ipc_call_t call; 1488 ipc_callid_t callid= ipc_wait_cycle(&call, timeout, flags);1485 cap_handle_t chandle = ipc_wait_cycle(&call, timeout, flags); 1489 1486 1490 1487 atomic_dec(&threads_in_ipc_wait); 1491 1488 1492 if (!callid) { 1493 handle_expired_timeouts(); 1494 continue; 1489 assert(chandle >= 0); 1490 1491 if (chandle == CAP_NIL) { 1492 if (call.flags == 0) { 1493 /* This neither a notification nor an answer. */ 1494 handle_expired_timeouts(); 1495 continue; 1496 } 1495 1497 } 1496 1498 1497 1499 if (call.flags & IPC_CALLID_ANSWERED) 1498 1500 continue; 1499 1500 handle_call(c allid, &call);1501 } 1502 1501 1502 handle_call(chandle, &call); 1503 } 1504 1503 1505 return 0; 1504 1506 } … … 1631 1633 * @param arg3 Service-defined payload argument. 1632 1634 * @param arg4 Service-defined payload argument. 1633 * @param dataptr If non-NULL, storage where the reply data will be 1634 * stored. 1635 * @param dataptr If non-NULL, storage where the reply data will be stored. 1635 1636 * 1636 1637 * @return Hash of the sent message or 0 on error. … … 2018 2019 } 2019 2020 2020 sysarg_t async_answer_0( ipc_callid_t callid, sysarg_t retval)2021 { 2022 return ipc_answer_0(c allid, retval);2023 } 2024 2025 sysarg_t async_answer_1( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)2026 { 2027 return ipc_answer_1(c allid, retval, arg1);2028 } 2029 2030 sysarg_t async_answer_2( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2021 sysarg_t async_answer_0(cap_handle_t chandle, sysarg_t retval) 2022 { 2023 return ipc_answer_0(chandle, retval); 2024 } 2025 2026 sysarg_t async_answer_1(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1) 2027 { 2028 return ipc_answer_1(chandle, retval, arg1); 2029 } 2030 2031 sysarg_t async_answer_2(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2031 2032 sysarg_t arg2) 2032 2033 { 2033 return ipc_answer_2(c allid, retval, arg1, arg2);2034 } 2035 2036 sysarg_t async_answer_3( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2034 return ipc_answer_2(chandle, retval, arg1, arg2); 2035 } 2036 2037 sysarg_t async_answer_3(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2037 2038 sysarg_t arg2, sysarg_t arg3) 2038 2039 { 2039 return ipc_answer_3(c allid, retval, arg1, arg2, arg3);2040 } 2041 2042 sysarg_t async_answer_4( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2040 return ipc_answer_3(chandle, retval, arg1, arg2, arg3); 2041 } 2042 2043 sysarg_t async_answer_4(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2043 2044 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) 2044 2045 { 2045 return ipc_answer_4(c allid, retval, arg1, arg2, arg3, arg4);2046 } 2047 2048 sysarg_t async_answer_5( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2046 return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4); 2047 } 2048 2049 sysarg_t async_answer_5(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2049 2050 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5) 2050 2051 { 2051 return ipc_answer_5(c allid, retval, arg1, arg2, arg3, arg4, arg5);2052 } 2053 2054 int async_forward_fast( ipc_callid_t callid, async_exch_t *exch,2052 return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5); 2053 } 2054 2055 int async_forward_fast(cap_handle_t chandle, async_exch_t *exch, 2055 2056 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode) 2056 2057 { … … 2058 2059 return ENOENT; 2059 2060 2060 return ipc_forward_fast(c allid, exch->phone, imethod, arg1, arg2, mode);2061 } 2062 2063 int async_forward_slow( ipc_callid_t callid, async_exch_t *exch,2061 return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode); 2062 } 2063 2064 int async_forward_slow(cap_handle_t chandle, async_exch_t *exch, 2064 2065 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 2065 2066 sysarg_t arg4, sysarg_t arg5, unsigned int mode) … … 2068 2069 return ENOENT; 2069 2070 2070 return ipc_forward_slow(c allid, exch->phone, imethod, arg1, arg2, arg3,2071 return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3, 2071 2072 arg4, arg5, mode); 2072 2073 } … … 2604 2605 * So far, this wrapper is to be used from within a connection fibril. 2605 2606 * 2606 * @param c allid Storage for the hashof the IPC_M_SHARE_IN call.2607 * @param size Destination address space area size.2607 * @param chandle Storage for the handle of the IPC_M_SHARE_IN call. 2608 * @param size Destination address space area size. 2608 2609 * 2609 2610 * @return True on success, false on failure. 2610 2611 * 2611 2612 */ 2612 bool async_share_in_receive( ipc_callid_t *callid, size_t *size)2613 { 2614 assert(c allid);2613 bool async_share_in_receive(cap_handle_t *chandle, size_t *size) 2614 { 2615 assert(chandle); 2615 2616 assert(size); 2616 2617 2617 2618 ipc_call_t data; 2618 *c allid= async_get_call(&data);2619 *chandle = async_get_call(&data); 2619 2620 2620 2621 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN) … … 2631 2632 * argument. 2632 2633 * 2633 * @param c allid Hashof the IPC_M_DATA_READ call to answer.2634 * @param src Source address space base.2635 * @param flags Flags to be used for sharing. Bits can be only cleared.2634 * @param chandle Handle of the IPC_M_DATA_READ call to answer. 2635 * @param src Source address space base. 2636 * @param flags Flags to be used for sharing. Bits can be only cleared. 2636 2637 * 2637 2638 * @return Zero on success or a value from @ref errno.h on failure. 2638 2639 * 2639 2640 */ 2640 int async_share_in_finalize( ipc_callid_t callid, void *src, unsigned int flags)2641 { 2642 return ipc_answer_3(c allid, EOK, (sysarg_t) src, (sysarg_t) flags,2641 int async_share_in_finalize(cap_handle_t chandle, void *src, unsigned int flags) 2642 { 2643 return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags, 2643 2644 (sysarg_t) __entry); 2644 2645 } … … 2670 2671 * So far, this wrapper is to be used from within a connection fibril. 2671 2672 * 2672 * @param c allidStorage for the hash of the IPC_M_SHARE_OUT call.2673 * @param size Storage for the source address space area size.2674 * @param flags Storage for the sharing flags.2673 * @param chandle Storage for the hash of the IPC_M_SHARE_OUT call. 2674 * @param size Storage for the source address space area size. 2675 * @param flags Storage for the sharing flags. 2675 2676 * 2676 2677 * @return True on success, false on failure. 2677 2678 * 2678 2679 */ 2679 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags) 2680 { 2681 assert(callid); 2680 bool async_share_out_receive(cap_handle_t *chandle, size_t *size, 2681 unsigned int *flags) 2682 { 2683 assert(chandle); 2682 2684 assert(size); 2683 2685 assert(flags); 2684 2686 2685 2687 ipc_call_t data; 2686 *c allid= async_get_call(&data);2688 *chandle = async_get_call(&data); 2687 2689 2688 2690 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT) … … 2700 2702 * argument. 2701 2703 * 2702 * @param c allid Hashof the IPC_M_DATA_WRITE call to answer.2703 * @param dst Address of the storage for the destination address space area2704 * base address.2705 * 2706 * @return Zero on success or a value from @ref errno.h on failure.2707 * 2708 */ 2709 int async_share_out_finalize( ipc_callid_t callid, void **dst)2710 { 2711 return ipc_answer_2(c allid, EOK, (sysarg_t) __entry, (sysarg_t) dst);2704 * @param chandle Handle of the IPC_M_DATA_WRITE call to answer. 2705 * @param dst Address of the storage for the destination address space area 2706 * base address. 2707 * 2708 * @return Zero on success or a value from @ref errno.h on failure. 2709 * 2710 */ 2711 int async_share_out_finalize(cap_handle_t chandle, void **dst) 2712 { 2713 return ipc_answer_2(chandle, EOK, (sysarg_t) __entry, (sysarg_t) dst); 2712 2714 } 2713 2715 … … 2755 2757 * So far, this wrapper is to be used from within a connection fibril. 2756 2758 * 2757 * @param c allid Storage for the hashof the IPC_M_DATA_READ.2758 * @param size Storage for the maximum size. Can be NULL.2759 * @param chandle Storage for the handle of the IPC_M_DATA_READ. 2760 * @param size Storage for the maximum size. Can be NULL. 2759 2761 * 2760 2762 * @return True on success, false on failure. 2761 2763 * 2762 2764 */ 2763 bool async_data_read_receive( ipc_callid_t *callid, size_t *size)2765 bool async_data_read_receive(cap_handle_t *chandle, size_t *size) 2764 2766 { 2765 2767 ipc_call_t data; 2766 return async_data_read_receive_call(c allid, &data, size);2768 return async_data_read_receive_call(chandle, &data, size); 2767 2769 } 2768 2770 … … 2775 2777 * So far, this wrapper is to be used from within a connection fibril. 2776 2778 * 2777 * @param c allid Storage for the hashof the IPC_M_DATA_READ.2778 * @param size Storage for the maximum size. Can be NULL.2779 * @param chandle Storage for the handle of the IPC_M_DATA_READ. 2780 * @param size Storage for the maximum size. Can be NULL. 2779 2781 * 2780 2782 * @return True on success, false on failure. 2781 2783 * 2782 2784 */ 2783 bool async_data_read_receive_call( ipc_callid_t *callid, ipc_call_t *data,2785 bool async_data_read_receive_call(cap_handle_t *chandle, ipc_call_t *data, 2784 2786 size_t *size) 2785 2787 { 2786 assert(c allid);2788 assert(chandle); 2787 2789 assert(data); 2788 2790 2789 *c allid= async_get_call(data);2791 *chandle = async_get_call(data); 2790 2792 2791 2793 if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ) … … 2804 2806 * argument. 2805 2807 * 2806 * @param c allid Hashof the IPC_M_DATA_READ call to answer.2807 * @param src Source address for the IPC_M_DATA_READ call.2808 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than2809 * the maximum size announced by the sender.2810 * 2811 * @return Zero on success or a value from @ref errno.h on failure.2812 * 2813 */ 2814 int async_data_read_finalize( ipc_callid_t callid, const void *src, size_t size)2815 { 2816 return ipc_answer_2(c allid, EOK, (sysarg_t) src, (sysarg_t) size);2808 * @param chandle Handle of the IPC_M_DATA_READ call to answer. 2809 * @param src Source address for the IPC_M_DATA_READ call. 2810 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 2811 * the maximum size announced by the sender. 2812 * 2813 * @return Zero on success or a value from @ref errno.h on failure. 2814 * 2815 */ 2816 int async_data_read_finalize(cap_handle_t chandle, const void *src, size_t size) 2817 { 2818 return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size); 2817 2819 } 2818 2820 … … 2827 2829 return ENOENT; 2828 2830 2829 ipc_callid_t callid;2830 if (!async_data_read_receive(&c allid, NULL)) {2831 ipc_answer_0(c allid, EINVAL);2831 cap_handle_t chandle; 2832 if (!async_data_read_receive(&chandle, NULL)) { 2833 ipc_answer_0(chandle, EINVAL); 2832 2834 return EINVAL; 2833 2835 } … … 2836 2838 dataptr); 2837 2839 if (msg == 0) { 2838 ipc_answer_0(c allid, EINVAL);2840 ipc_answer_0(chandle, EINVAL); 2839 2841 return EINVAL; 2840 2842 } 2841 2843 2842 int retval = ipc_forward_fast(c allid, exch->phone, 0, 0, 0,2844 int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0, 2843 2845 IPC_FF_ROUTE_FROM_ME); 2844 2846 if (retval != EOK) { 2845 2847 async_forget(msg); 2846 ipc_answer_0(c allid, retval);2848 ipc_answer_0(chandle, retval); 2847 2849 return retval; 2848 2850 } … … 2880 2882 * So far, this wrapper is to be used from within a connection fibril. 2881 2883 * 2882 * @param c allid Storage for the hashof the IPC_M_DATA_WRITE.2883 * @param size Storage for the suggested size. May be NULL.2884 * 2885 * @return True on success, false on failure.2886 * 2887 */ 2888 bool async_data_write_receive( ipc_callid_t *callid, size_t *size)2884 * @param chandle Storage for the handle of the IPC_M_DATA_WRITE. 2885 * @param size Storage for the suggested size. May be NULL. 2886 * 2887 * @return True on success, false on failure. 2888 * 2889 */ 2890 bool async_data_write_receive(cap_handle_t *chandle, size_t *size) 2889 2891 { 2890 2892 ipc_call_t data; 2891 return async_data_write_receive_call(c allid, &data, size);2893 return async_data_write_receive_call(chandle, &data, size); 2892 2894 } 2893 2895 … … 2900 2902 * So far, this wrapper is to be used from within a connection fibril. 2901 2903 * 2902 * @param c allid Storage for the hashof the IPC_M_DATA_WRITE.2903 * @param data Storage for the ipc call data.2904 * @param size Storage for the suggested size. May be NULL.2904 * @param chandle Storage for the handle of the IPC_M_DATA_WRITE. 2905 * @param data Storage for the ipc call data. 2906 * @param size Storage for the suggested size. May be NULL. 2905 2907 * 2906 2908 * @return True on success, false on failure. 2907 2909 * 2908 2910 */ 2909 bool async_data_write_receive_call( ipc_callid_t *callid, ipc_call_t *data,2911 bool async_data_write_receive_call(cap_handle_t *chandle, ipc_call_t *data, 2910 2912 size_t *size) 2911 2913 { 2912 assert(c allid);2914 assert(chandle); 2913 2915 assert(data); 2914 2916 2915 *c allid= async_get_call(data);2917 *chandle = async_get_call(data); 2916 2918 2917 2919 if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE) … … 2930 2932 * argument. 2931 2933 * 2932 * @param c allid Hashof the IPC_M_DATA_WRITE call to answer.2933 * @param dst Final destination address for the IPC_M_DATA_WRITE call.2934 * @param size Final size for the IPC_M_DATA_WRITE call.2935 * 2936 * @return Zero on success or a value from @ref errno.h on failure.2937 * 2938 */ 2939 int async_data_write_finalize( ipc_callid_t callid, void *dst, size_t size)2940 { 2941 return ipc_answer_2(c allid, EOK, (sysarg_t) dst, (sysarg_t) size);2934 * @param chandle Handle of the IPC_M_DATA_WRITE call to answer. 2935 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 2936 * @param size Final size for the IPC_M_DATA_WRITE call. 2937 * 2938 * @return Zero on success or a value from @ref errno.h on failure. 2939 * 2940 */ 2941 int async_data_write_finalize(cap_handle_t chandle, void *dst, size_t size) 2942 { 2943 return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size); 2942 2944 } 2943 2945 … … 2969 2971 assert(data); 2970 2972 2971 ipc_callid_t callid;2973 cap_handle_t chandle; 2972 2974 size_t size; 2973 if (!async_data_write_receive(&c allid, &size)) {2974 ipc_answer_0(c allid, EINVAL);2975 if (!async_data_write_receive(&chandle, &size)) { 2976 ipc_answer_0(chandle, EINVAL); 2975 2977 return EINVAL; 2976 2978 } 2977 2979 2978 2980 if (size < min_size) { 2979 ipc_answer_0(c allid, EINVAL);2981 ipc_answer_0(chandle, EINVAL); 2980 2982 return EINVAL; 2981 2983 } 2982 2984 2983 2985 if ((max_size > 0) && (size > max_size)) { 2984 ipc_answer_0(c allid, EINVAL);2986 ipc_answer_0(chandle, EINVAL); 2985 2987 return EINVAL; 2986 2988 } 2987 2989 2988 2990 if ((granularity > 0) && ((size % granularity) != 0)) { 2989 ipc_answer_0(c allid, EINVAL);2991 ipc_answer_0(chandle, EINVAL); 2990 2992 return EINVAL; 2991 2993 } … … 2999 3001 3000 3002 if (arg_data == NULL) { 3001 ipc_answer_0(c allid, ENOMEM);3003 ipc_answer_0(chandle, ENOMEM); 3002 3004 return ENOMEM; 3003 3005 } 3004 3006 3005 int rc = async_data_write_finalize(c allid, arg_data, size);3007 int rc = async_data_write_finalize(chandle, arg_data, size); 3006 3008 if (rc != EOK) { 3007 3009 free(arg_data); … … 3028 3030 void async_data_write_void(sysarg_t retval) 3029 3031 { 3030 ipc_callid_t callid;3031 async_data_write_receive(&c allid, NULL);3032 ipc_answer_0(c allid, retval);3032 cap_handle_t chandle; 3033 async_data_write_receive(&chandle, NULL); 3034 ipc_answer_0(chandle, retval); 3033 3035 } 3034 3036 … … 3043 3045 return ENOENT; 3044 3046 3045 ipc_callid_t callid;3046 if (!async_data_write_receive(&c allid, NULL)) {3047 ipc_answer_0(c allid, EINVAL);3047 cap_handle_t chandle; 3048 if (!async_data_write_receive(&chandle, NULL)) { 3049 ipc_answer_0(chandle, EINVAL); 3048 3050 return EINVAL; 3049 3051 } … … 3052 3054 dataptr); 3053 3055 if (msg == 0) { 3054 ipc_answer_0(c allid, EINVAL);3056 ipc_answer_0(chandle, EINVAL); 3055 3057 return EINVAL; 3056 3058 } 3057 3059 3058 int retval = ipc_forward_fast(c allid, exch->phone, 0, 0, 0,3060 int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0, 3059 3061 IPC_FF_ROUTE_FROM_ME); 3060 3062 if (retval != EOK) { 3061 3063 async_forget(msg); 3062 ipc_answer_0(c allid, retval);3064 ipc_answer_0(chandle, retval); 3063 3065 return retval; 3064 3066 } … … 3085 3087 /* Accept the phone */ 3086 3088 ipc_call_t call; 3087 ipc_callid_t callid = async_get_call(&call); 3088 int phone = (int) IPC_GET_ARG5(call); 3089 3090 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || 3091 (phone < 0)) { 3092 async_answer_0(callid, EINVAL); 3089 cap_handle_t chandle = async_get_call(&call); 3090 cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call); 3091 3092 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) { 3093 async_answer_0(chandle, EINVAL); 3093 3094 return NULL; 3094 3095 } … … 3096 3097 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t)); 3097 3098 if (sess == NULL) { 3098 async_answer_0(c allid, ENOMEM);3099 async_answer_0(chandle, ENOMEM); 3099 3100 return NULL; 3100 3101 } … … 3102 3103 sess->iface = 0; 3103 3104 sess->mgmt = mgmt; 3104 sess->phone = ph one;3105 sess->phone = phandle; 3105 3106 sess->arg1 = 0; 3106 3107 sess->arg2 = 0; … … 3115 3116 3116 3117 /* Acknowledge the connected phone */ 3117 async_answer_0(c allid, EOK);3118 async_answer_0(chandle, EOK); 3118 3119 3119 3120 return sess; … … 3136 3137 async_sess_t *async_callback_receive_start(exch_mgmt_t mgmt, ipc_call_t *call) 3137 3138 { 3138 int phone = (int) IPC_GET_ARG5(*call); 3139 3140 if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || 3141 (phone < 0)) 3139 cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call); 3140 3141 if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) 3142 3142 return NULL; 3143 3143 … … 3148 3148 sess->iface = 0; 3149 3149 sess->mgmt = mgmt; 3150 sess->phone = ph one;3150 sess->phone = phandle; 3151 3151 sess->arg1 = 0; 3152 3152 sess->arg2 = 0; … … 3170 3170 } 3171 3171 3172 bool async_state_change_receive( ipc_callid_t *callid, sysarg_t *arg1,3172 bool async_state_change_receive(cap_handle_t *chandle, sysarg_t *arg1, 3173 3173 sysarg_t *arg2, sysarg_t *arg3) 3174 3174 { 3175 assert(c allid);3175 assert(chandle); 3176 3176 3177 3177 ipc_call_t call; 3178 *c allid= async_get_call(&call);3178 *chandle = async_get_call(&call); 3179 3179 3180 3180 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) … … 3191 3191 } 3192 3192 3193 int async_state_change_finalize( ipc_callid_t callid, async_exch_t *other_exch)3194 { 3195 return ipc_answer_1(c allid, EOK, other_exch->phone);3193 int async_state_change_finalize(cap_handle_t chandle, async_exch_t *other_exch) 3194 { 3195 return ipc_answer_1(chandle, EOK, other_exch->phone); 3196 3196 } 3197 3197
Note:
See TracChangeset
for help on using the changeset viewer.