Exemplo n.º 1
0
static void
handle_fd (DskPattern *pattern,
           const char *prefix_filename,
           unsigned    buffer_size,
           int         fd)
{
  DskBuffer in = DSK_BUFFER_INIT;
  DskBuffer out = DSK_BUFFER_INIT;
  for (;;)
    {
      int rv = dsk_buffer_readv (&in, fd);
      if (rv == 0)
        break;
      char *line;
      while ((line = dsk_buffer_read_line (&in)) != NULL)
        {
          if (dsk_pattern_match (pattern, line))
            {
              if (prefix_filename)
                {
                  dsk_buffer_append_string (&out, prefix_filename);
                  dsk_buffer_append_string (&out, ": ");
                }
              dsk_buffer_append_string (&out, line);
              dsk_buffer_append_byte (&out, '\n');

              while (out.size > buffer_size)
                dsk_buffer_writev (&out, STDOUT_FILENO);
            }
          dsk_free (line);
        }
    }
  while (out.size > 0)
    dsk_buffer_writev (&out, STDOUT_FILENO);
}
Exemplo n.º 2
0
static DskIOResult
dsk_client_stream_sink_write_buffer  (DskOctetSink   *sink,
                                      DskBuffer      *write_buffer,
                                      DskError      **error)
{
  int rv;
  DskClientStream *stream;
  if (sink->stream == NULL)
    {
      dsk_set_error (error, "write to dead stream");
      return DSK_IO_RESULT_ERROR;
    }
  stream = DSK_CLIENT_STREAM (sink->stream);
  if (stream->fd < 0)
    {
      dsk_set_error (error, "write to stream with no file-descriptor");
      return DSK_IO_RESULT_ERROR;
    }
  rv = dsk_buffer_writev (write_buffer, stream->fd);
  if (rv < 0)
    {
      if (errno == EINTR || errno == EAGAIN)
        return DSK_IO_RESULT_AGAIN;
      dsk_set_error (error, "error writing data to fd %u: %s",
                     stream->fd, strerror (errno));
      return DSK_IO_RESULT_ERROR;
    }
  ping_idle_disconnect_timer (stream);
  return DSK_IO_RESULT_SUCCESS;
}
Exemplo n.º 3
0
static void
respond_take_json (DskHttpServerRequest *request,
                   DskJsonValue         *value)
{
  DskBuffer buffer = DSK_BUFFER_STATIC_INIT;
  DskHttpServerResponseOptions options = DSK_HTTP_SERVER_RESPONSE_OPTIONS_DEFAULT;
  dsk_json_value_to_buffer (value, -1, &buffer);
  options.source_buffer = &buffer;
  options.content_type = "application/json";
  dsk_http_server_request_respond (request, &options);

#if 0
  dsk_json_value_to_buffer (value, 0, &buffer);
  while (buffer.size)
    dsk_buffer_writev (&buffer, 1);
#endif
  dsk_json_value_free (value);
}