* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <gio/gio.h>
+#include <glib/gstdio.h>
#ifdef G_OS_UNIX
+#include <fcntl.h>
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
#endif
g_assert_cmpstr (buf, ==, "x");
*success = TRUE;
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean
readable = g_pollable_input_stream_is_readable (in);
g_assert_cmpint (readable, ==, expected);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean
nwrote = g_output_stream_write (out, buf, 2, NULL, &error);
g_assert_no_error (error);
g_assert_cmpint (nwrote, ==, 2);
+/* Give the pipe a few ticks to propagate the write for sockets. On my
+ * iMac i7, 40 works, 30 doesn't. */
+ g_usleep (80L);
check_source_readability_callback (GINT_TO_POINTER (TRUE));
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean
{
check_source_readability_callback (user_data);
g_main_loop_quit (loop);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static void
GSource *poll_source;
gboolean success = FALSE;
+ g_assert (g_pollable_input_stream_can_poll (in));
+ g_assert (g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (out)));
+
readable = g_pollable_input_stream_is_readable (in);
g_assert (!readable);
static void
test_pollable_unix (void)
{
- int pipefds[2], status;
+ int pipefds[2], status, fd;
status = pipe (pipefds);
g_assert_cmpint (status, ==, 0);
g_object_unref (in);
g_object_unref (out);
+
+ /* Non-pipe/socket unix streams are not pollable */
+ fd = g_open ("/dev/null", O_RDWR, 0);
+ g_assert_cmpint (fd, !=, -1);
+ in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (fd, FALSE));
+ out = g_unix_output_stream_new (fd, FALSE);
+
+ g_assert (!g_pollable_input_stream_can_poll (in));
+ g_assert (!g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (out)));
+
+ g_object_unref (in);
+ g_object_unref (out);
+ close (fd);
}
+
+static void
+test_pollable_converter (void)
+{
+ GConverter *converter;
+ GError *error = NULL;
+ GInputStream *ibase;
+ int pipefds[2], status;
+
+ status = pipe (pipefds);
+ g_assert_cmpint (status, ==, 0);
+
+ ibase = G_INPUT_STREAM (g_unix_input_stream_new (pipefds[0], TRUE));
+ converter = G_CONVERTER (g_charset_converter_new ("UTF-8", "UTF-8", &error));
+ g_assert_no_error (error);
+
+ in = G_POLLABLE_INPUT_STREAM (g_converter_input_stream_new (ibase, converter));
+ g_object_unref (converter);
+ g_object_unref (ibase);
+
+ out = g_unix_output_stream_new (pipefds[1], TRUE);
+
+ test_streams ();
+
+ g_object_unref (in);
+ g_object_unref (out);
+}
+
#endif
static void
g_object_unref (server_conn);
g_object_unref (client);
g_object_unref (listener);
+ g_object_unref (effective_address);
}
int
main (int argc,
char *argv[])
{
- g_type_init ();
g_test_init (&argc, &argv, NULL);
#ifdef G_OS_UNIX
g_test_add_func ("/pollable/unix", test_pollable_unix);
+ g_test_add_func ("/pollable/converter", test_pollable_converter);
#endif
g_test_add_func ("/pollable/socket", test_pollable_socket);