Changeset eda925a in mainline for uspace/lib
- 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
- Location:
- uspace/lib
- Files:
-
- 3 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 { -
uspace/lib/libc/include/async.h
rb4cbef1 reda925a 310 310 extern int async_data_read_receive(ipc_callid_t *, size_t *); 311 311 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t); 312 312 313 extern int async_data_read_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, 313 314 ipcarg_t, ipcarg_t, ipc_call_t *); 314 315 315 316 /* 316 * User-friendly wrappers for async_data_forward_fast(). 317 */ 318 #define async_data_forward_0_0(phoneid, method, answer) \ 319 async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) 320 #define async_data_forward_0_1(phoneid, method, answer) \ 321 async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer)) 322 #define async_data_forward_1_0(phoneid, method, arg1, answer) \ 323 async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL) 324 #define async_data_forward_1_1(phoneid, method, arg1, answer) \ 325 async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, (answer)) 326 #define async_data_forward_2_0(phoneid, method, arg1, arg2, answer) \ 327 async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, NULL) 328 #define async_data_forward_2_1(phoneid, method, arg1, arg2, answer) \ 329 async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 317 * User-friendly wrappers for async_data_write_forward_fast(). 318 */ 319 #define async_data_write_forward_0_0(phoneid, method, answer) \ 320 async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) 321 #define async_data_write_forward_0_1(phoneid, method, answer) \ 322 async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer)) 323 #define async_data_write_forward_1_0(phoneid, method, arg1, answer) \ 324 async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL) 325 #define async_data_write_forward_1_1(phoneid, method, arg1, answer) \ 326 async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, \ 330 327 (answer)) 331 #define async_data_ forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \332 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \333 NULL) 334 #define async_data_ forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \335 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \328 #define async_data_write_forward_2_0(phoneid, method, arg1, arg2, answer) \ 329 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 330 NULL) 331 #define async_data_write_forward_2_1(phoneid, method, arg1, arg2, answer) \ 332 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 336 333 (answer)) 337 #define async_data_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 338 async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 334 #define async_data_write_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \ 335 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 336 0, NULL) 337 #define async_data_write_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \ 338 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 339 0, (answer)) 340 #define async_data_write_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 341 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 339 342 (arg4), NULL) 340 #define async_data_ forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \341 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \343 #define async_data_write_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 344 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 342 345 (arg4), (answer)) 343 346 … … 345 348 extern int async_data_write_receive(ipc_callid_t *, size_t *); 346 349 extern int async_data_write_finalize(ipc_callid_t, void *, size_t); 347 extern int async_data_receive(void **, const size_t, const size_t, 348 const size_t, size_t *); 349 extern int async_string_receive(char **, const size_t, size_t *); 350 extern void async_data_void(const int); 351 extern int async_data_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t, 352 ipcarg_t, ipc_call_t *); 350 351 extern int async_data_write_accept(void **, const bool, const size_t, 352 const size_t, const size_t, size_t *); 353 extern void async_data_write_void(const int); 354 355 extern int async_data_write_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, 356 ipcarg_t, ipcarg_t, ipc_call_t *); 353 357 354 358 #endif -
uspace/lib/libfs/libfs.c
rb4cbef1 reda925a 176 176 if ((res != EOK) || (!fn)) { 177 177 ipc_hangup(mountee_phone); 178 async_data_ void(combine_rc(res, ENOENT));178 async_data_write_void(combine_rc(res, ENOENT)); 179 179 ipc_answer_0(rid, combine_rc(res, ENOENT)); 180 180 return; … … 184 184 ipc_hangup(mountee_phone); 185 185 (void) ops->node_put(fn); 186 async_data_ void(EBUSY);186 async_data_write_void(EBUSY); 187 187 ipc_answer_0(rid, EBUSY); 188 188 return; … … 193 193 ipc_hangup(mountee_phone); 194 194 (void) ops->node_put(fn); 195 async_data_ void(rc);195 async_data_write_void(rc); 196 196 ipc_answer_0(rid, rc); 197 197 return; … … 199 199 200 200 ipc_call_t answer; 201 rc = async_data_ forward_1_1(mountee_phone, VFS_OUT_MOUNTED, mr_dev_handle,202 &answer);201 rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED, 202 mr_dev_handle, &answer); 203 203 204 204 if (rc == EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.