Ejemplo n.º 1
0
static void *log_commit_thread (void *arg)
{
   INFO0 ("started");
   while (1)
   {
       int ret = util_timed_wait_for_fd (logger_fd[0], 5000);
       if (ret == 0) continue;
       if (ret > 0)
       {
           char cm[80];
           ret = pipe_read (logger_fd[0], cm, sizeof cm);
           if (ret > 0)
           {
               // fprintf (stderr, "logger woken with %d\n", ret);
               log_commit_entries ();
               continue;
           }
       }
       if (ret < 0 && sock_recoverable (sock_error()))
           continue;
       int err = sock_error();
       sock_close (logger_fd[0]);
       sock_close (logger_fd[1]);
       if (worker_count)
       {
           worker_control_create (logger_fd);
           ERROR1 ("logger received code %d", err);
           continue;
       }
       // fprintf (stderr, "logger closed with zero workers\n");
       break;
   }
   return NULL;
}
Ejemplo n.º 2
0
/* get some data from the source. The stream data is placed in a refbuf
 * and sent back, however NULL is also valid as in the case of a short
 * timeout and there's no data pending.
 */
static refbuf_t *get_next_buffer (source_t *source)
{
    refbuf_t *refbuf = NULL;
    int delay = 250;

    if (source->short_delay)
        delay = 0;
    while (global.running == ICE_RUNNING && source->running)
    {
        int fds;
        time_t current = time (NULL);

        fds = util_timed_wait_for_fd (source->con->sock, delay);

        if (fds < 0)
        {
            if (! sock_recoverable (sock_error()))
            {
                WARN0 ("Error while waiting on socket, Disconnecting source");
                source->running = 0;
            }
            break;
        }
        if (fds == 0)
        {
            if (source->last_read + (time_t)source->timeout < current)
            {
                DEBUG3 ("last %ld, timeout %ld, now %ld", source->last_read, source->timeout, current);
                WARN0 ("Disconnecting source due to socket timeout");
                source->running = 0;
            }
            break;
        }
        source->last_read = current;
        refbuf = source->format->get_buffer (source);
        if (refbuf)
            break;
    }

    return refbuf;
}
Ejemplo n.º 3
0
/* get some data from the source. The stream data is placed in a refbuf
 * and sent back, however NULL is also valid as in the case of a short
 * timeout and there's no data pending.
 */
static refbuf_t *get_next_buffer (source_t *source)
{
    refbuf_t *refbuf = NULL;
    int delay = 250;

    if (source->short_delay)
        delay = 0;
    while (global.running == ICE_RUNNING && source->running)
    {
        int fds = 0;
        time_t current = time (NULL);

        if (source->client)
            fds = util_timed_wait_for_fd (source->con->sock, delay);
        else
        {
            thread_sleep (delay*1000);
            source->last_read = current;
        }

        if (current >= source->client_stats_update)
        {
            stats_event_args (source->mount, "total_bytes_read",
                    "%"PRIu64, source->format->read_bytes);
            stats_event_args (source->mount, "total_bytes_sent",
                    "%"PRIu64, source->format->sent_bytes);
            source->client_stats_update = current + 5;
        }
        if (fds < 0)
        {
            if (! sock_recoverable (sock_error()))
            {
                WARN0 ("Error while waiting on socket, Disconnecting source");
                source->running = 0;
            }
            break;
        }
        if (fds == 0)
        {
            if (source->last_read + (time_t)source->timeout < current)
            {
                DEBUG3 ("last %ld, timeout %d, now %ld", (long)source->last_read,
                        source->timeout, (long)current);
                WARN0 ("Disconnecting source due to socket timeout");
                source->running = 0;
            }
            break;
        }
        source->last_read = current;
        refbuf = source->format->get_buffer (source);
        if (source->client->con && source->client->con->error)
        {
            INFO1 ("End of Stream %s", source->mount);
            source->running = 0;
            continue;
        }
        if (refbuf)
            break;
    }

    return refbuf;
}