static void
test_io_stream_properties (NiceAddress *addr)
{
  NiceAgent *agent;
  guint stream_id;
  GIOStream *io_stream;
  GInputStream *input_stream;
  GOutputStream *output_stream;

  agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
  nice_agent_add_local_address (agent, addr);

  stream_id = nice_agent_add_stream (agent, 1);

  /* Try building an I/O stream around it. */
  io_stream = nice_agent_get_io_stream (agent, stream_id, 1);
  g_assert (G_IS_IO_STREAM (io_stream));
  g_assert (NICE_IS_IO_STREAM (io_stream));

  /* Check various initial properties. */
  g_assert (!g_io_stream_is_closed (G_IO_STREAM (io_stream)));
  g_assert (!g_io_stream_has_pending (G_IO_STREAM (io_stream)));

  /* Check the input stream’s properties. */
  input_stream = g_io_stream_get_input_stream (G_IO_STREAM (io_stream));
  g_assert (G_IS_INPUT_STREAM (input_stream));
  g_assert (NICE_IS_INPUT_STREAM (input_stream));

  g_assert (!g_input_stream_is_closed (input_stream));
  g_assert (!g_input_stream_has_pending (input_stream));

  /* Check the output stream’s properties. */
  output_stream = g_io_stream_get_output_stream (G_IO_STREAM (io_stream));
  g_assert (G_IS_OUTPUT_STREAM (output_stream));
  g_assert (NICE_IS_OUTPUT_STREAM (output_stream));

  g_assert (!g_output_stream_is_closing (output_stream));
  g_assert (!g_output_stream_is_closed (output_stream));
  g_assert (!g_output_stream_has_pending (output_stream));

  /* Remove the component and check that the I/O streams close. */
  nice_agent_remove_stream (agent, stream_id);

  g_assert (g_io_stream_is_closed (G_IO_STREAM (io_stream)));
  g_assert (g_input_stream_is_closed (input_stream));
  g_assert (g_output_stream_is_closed (output_stream));

  g_object_unref (io_stream);
  g_object_unref (agent);
}
Exemple #2
0
static void ekg_gnutls_handle_data(GDataInputStream *s, gpointer data) {
	struct ekg_gnutls_connection *gc = data;
	ssize_t ret;
	char buf[4096];

	g_assert(gc->connection->slave);

	do {
		ret = gnutls_record_recv(gc->session, buf, sizeof(buf));

		if (ret > 0)
			g_memory_input_stream_add_data(
					gc->instream,
					g_memdup(buf, ret),
					ret,
					g_free);
		else if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN) {
			GError *err;
			
			if (ret != 0)
				err = g_error_new_literal(EKG_GNUTLS_ERROR,
						ret, gnutls_strerror(ret));
			else {
				debug_function("ekg_gnutls_handle_data(), got EOF from gnutls\n");
				err = g_error_new_literal(
						EKG_CONNECTION_ERROR,
						EKG_CONNECTION_ERROR_EOF,
						"Connection terminated");
			}

			gc->connection->slave->failure_callback(
					gc->connection->slave->instream,
					err,
					gc->connection->slave->priv_data);
			g_error_free(err);
			ekg_connection_remove(gc->connection->slave);
			ekg_connection_remove(gc->connection);
			return;
		}
	} while (ret > 0 || ret == GNUTLS_E_INTERRUPTED);

		/* not necessarily async but be lazy */
	if (!g_input_stream_has_pending(G_INPUT_STREAM(gc->connection->slave->instream)))
		setup_async_read(gc->connection->slave);
}
Exemple #3
0
static void ekg_connection_remove(struct ekg_connection *c) {
	if (g_input_stream_has_pending(G_INPUT_STREAM(c->instream))) {
		debug_warn("ekg_connection_remove(%x) input stream has pending!\n", c);
		g_input_stream_clear_pending(G_INPUT_STREAM(c->instream));
	}
#if 0 /* XXX */
	g_assert(!g_output_stream_has_pending(
				G_OUTPUT_STREAM(c->outstream)));
#endif

	connections = g_slist_remove(connections, c);

	g_string_free(c->wr_buffer, TRUE);
	g_object_unref(c->cancellable);
	g_object_unref(c->instream);
	g_object_unref(c->outstream);
	g_slice_free(struct ekg_connection, c);
}