Example #1
0
/* TODO: Enhance
  - client should be able to send multiple bytes
  - escSend() to be error tolorent
  - handle sending esc sequence to tty
*/
static int readFromStdin(int clientfd, int stdi) {
  static escMode mode = EOL;
  char c;
  int nbytes;

  nbytes = read(stdi, &c, 1);
  if (nbytes < 0) {
    perror("mTerm_client: Client socket read error");
    return 0;
  }

  if(c == ASCII_CTRL_X) {
    escClose(clientfd);
    mode = EOL;
    return 1;
  }

  if((mode == EOL) && (c == ASCII_ESC)) {
    mode = ESC;
    return 1;
  } else if (mode == ESC) {
    return ( processEscMode(clientfd, c , &mode));
  } else if ( mode == SEND) {
    if (escSend(clientfd, c , &mode) < 0) {
      mode = EOL;
      perror("mTerm_client: Invalid input to read buffer");
    }
    return 1;
  }
  charSend(clientfd, &c, 1);
  return 1;
}
Example #2
0
/* TODO: Enhance
  - escSend() to be error tolorent
  - handle sending esc sequence to tty
*/
static int readFromStdin(int clientfd, int stdi) {
  static escMode mode = EOL;
  char c[MAX_BYTE];
  int nbytes;

  nbytes = read(stdi, &c, sizeof(c));
  if (nbytes < 0) {
    perror("mTerm_client: Client socket read error to mTerm_server");
    return 0;
  }
  if((mode == EOL) && (c[0] == ASCII_CTRL_L)) {
    mode = ESC;
    return 1;
  } else if (mode == ESC) {
    return (processEscMode(clientfd, c[0], &mode));
  } else if (mode == SEND) {
    if (escSend(clientfd, c[0] , &mode) < 0) {
      mode = EOL;
      perror("mTerm_client: Invalid input to read buffer");
    }
    return 1;
  }
  charSend(clientfd, &c[0], nbytes);
  return 1;
}