Пример #1
0
static int read_thread(void *data)
{
	int local_delay = 0;
	struct st_inf s;
	static struct st_inf sp;

        while (!kthread_should_stop()) {

		/*
		 * Do not sleep the whole chunk, otherwise if
		 *  the module is removed it will wait for that whole delay.
		 */
		if (local_delay != 0) {
			local_delay--;
			/* ToDo: Find a better interruptible delay implementation */
			wait_event_interruptible_timeout(_queue, 0, HZ);
			continue;
		}

		local_delay = _read_delay;
		_reads[0]++;

		if (start_read() != 0) {
			continue;
		}

		if (do_read_data(&s) != 0) {
			local_delay = SHORT_DELAY; /* Ignore this reading */
		}
		else {
			if (_reads[1] == 0) {
				local_delay = SHORT_DELAY;
				_reads[1]++ ;

			}
			else {
				if ((s.t - sp.t > 50) ||  /* 5 degrees difference */
				    (s.t - sp.t < -50) ||
				    (s.rh - sp.rh > 100) || /* or 10 RH differene */
				    (s.rh - sp.rh < -100))
				{
					/* Ignore this reading */
					local_delay = SHORT_DELAY;
				}
				else {
					sns = s;
					_reads[1]++;
				}
			}
			sp = s;
		}
        }
        return 0;
}
Пример #2
0
/*
 *   Read Data command
 *     Open Data Channel, read the data from
 *     the archive device and send to File
 *     daemon.
 */
static bool read_data_cmd(JCR *jcr)
{
   BSOCK *fd = jcr->file_bsock;

   Dmsg1(120, "Read data: %s", fd->msg);
   if (jcr->session_opened) {
      Dmsg1(120, "<bfiled: %s", fd->msg);
      return do_read_data(jcr);
   } else {
      pm_strcpy(jcr->errmsg, _("Attempt to read on non-open session.\n"));
      fd->fsend(NOT_opened);
      return false;
   }
}
Пример #3
0
void libcouchbase_server_event_handler(libcouchbase_socket_t sock, short which, void *arg) {
    libcouchbase_server_t *c = arg;
    (void)sock;

    if (which & LIBCOUCHBASE_READ_EVENT) {
        if (do_read_data(c) != 0) {
            /* TODO stash error message somewhere
             * "Failed to read from connection to \"%s:%s\"", c->hostname, c->port */
            libcouchbase_failout_server(c, LIBCOUCHBASE_NETWORK_ERROR);
            return;
        }
    }

    if (which & LIBCOUCHBASE_WRITE_EVENT) {
        if (c->connected) {
            hrtime_t now = gethrtime();
            hrtime_t tmo = c->instance->timeout.usec;
            tmo *= 1000;
            if (c->next_timeout != 0 && (now > (tmo + c->next_timeout))) {
                libcouchbase_purge_single_server(c,
                                                 &c->cmd_log,
                                                 &c->output_cookies,
                                                 tmo, now,
                                                 LIBCOUCHBASE_ETIMEDOUT);
            }
        }

        if (do_send_data(c) != 0) {
            /* TODO stash error message somewhere
             * "Failed to send to the connection to \"%s:%s\"", c->hostname, c->port */
            libcouchbase_failout_server(c, LIBCOUCHBASE_NETWORK_ERROR);
            return;
        }
    }

    if (c->output.nbytes == 0) {
        c->instance->io->update_event(c->instance->io, c->sock,
                                      c->event, LIBCOUCHBASE_READ_EVENT,
                                      c, libcouchbase_server_event_handler);
    } else {
        c->instance->io->update_event(c->instance->io, c->sock,
                                      c->event, LIBCOUCHBASE_RW_EVENT,
                                      c, libcouchbase_server_event_handler);
    }

    libcouchbase_maybe_breakout(c->instance);

    /* Make it known that this was a success. */
    libcouchbase_error_handler(c->instance, LIBCOUCHBASE_SUCCESS, NULL);
}
Пример #4
0
void lcb_server_v0_event_handler(lcb_socket_t sock, short which, void *arg)
{
    lcb_server_t *c = arg;
    lcb_connection_t conn = &c->connection;
    (void)sock;

    if (which & LCB_WRITE_EVENT) {
        lcb_sockrw_status_t status;

        status = lcb_sockrw_v0_write(conn, conn->output);
        if (status != LCB_SOCKRW_WROTE && status != LCB_SOCKRW_WOULDBLOCK) {
            event_complete_common(c, LCB_NETWORK_ERROR);
            return;
        }
    }

    if (which & LCB_READ_EVENT || conn->input->nbytes) {
        if (do_read_data(c, which & LCB_READ_EVENT) != 0) {
            /* TODO stash error message somewhere
             * "Failed to read from connection to \"%s:%s\"", c->hostname, c->port */
            event_complete_common(c, LCB_NETWORK_ERROR);
            return;
        }
    }

    /**
     * Because of the operations-per-call limit, we might still need to read
     * a bit more once the event loop calls us again. We can't assume a
     * non-blocking read if we don't expect any data, but we can usually rely
     * on a non-blocking write.
     */
    if (conn->output->nbytes || conn->input->nbytes) {
        which = LCB_RW_EVENT;
    } else {
        which = LCB_READ_EVENT;
    }

    lcb_sockrw_set_want(conn, which, 1);
    event_complete_common(c, LCB_SUCCESS);
}