aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index cdead59d2..6560726ea 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1451,33 +1451,23 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1451/** 1451/**
1452 * Creates an interprocess channel 1452 * Creates an interprocess channel
1453 * 1453 *
1454 * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO 1454 * @param pf how to configure the pipe
1455 * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO
1456 * @param inherit_read inherit the parent processes stdin (only for windows)
1457 * @param inherit_write inherit the parent processes stdout (only for windows)
1458 * @return handle to the new pipe, NULL on error 1455 * @return handle to the new pipe, NULL on error
1459 */ 1456 */
1460struct GNUNET_DISK_PipeHandle * 1457struct GNUNET_DISK_PipeHandle *
1461GNUNET_DISK_pipe (int blocking_read, 1458GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf)
1462 int blocking_write,
1463 int inherit_read,
1464 int inherit_write)
1465{ 1459{
1466 int fd[2]; 1460 int fd[2];
1467 int ret;
1468 int eno;
1469 1461
1470 (void) inherit_read; 1462 if (-1 == pipe (fd))
1471 (void) inherit_write;
1472 ret = pipe (fd);
1473 if (ret == -1)
1474 { 1463 {
1475 eno = errno; 1464 int eno = errno;
1465
1476 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 1466 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1477 errno = eno; 1467 errno = eno;
1478 return NULL; 1468 return NULL;
1479 } 1469 }
1480 return GNUNET_DISK_pipe_from_fd (blocking_read, blocking_write, fd); 1470 return GNUNET_DISK_pipe_from_fd (pf, fd);
1481} 1471}
1482 1472
1483 1473
@@ -1485,29 +1475,26 @@ GNUNET_DISK_pipe (int blocking_read,
1485 * Creates a pipe object from a couple of file descriptors. 1475 * Creates a pipe object from a couple of file descriptors.
1486 * Useful for wrapping existing pipe FDs. 1476 * Useful for wrapping existing pipe FDs.
1487 * 1477 *
1488 * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO 1478 * @param pf how to configure the pipe
1489 * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO
1490 * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes 1479 * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes
1491 * 1480 *
1492 * @return handle to the new pipe, NULL on error 1481 * @return handle to the new pipe, NULL on error
1493 */ 1482 */
1494struct GNUNET_DISK_PipeHandle * 1483struct GNUNET_DISK_PipeHandle *
1495GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]) 1484GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf,
1485 int fd[2])
1496{ 1486{
1497 struct GNUNET_DISK_PipeHandle *p; 1487 struct GNUNET_DISK_PipeHandle *p;
1498 1488 int ret = 0;
1499 p = GNUNET_new (struct GNUNET_DISK_PipeHandle);
1500
1501 int ret;
1502 int flags; 1489 int flags;
1503 int eno = 0; /* make gcc happy */ 1490 int eno = 0; /* make gcc happy */
1504 1491
1505 ret = 0; 1492 p = GNUNET_new (struct GNUNET_DISK_PipeHandle);
1506 if (fd[0] >= 0) 1493 if (fd[0] >= 0)
1507 { 1494 {
1508 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle); 1495 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1509 p->fd[0]->fd = fd[0]; 1496 p->fd[0]->fd = fd[0];
1510 if (! blocking_read) 1497 if (0 == (GNUNET_DISK_PF_BLOCKING_READ & pf))
1511 { 1498 {
1512 flags = fcntl (fd[0], F_GETFL); 1499 flags = fcntl (fd[0], F_GETFL);
1513 flags |= O_NONBLOCK; 1500 flags |= O_NONBLOCK;
@@ -1530,7 +1517,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
1530 { 1517 {
1531 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle); 1518 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1532 p->fd[1]->fd = fd[1]; 1519 p->fd[1]->fd = fd[1];
1533 if (! blocking_write) 1520 if (0 == (GNUNET_DISK_PF_BLOCKING_WRITE & pf))
1534 { 1521 {
1535 flags = fcntl (fd[1], F_GETFL); 1522 flags = fcntl (fd[1], F_GETFL);
1536 flags |= O_NONBLOCK; 1523 flags |= O_NONBLOCK;
@@ -1562,7 +1549,6 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
1562 errno = eno; 1549 errno = eno;
1563 return NULL; 1550 return NULL;
1564 } 1551 }
1565
1566 return p; 1552 return p;
1567} 1553}
1568 1554
@@ -1572,7 +1558,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
1572 * 1558 *
1573 * @param p pipe to close 1559 * @param p pipe to close
1574 * @param end which end of the pipe to close 1560 * @param end which end of the pipe to close
1575 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 1561 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1576 */ 1562 */
1577int 1563int
1578GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, 1564GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
@@ -1644,7 +1630,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
1644 * Closes an interprocess channel 1630 * Closes an interprocess channel
1645 * 1631 *
1646 * @param p pipe to close 1632 * @param p pipe to close
1647 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 1633 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1648 */ 1634 */
1649int 1635int
1650GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) 1636GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)