Changeset 371bd7d in mainline for uspace/lib/c/generic/async.c
- Timestamp:
- 2010-03-27T09:22:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36a75a2
- Parents:
- cd82bb1 (diff), eaf22d4 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rcd82bb1 r371bd7d 1101 1101 } 1102 1102 1103 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1104 * 1105 * Ask through phone for a new connection to some service. 1106 * 1107 * @param phoneid Phone handle used for contacting the other side. 1108 * @param arg1 User defined argument. 1109 * @param arg2 User defined argument. 1110 * @param arg3 User defined argument. 1111 * 1112 * @return New phone handle on success or a negative error code. 1113 */ 1114 int 1115 async_connect_me_to(int phoneid, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3) 1116 { 1117 int rc; 1118 ipcarg_t newphid; 1119 1120 rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL, 1121 NULL, NULL, NULL, &newphid); 1122 1123 if (rc != EOK) 1124 return rc; 1125 1126 return newphid; 1127 } 1128 1129 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1130 * 1131 * Ask through phone for a new connection to some service and block until 1132 * success. 1133 * 1134 * @param phoneid Phone handle used for contacting the other side. 1135 * @param arg1 User defined argument. 1136 * @param arg2 User defined argument. 1137 * @param arg3 User defined argument. 1138 * 1139 * @return New phone handle on success or a negative error code. 1140 */ 1141 int 1142 async_connect_me_to_blocking(int phoneid, ipcarg_t arg1, ipcarg_t arg2, 1143 ipcarg_t arg3) 1144 { 1145 int rc; 1146 ipcarg_t newphid; 1147 1148 rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1149 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid); 1150 1151 if (rc != EOK) 1152 return rc; 1153 1154 return newphid; 1155 } 1156 1103 1157 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework. 1104 1158 * … … 1287 1341 } 1288 1342 1343 /** Wrapper for forwarding any read request 1344 * 1345 * 1346 */ 1347 int async_data_read_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1348 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1349 { 1350 ipc_callid_t callid; 1351 if (!async_data_read_receive(&callid, NULL)) { 1352 ipc_answer_0(callid, EINVAL); 1353 return EINVAL; 1354 } 1355 1356 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4, 1357 dataptr); 1358 if (msg == 0) { 1359 ipc_answer_0(callid, EINVAL); 1360 return EINVAL; 1361 } 1362 1363 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0, 1364 IPC_FF_ROUTE_FROM_ME); 1365 if (retval != EOK) { 1366 async_wait_for(msg, NULL); 1367 ipc_answer_0(callid, retval); 1368 return retval; 1369 } 1370 1371 ipcarg_t rc; 1372 async_wait_for(msg, &rc); 1373 1374 return (int) rc; 1375 } 1376 1289 1377 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework. 1290 1378 * 1291 * @param phoneid Phone that will be used to contact the receiving side. 1292 * @param src Address of the beginning of the source buffer. 1293 * @param size Size of the source buffer. 1294 * 1295 * @return Zero on success or a negative error code from errno.h. 1379 * @param phoneid Phone that will be used to contact the receiving side. 1380 * @param src Address of the beginning of the source buffer. 1381 * @param size Size of the source buffer. 1382 * 1383 * @return Zero on success or a negative error code from errno.h. 1384 * 1296 1385 */ 1297 1386 int async_data_write_start(int phoneid, const void *src, size_t size) … … 1308 1397 * So far, this wrapper is to be used from within a connection fibril. 1309 1398 * 1310 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will 1311 * be stored. 1312 * @param size Storage where the suggested size will be stored. May be 1313 * NULL 1314 * 1315 * @return Non-zero on success, zero on failure. 1399 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will 1400 * be stored. 1401 * @param size Storage where the suggested size will be stored. May be 1402 * NULL 1403 * 1404 * @return Non-zero on success, zero on failure. 1405 * 1316 1406 */ 1317 1407 int async_data_write_receive(ipc_callid_t *callid, size_t *size) … … 1320 1410 1321 1411 assert(callid); 1322 1412 1323 1413 *callid = async_get_call(&data); 1324 1414 if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE) 1325 1415 return 0; 1416 1326 1417 if (size) 1327 1418 *size = (size_t) IPC_GET_ARG2(data); 1419 1328 1420 return 1; 1329 1421 } … … 1334 1426 * so that the user doesn't have to remember the meaning of each IPC argument. 1335 1427 * 1336 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1337 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 1338 * @param size Final size for the IPC_M_DATA_WRITE call. 1339 * 1340 * @return Zero on success or a value from @ref errno.h on failure. 1428 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1429 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 1430 * @param size Final size for the IPC_M_DATA_WRITE call. 1431 * 1432 * @return Zero on success or a value from @ref errno.h on failure. 1433 * 1341 1434 */ 1342 1435 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size) … … 1345 1438 } 1346 1439 1440 /** Wrapper for receiving binary data or strings 1441 * 1442 * This wrapper only makes it more comfortable to use async_data_write_* 1443 * functions to receive binary data or strings. 1444 * 1445 * @param data Pointer to data pointer (which should be later disposed 1446 * by free()). If the operation fails, the pointer is not 1447 * touched. 1448 * @param nullterm If true then the received data is always zero terminated. 1449 * This also causes to allocate one extra byte beyond the 1450 * raw transmitted data. 1451 * @param min_size Minimum size (in bytes) of the data to receive. 1452 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1453 * no limit. 1454 * @param granulariy If non-zero then the size of the received data has to 1455 * be divisible by this value. 1456 * @param received If not NULL, the size of the received data is stored here. 1457 * 1458 * @return Zero on success or a value from @ref errno.h on failure. 1459 * 1460 */ 1461 int async_data_write_accept(void **data, const bool nullterm, 1462 const size_t min_size, const size_t max_size, const size_t granularity, 1463 size_t *received) 1464 { 1465 ipc_callid_t callid; 1466 size_t size; 1467 if (!async_data_write_receive(&callid, &size)) { 1468 ipc_answer_0(callid, EINVAL); 1469 return EINVAL; 1470 } 1471 1472 if (size < min_size) { 1473 ipc_answer_0(callid, EINVAL); 1474 return EINVAL; 1475 } 1476 1477 if ((max_size > 0) && (size > max_size)) { 1478 ipc_answer_0(callid, EINVAL); 1479 return EINVAL; 1480 } 1481 1482 if ((granularity > 0) && ((size % granularity) != 0)) { 1483 ipc_answer_0(callid, EINVAL); 1484 return EINVAL; 1485 } 1486 1487 void *_data; 1488 1489 if (nullterm) 1490 _data = malloc(size + 1); 1491 else 1492 _data = malloc(size); 1493 1494 if (_data == NULL) { 1495 ipc_answer_0(callid, ENOMEM); 1496 return ENOMEM; 1497 } 1498 1499 int rc = async_data_write_finalize(callid, _data, size); 1500 if (rc != EOK) { 1501 free(_data); 1502 return rc; 1503 } 1504 1505 if (nullterm) 1506 ((char *) _data)[size] = 0; 1507 1508 *data = _data; 1509 if (received != NULL) 1510 *received = size; 1511 1512 return EOK; 1513 } 1514 1515 /** Wrapper for voiding any data that is about to be received 1516 * 1517 * This wrapper can be used to void any pending data 1518 * 1519 * @param retval Error value from @ref errno.h to be returned to the caller. 1520 * 1521 */ 1522 void async_data_write_void(const int retval) 1523 { 1524 ipc_callid_t callid; 1525 async_data_write_receive(&callid, NULL); 1526 ipc_answer_0(callid, retval); 1527 } 1528 1529 /** Wrapper for forwarding any data that is about to be received 1530 * 1531 * 1532 */ 1533 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1534 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1535 { 1536 ipc_callid_t callid; 1537 if (!async_data_write_receive(&callid, NULL)) { 1538 ipc_answer_0(callid, EINVAL); 1539 return EINVAL; 1540 } 1541 1542 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4, 1543 dataptr); 1544 if (msg == 0) { 1545 ipc_answer_0(callid, EINVAL); 1546 return EINVAL; 1547 } 1548 1549 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0, 1550 IPC_FF_ROUTE_FROM_ME); 1551 if (retval != EOK) { 1552 async_wait_for(msg, NULL); 1553 ipc_answer_0(callid, retval); 1554 return retval; 1555 } 1556 1557 ipcarg_t rc; 1558 async_wait_for(msg, &rc); 1559 1560 return (int) rc; 1561 } 1562 1347 1563 /** @} 1348 1564 */
Note:
See TracChangeset
for help on using the changeset viewer.