mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 15:33:39 +02:00
GUnixInput/OutputStream: fix blocking methods to always block
Previously, if you created a GUnixInputStream or GUnixOutputStream from a non-blocking file descriptor, it might sometimes return G_IO_ERROR_WOULD_BLOCK from g_input_stream_read/g_output_stream_write, which is wrong. Fix that. (Use the GPollableInput/OutputStream methods if you want non-blocking I/O.) Also, add a test for this to gio/tests/unix-streams. Also, fix the GError messages to say "Error reading from file descriptor", etc instead of "Error reading from unix" (which was presumably from a bad search and replace job). https://bugzilla.gnome.org/show_bug.cgi?id=626866
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixinputstream.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
#include <glib/glib-unix.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -194,7 +195,7 @@ timeout (gpointer cancellable)
|
||||
}
|
||||
|
||||
static void
|
||||
test_pipe_io (void)
|
||||
test_pipe_io (gconstpointer nonblocking)
|
||||
{
|
||||
GThread *writer, *reader;
|
||||
GInputStream *in;
|
||||
@@ -212,6 +213,20 @@ test_pipe_io (void)
|
||||
|
||||
g_assert (pipe (writer_pipe) == 0 && pipe (reader_pipe) == 0);
|
||||
|
||||
if (nonblocking)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_unix_set_fd_nonblocking (writer_pipe[0], TRUE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_unix_set_fd_nonblocking (writer_pipe[1], TRUE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_unix_set_fd_nonblocking (reader_pipe[0], TRUE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_unix_set_fd_nonblocking (reader_pipe[1], TRUE, &error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
writer_cancel = g_cancellable_new ();
|
||||
reader_cancel = g_cancellable_new ();
|
||||
main_cancel = g_cancellable_new ();
|
||||
@@ -249,7 +264,12 @@ main (int argc,
|
||||
g_type_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/unix-streams/pipe-io-test", test_pipe_io);
|
||||
g_test_add_data_func ("/unix-streams/pipe-io-test",
|
||||
GINT_TO_POINTER (FALSE),
|
||||
test_pipe_io);
|
||||
g_test_add_data_func ("/unix-streams/nonblocking-io-test",
|
||||
GINT_TO_POINTER (TRUE),
|
||||
test_pipe_io);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user