示例#1
0
文件: telnet.c 项目: DruSatori/AEMud
/*
 * Read data from the Telnet session to the raw input queue.
 */
static void
telnet_read(ndesc_t *nd, telnet_t *tp)
{
    int cc;

    if (!nq_full(tp->t_rawq))
    {
	if (tp->t_flags & TF_URGENT)
	{
	    if (at_mark(nd_fd(nd)))
	    {
		tp->t_flags &= ~TF_URGENT;
		nd_enable(nd, ND_X);
	    }
	}

        cc = nq_recv(tp->t_rawq, nd_fd(nd), &tp->t_rblen);
        if (cc == -1)
        {
            switch (errno)
            {
            case EWOULDBLOCK:
            case EINTR:
            case EPROTO:
                break;

            default:
		telnet_disconnect(tp);
                return;
            }
        }

	if (cc == 0)
	{
	    telnet_disconnect(tp);
	    return;
	}

	if ((tp->t_flags & TF_FLOWC) == 0)
	    nd_enable(nd, ND_C);

	telnet_enabr(tp);

	if (!nq_full(tp->t_rawq))
	    return;
    }

    tp->t_flags |= TF_ENABR;
    nd_disable(nd, ND_R);
}
示例#2
0
文件: telnet.c 项目: DruSatori/AEMud
/*
 * Write data from the output queue to the Telnet session.
 */
static void
telnet_write(ndesc_t *nd, telnet_t *tp)
{
    if (!nq_empty(tp->t_outq))
    {
	if (nq_send(tp->t_outq, nd_fd(nd), &tp->t_sblen) == -1)
	{
	    switch (errno)
	    {
	    case EWOULDBLOCK:
	    case EINTR:
	    case EPROTO:
		break;

	    default:
		telnet_disconnect(tp);
		return;
	    }
	}
    }

    if (tp->t_flags & TF_OVFLOUTQ)
    {
	if (nq_len(tp->t_outq) < TELNET_OUTQ_LOWAT)
	{
	    tp->t_flags &= ~TF_OVFLOUTQ;
	    nq_puts(tp->t_outq, (u_char *)"*** Truncated. ***\r\n");
	}
    }

    if (tp->t_flags & TF_FLOWC)
    {
	if (nq_len(tp->t_outq) < TELNET_OUTQ_HIWAT)
	{
	    tp->t_flags &= ~TF_FLOWC;
	    nd_enable(nd, ND_C);
	}
    }

    if (!nq_empty(tp->t_outq))
	return;

    nq_init(tp->t_outq);

    tp->t_flags |= TF_ENABW;
    nd_disable(nd, ND_W);
}
示例#3
0
/*
 * Write data from the output queue to the Telnet session.
 */
static void
telnet_write(ndesc_t *nd, telnet_t *tp)
{
    if (!nq_empty(tp->t_outq))
    {
	if (nq_send(tp->t_outq, nd_fd(nd), &tp->t_sblen) == -1)
	{
	    switch (errno)
	    {
	    case EWOULDBLOCK:
	    case EINTR:
	    case EPROTO:
		break;

	    default:
		telnet_disconnect(tp);
		return;
	    }
	}
    }

    if (tp->t_flags & TF_OVFLOUTQ)
    {
	if (nq_len(tp->t_outq) < TELNET_OUTQ_LOWAT)
	{
	    tp->t_flags &= ~TF_OVFLOUTQ;
	    if (tp->t_flags & (TF_INPUT|TF_DISCONNECT) &&
		!tp->task) /* Reenable command processing */
		tp->task = create_task(telnet_interactive, tp);
	}
    }

    if (!nq_empty(tp->t_outq))
	return;

    nq_init(tp->t_outq);

    nd_disable(nd, ND_W);
}