Пример #1
0
TermiosHelper::~TermiosHelper()
{
    // It is good practice to reset a serial port back to the state in
    // which you found it. This is why we saved the original termios struct
    // The constant TCSANOW (defined in termios.h) indicates that
    // the change should take effect immediately.

    restoreTermios();

    delete originalAttrs_;
    delete currentAttrs_;
}
Пример #2
0
Файл: luit.c Проект: aosm/X11
void
parent(int pid, int pty)
{
    unsigned char buf[BUFFER_SIZE];
    int i;
    int val;
    int rc;

    if(verbose) {
        reportIso2022(outputState);
    }

#ifdef SIGWINCH
    installHandler(SIGWINCH, sigwinchHandler);
#endif
    installHandler(SIGCHLD, sigchldHandler);

    rc = copyTermios(0, pty);
    if(rc < 0)
        FatalError("Couldn't copy terminal settings\n");

    rc = setRawTermios();
    if(rc < 0)
        FatalError("Couldn't set terminal to raw\n");

    val = fcntl(0, F_GETFL, 0);
    if(val >= 0) {
        fcntl(0, F_SETFL, val | O_NONBLOCK);
    }
    val = fcntl(pty, F_GETFL, 0);
    if(val >= 0) {
        fcntl(pty, F_SETFL, val | O_NONBLOCK);
    }

    setWindowSize(0, pty);

    for(;;) {
        rc = waitForInput(0, pty);

        if(sigwinch_queued) {
            sigwinch_queued = 0;
            setWindowSize(0, pty);
        }

        if(sigchld_queued && exitOnChild)
            break;

        if(rc > 0) {
            if(rc & 2) {
                i = read(pty, buf, BUFFER_SIZE);
                if((i == 0) || ((i < 0) && (errno != EAGAIN)))
                    break;
                if(i > 0)
                    copyOut(outputState, 0, buf, i);
            }
            if(rc & 1) {
                i = read(0, buf, BUFFER_SIZE);
                if((i == 0) || ((i < 0) && (errno != EAGAIN)))
                    break;
                if(i > 0)
                    copyIn(inputState, pty, buf, i);
            }
        }
    }

    restoreTermios();
}