コード例 #1
0
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);
}
コード例 #2
0
ファイル: deadbeef-gvfs.c プロジェクト: asv/deadbeef-gvfs
static int64_t
ddb_gvfs_getlength (DB_FILE *stream)
{
  vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream;

  g_return_val_if_fail (data != NULL, -1);
  g_return_val_if_fail (! g_input_stream_is_closed (data->handle), -1);

  GError *error = NULL;
  GFileInfo *info;

  info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM(data->handle),
                                         G_FILE_ATTRIBUTE_STANDARD_SIZE,
                                         NULL, &error);
  if (info == NULL)
    {
      g_warning ("Could not read stream info: %s", error->message);
      g_error_free (error);
      return -1;
    }

  gint64 size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
  g_object_unref (info);

  return size;
}
コード例 #3
0
ファイル: gvfs.c プロジェクト: kfihihc/xmms2-devel
static gint64
xmms_gvfs_seek (xmms_xform_t *xform, gint64 offset,
                xmms_xform_seek_mode_t whence, xmms_error_t *error)
{
    GSeekType type;
    GError *err = NULL;
    xmms_gvfs_data_t *data = xmms_xform_private_data_get (xform);

    g_return_val_if_fail (data, -1);
    g_return_val_if_fail (!g_input_stream_is_closed (data->handle), -1);

    switch (whence) {
    case XMMS_XFORM_SEEK_CUR:
        type = G_SEEK_CUR;
        break;
    case XMMS_XFORM_SEEK_SET:
        type = G_SEEK_SET;
        break;
    case XMMS_XFORM_SEEK_END:
        type = G_SEEK_END;
        break;
    }

    if (g_seekable_seek (G_SEEKABLE (data->handle), offset, type, NULL, &err)) {
        return g_seekable_tell (G_SEEKABLE (data->handle));
    }

    xmms_error_set (error, XMMS_ERROR_GENERIC, err->message);
    return -1;
}
コード例 #4
0
static gboolean
gst_gio_base_src_start (GstBaseSrc * base_src)
{
  GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src);
  GstGioBaseSrcClass *gbsrc_class = GST_GIO_BASE_SRC_GET_CLASS (src);

  src->position = 0;

  /* FIXME: This will likely block */
  src->stream = gbsrc_class->get_stream (src);
  if (G_UNLIKELY (!G_IS_INPUT_STREAM (src->stream))) {
    GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
        ("No input stream provided by subclass"));
    return FALSE;
  } else if (G_UNLIKELY (g_input_stream_is_closed (src->stream))) {
    GST_ELEMENT_ERROR (src, LIBRARY, FAILED, (NULL),
        ("Input stream is already closed"));
    return FALSE;
  }

  if (G_IS_SEEKABLE (src->stream))
    src->position = g_seekable_tell (G_SEEKABLE (src->stream));

  GST_DEBUG_OBJECT (src, "started source");

  return TRUE;
}
コード例 #5
0
ファイル: inputstream.c プロジェクト: kakaroto/libnice
static gssize
nice_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer,
    gsize count, GError **error)
{
  NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
  NiceAgent *agent;  /* owned */
  gssize len;

  /* Closed streams are not readable. */
  if (g_input_stream_is_closed (G_INPUT_STREAM (stream))) {
    return 0;
  }

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed due to the NiceAgent being finalised.");
    return -1;
  }

  len = nice_agent_recv_nonblocking (agent, priv->stream_id,
      priv->component_id, (guint8 *) buffer, count, NULL, error);

  g_object_unref (agent);

  return len;
}
コード例 #6
0
ファイル: deadbeef-gvfs.c プロジェクト: asv/deadbeef-gvfs
static int64_t
ddb_gvfs_tell (DB_FILE *stream)
{
  vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream;

  g_return_val_if_fail (data != NULL, -1);
  g_return_val_if_fail (! g_input_stream_is_closed (data->handle), -1);

  return g_seekable_tell (G_SEEKABLE (data->handle));
}
コード例 #7
0
ファイル: inputstream.c プロジェクト: kakaroto/libnice
static gboolean
nice_input_stream_is_readable (GPollableInputStream *stream)
{
  NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
  Component *component = NULL;
  Stream *_stream = NULL;
  gboolean retval = FALSE;
  GSList *i;
  NiceAgent *agent;  /* owned */

  /* Closed streams are not readable. */
  if (g_input_stream_is_closed (G_INPUT_STREAM (stream)))
    return FALSE;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return FALSE;

  agent_lock (agent);

  if (!agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component)) {
    g_warning ("Could not find component %u in stream %u", priv->component_id,
        priv->stream_id);
    goto done;
  }

  /* If it’s a reliable agent, see if there’s any pending data in the pseudo-TCP
   * buffer. */
  if (agent->reliable &&
      pseudo_tcp_socket_get_available_bytes (component->tcp) > 0) {
    retval = TRUE;
    goto done;
  }

  /* Check whether any of the component’s FDs are pollable. */
  for (i = component->socket_sources; i != NULL; i = i->next) {
    SocketSource *socket_source = i->data;
    NiceSocket *nicesock = socket_source->socket;

    if (g_socket_condition_check (nicesock->fileno, G_IO_IN) != 0) {
      retval = TRUE;
      break;
    }
  }

done:
  agent_unlock (agent);

  g_object_unref (agent);

  return retval;
}
コード例 #8
0
static inline void
try_write_next_buffer (SoupCacheInputStream *istream)
{
	SoupCacheInputStreamPrivate *priv = istream->priv;

	if (priv->current_writing_buffer == NULL && priv->buffer_queue->length)
		soup_cache_input_stream_write_next_buffer (istream);
	else if (priv->read_finished)
		notify_and_clear (istream, NULL);
	else if (g_input_stream_is_closed (G_INPUT_STREAM (istream))) {
		GError *error = NULL;
		g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_CLOSED,
				     _("Network stream unexpectedly closed"));
		notify_and_clear (istream, error);
	}
}
コード例 #9
0
ファイル: deadbeef-gvfs.c プロジェクト: asv/deadbeef-gvfs
static size_t
ddb_gvfs_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream)
{
  vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream;
  g_return_val_if_fail (data != NULL, EOF);
  g_return_val_if_fail (! g_input_stream_is_closed (data->handle), -1);

  GError *error = NULL;
  gssize bytes = g_input_stream_read (data->handle, ptr, size * nmemb, NULL, &error);
  if (bytes < 0) {
      g_warning ("ddb_gvfs_read: error: %s", error->message);
      g_error_free (error);
      return 0;
  }

  return bytes / size;
}
コード例 #10
0
const gchar *
checkcopy_input_stream_get_checksum (CheckcopyInputStream * stream, CheckcopyChecksumType type)
{
  CheckcopyInputStreamPrivate *priv = GET_PRIVATE (stream);
  GFilterInputStream *filter = G_FILTER_INPUT_STREAM (stream);
  GInputStream *base = filter->base_stream;

  const gchar *checksum;

  if (g_input_stream_is_closed (base)) {
    checksum = checksum_get_string (type, priv->checksum[type]);
  } else {
    checksum = NULL;
  }

  return checksum;
}
コード例 #11
0
ファイル: gvfs.c プロジェクト: kfihihc/xmms2-devel
static gint
xmms_gvfs_read (xmms_xform_t *xform, gpointer buffer, gint len,
                xmms_error_t *error)
{
    gint ret;
    GError *err = NULL;
    xmms_gvfs_data_t *data = xmms_xform_private_data_get (xform);

    g_return_val_if_fail (data, -1);
    g_return_val_if_fail (!g_input_stream_is_closed (data->handle), -1);

    ret = g_input_stream_read (data->handle, buffer, len, NULL, &err);

    if (ret < 0) {
        xmms_error_set (error, XMMS_ERROR_GENERIC, err->message);
    }

    return ret;
}
コード例 #12
0
ファイル: inputstream.c プロジェクト: kakaroto/libnice
static void
nice_input_stream_dispose (GObject *object)
{
  NiceInputStream *self = NICE_INPUT_STREAM (object);
  NiceAgent *agent;

  /* Ensure the stream is closed first, otherwise the agent can’t be found in
   * the close handler called by the parent implementation. */
  if (!g_input_stream_is_closed (G_INPUT_STREAM (object)))
    g_input_stream_close (G_INPUT_STREAM (object), NULL, NULL);

  agent = g_weak_ref_get (&self->priv->agent_ref);
  if (agent != NULL) {
    g_signal_handlers_disconnect_by_func (agent, streams_removed_cb, self);
    g_object_unref (agent);
  }

  g_weak_ref_clear (&self->priv->agent_ref);

  G_OBJECT_CLASS (nice_input_stream_parent_class)->dispose (object);
}
コード例 #13
0
ファイル: inputstream.c プロジェクト: kakaroto/libnice
static GSource *
nice_input_stream_create_source (GPollableInputStream *stream,
    GCancellable *cancellable)
{
  NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
  GSource *component_source = NULL;
  NiceAgent *agent;  /* owned */

  /* Closed streams cannot have sources. */
  if (g_input_stream_is_closed (G_INPUT_STREAM (stream)))
    goto dummy_source;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    goto dummy_source;

  component_source = component_input_source_new (agent, priv->stream_id,
      priv->component_id, stream, cancellable);

  g_object_unref (agent);

  return component_source;

 dummy_source:

  component_source = g_pollable_source_new (G_OBJECT (stream));

  if (cancellable) {
    GSource *cancellable_source = g_cancellable_source_new (cancellable);

    g_source_set_dummy_callback (cancellable_source);
    g_source_add_child_source (component_source, cancellable_source);
    g_source_unref (cancellable_source);
  }

  return component_source;
}
コード例 #14
0
ファイル: deadbeef-gvfs.c プロジェクト: asv/deadbeef-gvfs
static int
ddb_gvfs_seek (DB_FILE *stream, int64_t offset, int whence)
{
  vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream;

  g_return_val_if_fail (data != NULL, -1);

  if (!g_seekable_can_seek (G_SEEKABLE (data->handle)))
    return -1;

  g_return_val_if_fail (! g_input_stream_is_closed (data->handle), -1);

  GSeekType seektype;
  switch (whence) {
    case SEEK_CUR:
      seektype = G_SEEK_CUR;
      break;

    case SEEK_END:
      seektype = G_SEEK_END;
      break;

    default:
      seektype = G_SEEK_SET;
      break;
  }

  GError *error = NULL;

  if (g_seekable_seek (G_SEEKABLE (data->handle), offset, seektype, NULL, &error))
    return 0;

  g_warning ("Could not seek: %s", error->message);
  g_error_free (error);

  return -1;
}