Example #1
0
static void setup_async_read(struct ekg_connection *c) {
	g_buffered_input_stream_fill_async(
			G_BUFFERED_INPUT_STREAM(c->instream),
			-1, /* fill the buffer */
			G_PRIORITY_DEFAULT,
			c->cancellable,
			done_async_read,
			c);
}
Example #2
0
static void
client_fill_cb (GObject *source_object,
		GAsyncResult *result,
		gpointer user_data)
{
  BroadwayClient *client = user_data;
  gssize res;

  res = g_buffered_input_stream_fill_finish (client->in, result, NULL);
  
  if (res > 0)
    {
      guint32 size;
      gsize count, remaining;
      guint8 *buffer;

      buffer = (guint8 *)g_buffered_input_stream_peek_buffer (client->in, &count);

      remaining = count;
      while (remaining >= sizeof (guint32))
	{
	  memcpy (&size, buffer, sizeof (guint32));

	  if (size <= remaining)
	    {
	      client_handle_request (client, (BroadwayRequest *)buffer);

	      remaining -= size;
	      buffer += size;
	    }
	}
      
      /* This is guaranteed not to block */
      g_input_stream_skip (G_INPUT_STREAM (client->in), count - remaining, NULL, NULL);
      
      g_buffered_input_stream_fill_async (client->in,
					  4*1024,
					  0,
					  NULL,
					  client_fill_cb, client);
    }
  else
    {
      client_disconnected (client);
    }
}
Example #3
0
/**
 * news_parser_parse_async:
 * @parser: (in): A #NewsParser.
 * @stream: (in): A #GInputStream.
 * @cancellable: (in): A #GCancellable to to cancel the task.
 * @callback: (in): A callback to perform when the operation completes.
 * @user_data: (in): User data for @callback.
 *
 * Requests that @parser parse the feed contained in @stream asynchronously.
 * When the operation completes, @callback will be executed from the
 * main loop. @callback is responsible for calling news_parser_parse_finish()
 * to retrieve the result.
 *
 * Returns: None.
 */
void
news_parser_parse_async (NewsParser          *parser,
                         GInputStream        *stream,
                         GCancellable        *cancellable,
                         GAsyncReadyCallback  callback,
                         gpointer             user_data)
{
   NewsParserPrivate *priv;
   GInputStream *buffered;

   ENTRY;

   g_return_if_fail(NEWS_IS_PARSER(parser));
   g_return_if_fail(G_IS_INPUT_STREAM(stream));
   g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
   g_return_if_fail(callback != NULL);
   g_return_if_fail(parser->priv->simple == NULL);

   priv = parser->priv;

   priv->simple = g_simple_async_result_new(G_OBJECT(parser),
                                            callback, user_data,
                                            news_parser_parse_async);

   if (cancellable) {
      priv->cancellable = g_object_ref(cancellable);
   }

   buffered = g_buffered_input_stream_new_sized(stream, 1024);
   g_buffered_input_stream_fill_async(G_BUFFERED_INPUT_STREAM(buffered),
                                      BUFFER_FILL_SIZE,
                                      G_PRIORITY_DEFAULT,
                                      priv->cancellable,
                                      news_parser_buffered_fill_cb,
                                      g_object_ref(parser));
   g_object_unref(buffered);

   EXIT;
}
static VALUE
rg_fill_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbcount, rbio_priority, rbcancellable, block;
        gssize count;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "03&", &rbcount, &rbio_priority, &rbcancellable, &block);
        count = NIL_P(rbcount) ? -1 : RVAL2GSSIZE(rbcount);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_buffered_input_stream_fill_async(_SELF(self),
                                           count,
                                           io_priority,
                                           cancellable,
                                           rbgio_async_ready_callback,
                                           (gpointer)block);

        return self;
}
Example #5
0
static gboolean
incoming_client (GSocketService    *service,
		 GSocketConnection *connection,
		 GObject           *source_object)
{
  BroadwayClient *client;
  GInputStream *input;
  BroadwayInputMsg ev = { {0} };

  client = g_new0 (BroadwayClient, 1);
  client->id = client_id_count++;
  client->connection = g_object_ref (connection);

  input = g_io_stream_get_input_stream (G_IO_STREAM (client->connection));
  client->in = (GBufferedInputStream *)g_buffered_input_stream_new (input);

  clients = g_list_prepend (clients, client);

  g_buffered_input_stream_fill_async (client->in,
				      4*1024,
				      0,
				      NULL,
				      client_fill_cb, client);

  /* Send initial resize notify */
  ev.base.type = BROADWAY_EVENT_SCREEN_SIZE_CHANGED;
  ev.base.serial = broadway_server_get_next_serial (server) - 1;
  ev.base.time = broadway_server_get_last_seen_time (server);
  broadway_server_get_screen_size (server,
				   &ev.screen_resize_notify.width,
				   &ev.screen_resize_notify.height);

  broadway_events_got_input (&ev,
			     client->id);

  return TRUE;
}