Changeset eda925a in mainline for uspace/lib/libc/generic/async.c
- Timestamp:
- 2010-02-04T15:46:51Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d32358f
- Parents:
- b4cbef1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
rb4cbef1 reda925a 1383 1383 } 1384 1384 1385 /** Wrapper for receiving binary data 1385 /** Wrapper for receiving binary data or strings 1386 1386 * 1387 1387 * This wrapper only makes it more comfortable to use async_data_write_* 1388 * functions to receive binary data .1388 * functions to receive binary data or strings. 1389 1389 * 1390 1390 * @param data Pointer to data pointer (which should be later disposed 1391 1391 * by free()). If the operation fails, the pointer is not 1392 1392 * touched. 1393 * @param nullterm If true then the received data is always zero terminated. 1394 * This also causes to allocate one extra byte beyond the 1395 * raw transmitted data. 1393 1396 * @param min_size Minimum size (in bytes) of the data to receive. 1394 1397 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1395 1398 * no limit. 1396 * @param granulariy If non-zero ,then the size of the received data has to1399 * @param granulariy If non-zero then the size of the received data has to 1397 1400 * be divisible by this value. 1398 1401 * @param received If not NULL, the size of the received data is stored here. … … 1401 1404 * 1402 1405 */ 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) 1406 int async_data_write_accept(void **data, const bool nullterm, 1407 const size_t min_size, const size_t max_size, const size_t granularity, 1408 size_t *received) 1405 1409 { 1406 1410 ipc_callid_t callid; … … 1426 1430 } 1427 1431 1428 void *_data = malloc(size); 1432 void *_data; 1433 1434 if (nullterm) 1435 _data = malloc(size + 1); 1436 else 1437 _data = malloc(size); 1438 1429 1439 if (_data == NULL) { 1430 1440 ipc_answer_0(callid, ENOMEM); … … 1438 1448 } 1439 1449 1450 if (nullterm) 1451 ((char *) _data)[size] = 0; 1452 1440 1453 *data = _data; 1441 1454 if (received != NULL) … … 1445 1458 } 1446 1459 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 1460 /** Wrapper for voiding any data that is about to be received 1497 1461 * … … 1501 1465 * 1502 1466 */ 1503 void async_data_ void(const int retval)1467 void async_data_write_void(const int retval) 1504 1468 { 1505 1469 ipc_callid_t callid; … … 1512 1476 * 1513 1477 */ 1514 int async_data_ forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,1478 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1515 1479 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1516 1480 {
Note:
See TracChangeset
for help on using the changeset viewer.