Changeset c47e1a8 in mainline for uspace/lib/c/generic/async.c
- Timestamp:
- 2010-05-21T07:50:04Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d51ee2b
- Parents:
- cf8cc36 (diff), 15b592b (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
-
uspace/lib/c/generic/async.c (moved) (moved from uspace/lib/libc/generic/async.c ) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rcf8cc36 rc47e1a8 746 746 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, 747 747 &conn_hash_table_ops)) { 748 printf("%s: cannot create hash table\n", "async");748 printf("%s: Cannot create async hash table\n", "libc"); 749 749 return ENOMEM; 750 750 } … … 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 * … … 1310 1364 IPC_FF_ROUTE_FROM_ME); 1311 1365 if (retval != EOK) { 1366 async_wait_for(msg, NULL); 1312 1367 ipc_answer_0(callid, retval); 1313 1368 return retval; … … 1383 1438 } 1384 1439 1385 /** Wrapper for receiving binary data 1440 /** Wrapper for receiving binary data or strings 1386 1441 * 1387 1442 * This wrapper only makes it more comfortable to use async_data_write_* 1388 * functions to receive binary data .1443 * functions to receive binary data or strings. 1389 1444 * 1390 1445 * @param data Pointer to data pointer (which should be later disposed 1391 1446 * by free()). If the operation fails, the pointer is not 1392 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. 1393 1451 * @param min_size Minimum size (in bytes) of the data to receive. 1394 1452 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1395 1453 * no limit. 1396 * @param granulariy If non-zero ,then the size of the received data has to1454 * @param granulariy If non-zero then the size of the received data has to 1397 1455 * be divisible by this value. 1398 1456 * @param received If not NULL, the size of the received data is stored here. … … 1401 1459 * 1402 1460 */ 1403 int async_data_receive(void **data, const size_t min_size, 1404 const size_t max_size, const size_t granularity, size_t *received) 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) 1405 1464 { 1406 1465 ipc_callid_t callid; … … 1426 1485 } 1427 1486 1428 void *_data = malloc(size); 1487 void *_data; 1488 1489 if (nullterm) 1490 _data = malloc(size + 1); 1491 else 1492 _data = malloc(size); 1493 1429 1494 if (_data == NULL) { 1430 1495 ipc_answer_0(callid, ENOMEM); … … 1438 1503 } 1439 1504 1505 if (nullterm) 1506 ((char *) _data)[size] = 0; 1507 1440 1508 *data = _data; 1441 1509 if (received != NULL) … … 1445 1513 } 1446 1514 1447 /** Wrapper for receiving strings1448 *1449 * This wrapper only makes it more comfortable to use async_data_write_*1450 * functions to receive strings.1451 *1452 * @param str Pointer to string pointer (which should be later disposed1453 * by free()). If the operation fails, the pointer is not1454 * touched.1455 * @param max_size Maximum size (in bytes) of the string to receive. 0 means1456 * no limit.1457 * @param received If not NULL, the size of the received data is stored here.1458 *1459 * @return Zero on success or a value from @ref errno.h on failure.1460 *1461 */1462 int async_string_receive(char **str, const size_t max_size, size_t *received)1463 {1464 ipc_callid_t callid;1465 size_t size;1466 if (!async_data_write_receive(&callid, &size)) {1467 ipc_answer_0(callid, EINVAL);1468 return EINVAL;1469 }1470 1471 if ((max_size > 0) && (size > max_size)) {1472 ipc_answer_0(callid, EINVAL);1473 return EINVAL;1474 }1475 1476 char *data = (char *) malloc(size + 1);1477 if (data == NULL) {1478 ipc_answer_0(callid, ENOMEM);1479 return ENOMEM;1480 }1481 1482 int rc = async_data_write_finalize(callid, data, size);1483 if (rc != EOK) {1484 free(data);1485 return rc;1486 }1487 1488 data[size] = 0;1489 *str = data;1490 if (received != NULL)1491 *received = size;1492 1493 return EOK;1494 }1495 1496 1515 /** Wrapper for voiding any data that is about to be received 1497 1516 * … … 1501 1520 * 1502 1521 */ 1503 void async_data_ void(const int retval)1522 void async_data_write_void(const int retval) 1504 1523 { 1505 1524 ipc_callid_t callid; … … 1512 1531 * 1513 1532 */ 1514 int async_data_ forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,1533 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1515 1534 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1516 1535 { … … 1531 1550 IPC_FF_ROUTE_FROM_ME); 1532 1551 if (retval != EOK) { 1552 async_wait_for(msg, NULL); 1533 1553 ipc_answer_0(callid, retval); 1534 1554 return retval;
Note:
See TracChangeset
for help on using the changeset viewer.
