[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19146 - in gnunet/src: arm fs include nat testing transpor
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19146 - in gnunet/src: arm fs include nat testing transport util |
Date: |
Sun, 15 Jan 2012 00:18:06 +0100 |
Author: grothoff
Date: 2012-01-15 00:18:06 +0100 (Sun, 15 Jan 2012)
New Revision: 19146
Modified:
gnunet/src/arm/gnunet-service-arm.c
gnunet/src/fs/fs_dirmetascan.c
gnunet/src/include/gnunet_disk_lib.h
gnunet/src/nat/nat.c
gnunet/src/nat/nat_mini.c
gnunet/src/testing/testing.c
gnunet/src/transport/plugin_transport_wlan.c
gnunet/src/util/disk.c
gnunet/src/util/helper.c
gnunet/src/util/os_priority.c
gnunet/src/util/scheduler.c
gnunet/src/util/test_common_logging_runtime_loglevels.c
gnunet/src/util/test_os_start_process.c
gnunet/src/util/test_scheduler.c
Log:
LRN: enable more fine-grained control over blocking/non-blocking pipe operation
Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/arm/gnunet-service-arm.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -1174,7 +1174,7 @@
int ret;
struct GNUNET_SIGNAL_Context *shc_chld;
- sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+ sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (sigpipe != NULL);
shc_chld =
GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
Modified: gnunet/src/fs/fs_dirmetascan.c
===================================================================
--- gnunet/src/fs/fs_dirmetascan.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/fs/fs_dirmetascan.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -1047,7 +1047,7 @@
if (filename_expanded == NULL)
return NULL;
- progress_pipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+ progress_pipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO,
GNUNET_NO);
if (progress_pipe == NULL)
{
GNUNET_free (filename_expanded);
Modified: gnunet/src/include/gnunet_disk_lib.h
===================================================================
--- gnunet/src/include/gnunet_disk_lib.h 2012-01-14 23:16:53 UTC (rev
19145)
+++ gnunet/src/include/gnunet_disk_lib.h 2012-01-14 23:18:06 UTC (rev
19146)
@@ -395,7 +395,7 @@
* @return handle to the new pipe, NULL on error
*/
struct GNUNET_DISK_PipeHandle *
-GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write);
+GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int
inherit_write);
/**
@@ -408,7 +408,7 @@
* @return handle to the new pipe, NULL on error
*/
struct GNUNET_DISK_PipeHandle *
-GNUNET_DISK_pipe_from_fd (int blocking, int fd[2]);
+GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]);
/**
* Closes an interprocess channel
@@ -461,6 +461,19 @@
GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result,
size_t len);
+/**
+ * Read the contents of a binary file into a buffer.
+ * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
+ * when no data can be read).
+ *
+ * @param h handle to an open file
+ * @param result the buffer to write the result to
+ * @param len the maximum number of bytes to read
+ * @return the number of bytes read on success, GNUNET_SYSERR on failure
+ */
+ssize_t
+GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
+ void *result, size_t len);
/**
* Read the contents of a binary file into a buffer.
@@ -488,6 +501,17 @@
/**
+ * Write a buffer to a file, blocking, if necessary.
+ * @param h handle to open file
+ * @param buffer the data to write
+ * @param n number of bytes to write
+ * @return number of bytes written on success, GNUNET_SYSERR on error
+ */
+ssize_t
+GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
+ const void *buffer, size_t n);
+
+/**
* Write a buffer to a file. If the file is longer than
* the given buffer size, it will be truncated.
*
Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/nat/nat.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -835,7 +835,7 @@
(h->internal_address != NULL) &&
(NULL !=
(h->server_stdout =
- GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES))))
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES))))
{
#if DEBUG_NAT
LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s' at `%s'\n",
Modified: gnunet/src/nat/nat_mini.c
===================================================================
--- gnunet/src/nat/nat_mini.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/nat/nat_mini.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -169,7 +169,7 @@
eh = GNUNET_malloc (sizeof (struct GNUNET_NAT_ExternalHandle));
eh->cb = cb;
eh->cb_cls = cb_cls;
- eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == eh->opipe)
{
GNUNET_free (eh);
Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/testing/testing.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -239,7 +239,7 @@
/* Start create hostkey process if we don't already know the peer
identity! */
if (GNUNET_NO == d->have_hostkey)
{
- d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
+ d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO,
GNUNET_YES);
if (d->pipe_stdout == NULL)
{
cb = d->cb;
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2012-01-14 23:16:53 UTC
(rev 19145)
+++ gnunet/src/transport/plugin_transport_wlan.c 2012-01-14 23:18:06 UTC
(rev 19146)
@@ -1441,11 +1441,11 @@
return GNUNET_YES;
}
- plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO,
GNUNET_YES);
if (plugin->server_stdout == NULL)
return GNUNET_SYSERR;
- plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES,
GNUNET_NO);
if (plugin->server_stdin == NULL)
return GNUNET_SYSERR;
Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/util/disk.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -746,7 +746,75 @@
#endif
}
+/**
+ * Read the contents of a binary file into a buffer.
+ * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
+ * when no data can be read).
+ *
+ * @param h handle to an open file
+ * @param result the buffer to write the result to
+ * @param len the maximum number of bytes to read
+ * @return the number of bytes read on success, GNUNET_SYSERR on failure
+ */
+ssize_t
+GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
+ void *result, size_t len)
+{
+ if (h == NULL)
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
+#ifdef MINGW
+ DWORD bytesRead;
+
+ if (h->type != GNUNET_PIPE)
+ {
+ if (!ReadFile (h->h, result, len, &bytesRead, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
+ }
+ else
+ {
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe, trying to read\n");
+#endif
+ if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead))
+ {
+ if (GetLastError () != ERROR_IO_PENDING)
+ {
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n",
GetLastError ());
+#endif
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
+ else
+ {
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "ReadFile() queued a read, cancelling\n");
+#endif
+ CancelIo (h->h);
+ errno = EAGAIN;
+ return GNUNET_SYSERR;
+ }
+ }
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead);
+#endif
+ }
+ return bytesRead;
+#else
+ /* FIXME: set to non-blocking (fcntl?), read, then set back? */
+ return read (h->fd, result, len);
+#endif
+}
+
+
/**
* Read the contents of a binary file into a buffer.
*
@@ -871,6 +939,64 @@
}
/**
+ * Write a buffer to a file, blocking, if necessary.
+ * @param h handle to open file
+ * @param buffer the data to write
+ * @param n number of bytes to write
+ * @return number of bytes written on success, GNUNET_SYSERR on error
+ */
+ssize_t
+GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
+ const void *buffer, size_t n)
+{
+ if (h == NULL)
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
+
+#ifdef MINGW
+ DWORD bytesWritten;
+ /* We do a non-overlapped write, which is as blocking as it gets */
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
+#endif
+ if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
+ GetLastError ());
+#endif
+ return GNUNET_SYSERR;
+ }
+ if (bytesWritten == 0 && n > 0)
+ {
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
+#endif
+ WaitForSingleObject (h->h, INFINITE);
+ if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
+ GetLastError ());
+#endif
+ return GNUNET_SYSERR;
+ }
+ }
+#if DEBUG_PIPE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten);
+#endif
+ return bytesWritten;
+#else
+ /* FIXME: switch to blocking mode (fcntl?), write, then switch back? */
+ return write (h->fd, buffer, n);
+#endif
+}
+
+/**
* Write a buffer to a file. If the file is longer than the
* number of bytes that will be written, it will be truncated.
*
@@ -1971,7 +2097,7 @@
* @return handle to the new pipe, NULL on error
*/
struct GNUNET_DISK_PipeHandle *
-GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
+GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int
inherit_write)
{
struct GNUNET_DISK_PipeHandle *p;
struct GNUNET_DISK_FileHandle *fds;
@@ -2000,7 +2126,7 @@
p->fd[1]->fd = fd[1];
ret = 0;
flags = fcntl (fd[0], F_GETFL);
- if (!blocking)
+ if (!blocking_read)
flags |= O_NONBLOCK;
if (0 > fcntl (fd[0], F_SETFL, flags))
ret = -1;
@@ -2010,7 +2136,7 @@
ret = -1;
flags = fcntl (fd[1], F_GETFL);
- if (!blocking)
+ if (!blocking_write)
flags |= O_NONBLOCK;
if (0 > fcntl (fd[1], F_SETFL, flags))
ret = -1;
@@ -2034,7 +2160,8 @@
ret =
create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
- FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED);
+ blocking_read ? 0 : FILE_FLAG_OVERLAPPED,
+ blocking_write ? 0 : FILE_FLAG_OVERLAPPED);
if (!ret)
{
GNUNET_free (p);
@@ -2066,15 +2193,7 @@
}
CloseHandle (p->fd[1]->h);
p->fd[1]->h = tmp_handle;
- if (!blocking)
- {
- DWORD mode;
- mode = PIPE_NOWAIT;
- SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
- SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
- /* this always fails on Windows 95, so we don't care about error handling
*/
- }
p->fd[0]->type = GNUNET_PIPE;
p->fd[1]->type = GNUNET_PIPE;
@@ -2103,7 +2222,7 @@
* @return handle to the new pipe, NULL on error
*/
struct GNUNET_DISK_PipeHandle *
-GNUNET_DISK_pipe_from_fd (int blocking, int fd[2])
+GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
{
struct GNUNET_DISK_PipeHandle *p;
struct GNUNET_DISK_FileHandle *fds;
@@ -2124,7 +2243,7 @@
if (fd[0] >= 0)
{
flags = fcntl (fd[0], F_GETFL);
- if (!blocking)
+ if (!blocking_read)
flags |= O_NONBLOCK;
if (0 > fcntl (fd[0], F_SETFL, flags))
ret = -1;
@@ -2137,7 +2256,7 @@
if (fd[1] >= 0)
{
flags = fcntl (fd[1], F_GETFL);
- if (!blocking)
+ if (!blocking_write)
flags |= O_NONBLOCK;
if (0 > fcntl (fd[1], F_SETFL, flags))
ret = -1;
@@ -2170,18 +2289,6 @@
else
p->fd[1]->h = INVALID_HANDLE_VALUE;
- if (!blocking)
- {
- DWORD mode;
-
- mode = PIPE_NOWAIT;
- if (p->fd[0]->h != INVALID_HANDLE_VALUE)
- SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
- if (p->fd[1]->h != INVALID_HANDLE_VALUE)
- SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
- /* this always fails on Windows 95, so we don't care about error handling
*/
- }
-
if (p->fd[0]->h != INVALID_HANDLE_VALUE)
{
p->fd[0]->type = GNUNET_PIPE;
Modified: gnunet/src/util/helper.c
===================================================================
--- gnunet/src/util/helper.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/util/helper.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -286,8 +286,8 @@
static void
start_helper (struct GNUNET_HELPER_Handle *h)
{
- h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
- h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES,
GNUNET_NO);
+ h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO,
GNUNET_YES);
if ( (h->helper_in == NULL) || (h->helper_out == NULL))
{
/* out of file descriptors? try again later... */
Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/util/os_priority.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -1135,7 +1135,7 @@
}
if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
{
- lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES,
GNUNET_NO);
if (lsocks_pipe == NULL)
{
@@ -1582,7 +1582,7 @@
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
Modified: gnunet/src/util/scheduler.c
===================================================================
--- gnunet/src/util/scheduler.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/util/scheduler.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -803,7 +803,7 @@
rs = GNUNET_NETWORK_fdset_create ();
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_assert (shutdown_pipe_handle == NULL);
- shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+ shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO,
GNUNET_NO);
GNUNET_assert (shutdown_pipe_handle != NULL);
pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
GNUNET_DISK_PIPE_END_READ);
Modified: gnunet/src/util/test_common_logging_runtime_loglevels.c
===================================================================
--- gnunet/src/util/test_common_logging_runtime_loglevels.c 2012-01-14
23:16:53 UTC (rev 19145)
+++ gnunet/src/util/test_common_logging_runtime_loglevels.c 2012-01-14
23:18:06 UTC (rev 19146)
@@ -268,7 +268,7 @@
{
const struct GNUNET_DISK_FileHandle *stdout_read_handle;
- pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO,
GNUNET_YES);
if (pipe_stdout == NULL)
{
Modified: gnunet/src/util/test_os_start_process.c
===================================================================
--- gnunet/src/util/test_os_start_process.c 2012-01-14 23:16:53 UTC (rev
19145)
+++ gnunet/src/util/test_os_start_process.c 2012-01-14 23:18:06 UTC (rev
19146)
@@ -114,8 +114,8 @@
GNUNET_asprintf (&fn, "cat");
- hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
- hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES,
GNUNET_NO);
+ hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO,
GNUNET_YES);
if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
{
Modified: gnunet/src/util/test_scheduler.c
===================================================================
--- gnunet/src/util/test_scheduler.c 2012-01-14 23:16:53 UTC (rev 19145)
+++ gnunet/src/util/test_scheduler.c 2012-01-14 23:18:06 UTC (rev 19146)
@@ -119,7 +119,7 @@
GNUNET_assert (5 == *ok);
(*ok) = 6;
- p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+ p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (NULL != p);
fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19146 - in gnunet/src: arm fs include nat testing transport util,
gnunet <=