コード例 #1
0
ファイル: log.c プロジェクト: cread/slurm
bool
log_has_data()
{
	bool rc = false;
	slurm_mutex_lock(&log_lock);
	if (log->opt.buffered)
		rc = (cbuf_used(log->buf) > 0);
	slurm_mutex_unlock(&log_lock);
	return rc;
}
コード例 #2
0
ファイル: zio.c プロジェクト: surajpkn/flux-core
static int zio_eof_pending (zio_t *zio)
{
    /* Already closed? Then EOF can't be pending */
    if (zio_closed (zio))
      return (0);
    /*
     *   zio object has EOF pending if EOF flag is set and either the
     *    io is unbuffered or the buffer for IO is empty.
     */
    return (zio_eof (zio) && (!cbuf_used (zio->buf)));
}
コード例 #3
0
ファイル: zio.c プロジェクト: surajpkn/flux-core
/*
 *  Callback when zio->dstfd is writeable. Write buffered data to
 *   file descriptor.
 */
static int zio_writer_cb (zio_t *zio)
{
    int rc = 0;

    if (cbuf_used (zio->buf))
        rc = cbuf_read_to_fd (zio->buf, zio->dstfd, -1);
    if (rc < 0) {
        if (errno == EAGAIN)
            return (0);
        zio_debug (zio, "cbuf_read_to_fd: %s\n", strerror (errno));
        return (-1);
    }
    if ((rc == 0) && zio_eof_pending (zio))
        rc = zio_close (zio);
    return (rc);
}
コード例 #4
0
ファイル: evo_serial.c プロジェクト: kebkal/evins
int main(void) {
#ifdef _WIN32
    setmode(fileno(stdout),O_BINARY);
    setmode(fileno(stdin),O_BINARY);
#endif

    erl_chunk_t erl_inp = { 0xFF, 0, CHDR, {0} };
    cbuf_t erl_outp, rs_outp;
    uint8_t rs_inp[254];
    context_t *ctx[3];
    portconf_t portconf = {
        .path = "",
        .baudrate = 115200,
        .databits = 8,
        .stopbits = 1,
        .flowcontrol = 0,
        .parity = SPNONE
    };
    ssize_t rs;

    erl_outp.head = erl_outp.tail = erl_outp.data;
    rs_outp.head  = rs_outp.tail  = rs_outp.data;
    erl_outp.empty = rs_outp.empty = 1;

    ctx[0] = io_stdin();
    ctx[1] = io_stdout();
    ctx[2] = NULL;

    for (;;) {
        if ((rs = erl_read(ctx[0], &erl_inp)) < 0 && rs == -1)
            return 1;
        else if (rs > 0 && erl_inp.state == CREADY) {
            erl_inp.state = CHDR;
            erl_inp.done = 0;
            switch (erl_inp.data[0]) {
            case COPEN:
                erl_inp.data[erl_inp.len] = '\0';
                portconf.baudrate    =  erl_inp.data[1] |
                                       (erl_inp.data[2] << 8) |
                                       (erl_inp.data[3] << 16);
                portconf.databits    = ((erl_inp.data[4] >> 5) & 0x07) + 1;
                portconf.parity      = (erl_inp.data[4] >> 3) & 0x03;
                portconf.stopbits    = ((erl_inp.data[4] >> 2) & 0x01) + 1;
                portconf.flowcontrol = (erl_inp.data[4] >> 1) & 0x01;

                strncpy((char *)portconf.path, (char *)erl_inp.data + 5, sizeof(portconf.path) - 1);
                portconf.path[sizeof(portconf.path) - 1] = '\0';

                if (!(ctx[2] = io_open_rs232(&portconf)))
                    return 1;

                break;

            case CSEND:
                {
                    size_t n_write = erl_inp.len - 1, cf = cbuf_free(&rs_outp);
                    if (cf < n_write)
                        n_write = cf;

                    memcpy(rs_outp.head, erl_inp.data + 1, n_write);
                    rs_outp.head += n_write;

                    // TODO: make a notification of bottleneck overflow
                    // if (n_write != erl_inp.len - 1)
                    //     notiy_about_data_drop();

                    break;
                }
            }
#ifndef _WIN32
        } else if (rs == 0) {
            return 1;
#endif
        }

        if (ctx[2]) {
            if ((rs = io_read(ctx[2], rs_inp, sizeof(rs_inp))) < 0 && rs == -1)
                return 1;
            else if (rs > 0) {
                size_t len = 1 + 1 + rs;

                if (cbuf_free(&erl_outp) < len)
                    return 1;

                erl_outp.head[0] = len - 1;
                erl_outp.head[1] = CRECV;
                memcpy(erl_outp.head + 2, rs_inp, len);
                erl_outp.head += len;
            }

            while (ctx[2] && cbuf_used(&rs_outp)) {
                if ((rs = io_write(ctx[2], rs_outp.tail, cbuf_used(&rs_outp))) < 0 && rs == -1)
                    return 1;
                else if (rs > 0) {
                    rs_outp.tail += rs;
                    cbuf_norm(&rs_outp);
                } else
                    break;
            }
        }

        while (cbuf_used(&erl_outp)) {
            if ((rs = io_write(ctx[1], erl_outp.tail, cbuf_used(&erl_outp))) < 0 && rs == -1)
                return 1;
            else if (rs > 0) {
                erl_outp.tail += rs;
                cbuf_norm(&erl_outp);
            } else
                break;
        }

        if (!ctx[0]->req[0] || (ctx[2] && !ctx[2]->req[0]))
            continue;

        io_poll(ctx, 3);
    }
コード例 #5
0
ファイル: zio.c プロジェクト: surajpkn/flux-core
static int zio_buffer_empty (zio_t *zio)
{
    return (!zio_buffered (zio) || (cbuf_used (zio->buf) == 0));
}
コード例 #6
0
ファイル: zio.c プロジェクト: surajpkn/flux-core
static int zio_buffer_used (zio_t *zio)
{
    return cbuf_used (zio->buf);
}