1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)io.c	5.1 (Berkeley) 6/6/85";
   9: #endif not lint
  10: 
  11: /*
  12:  * This file contains the I/O handling and the exchange of
  13:  * edit characters. This connection itself is established in
  14:  * ctl.c
  15:  */
  16: 
  17: #include "talk.h"
  18: #include <stdio.h>
  19: #include <errno.h>
  20: #include <sys/time.h>
  21: 
  22: #define A_LONG_TIME 10000000
  23: #define STDIN_MASK (1<<fileno(stdin))   /* the bit mask for standard
  24: 					   input */
  25: extern int errno;
  26: 
  27: /*
  28:  * The routine to do the actual talking
  29:  */
  30: talk()
  31: {
  32:     register int read_template, sockt_mask;
  33:     int read_set, nb;
  34:     char buf[BUFSIZ];
  35:     struct timeval wait;
  36: 
  37:     message("Connection established\007\007\007");
  38:     current_line = 0;
  39:     sockt_mask = (1<<sockt);
  40: 
  41:     /*
  42: 	 * Wait on both the other process (sockt_mask) and
  43: 	 * standard input ( STDIN_MASK )
  44: 	 */
  45:     read_template = sockt_mask | STDIN_MASK;
  46:     forever {
  47:         read_set = read_template;
  48:         wait.tv_sec = A_LONG_TIME;
  49:         wait.tv_usec = 0;
  50:         nb = select(32, &read_set, 0, 0, &wait);
  51:         if (nb <= 0) {
  52:             if (errno == EINTR) {
  53:                 read_set = read_template;
  54:                 continue;
  55:             }
  56:             /* panic, we don't know what happened */
  57:             p_error("Unexpected error from select");
  58:             quit();
  59:         }
  60:         if (read_set & sockt_mask) {
  61:             /* There is data on sockt */
  62:             nb = read(sockt, buf, sizeof buf);
  63:             if (nb <= 0) {
  64:                 message("Connection closed. Exiting");
  65:                 quit();
  66:             }
  67:             display(&his_win, buf, nb);
  68:         }
  69:         if (read_set & STDIN_MASK) {
  70:             /*
  71: 			 * We can't make the tty non_blocking, because
  72: 			 * curses's output routines would screw up
  73: 			 */
  74:             ioctl(0, FIONREAD, (struct sgttyb *) &nb);
  75:             nb = read(0, buf, nb);
  76:             display(&my_win, buf, nb);
  77:             /* might lose data here because sockt is non-blocking */
  78:             write(sockt, buf, nb);
  79:         }
  80:     }
  81: }
  82: 
  83: extern  int errno;
  84: extern  int sys_nerr;
  85: extern  char *sys_errlist[];
  86: 
  87: /*
  88:  * p_error prints the system error message on the standard location
  89:  * on the screen and then exits. (i.e. a curses version of perror)
  90:  */
  91: p_error(string)
  92:     char *string;
  93: {
  94:     char *sys;
  95: 
  96:     sys = "Unknown error";
  97:     if (errno < sys_nerr)
  98:         sys = sys_errlist[errno];
  99:     wmove(my_win.x_win, current_line%my_win.x_nlines, 0);
 100:     wprintw(my_win.x_win, "[%s : %s (%d)]\n", string, sys, errno);
 101:     wrefresh(my_win.x_win);
 102:     move(LINES-1, 0);
 103:     refresh();
 104:     quit();
 105: }
 106: 
 107: /*
 108:  * Display string in the standard location
 109:  */
 110: message(string)
 111:     char *string;
 112: {
 113: 
 114:     wmove(my_win.x_win, current_line%my_win.x_nlines, 0);
 115:     wprintw(my_win.x_win, "[%s]\n", string);
 116:     wrefresh(my_win.x_win);
 117: }

Defined functions

message defined in line 110; used 12 times
talk defined in line 30; used 1 times

Defined variables

sccsid defined in line 8; never used

Defined macros

A_LONG_TIME defined in line 22; used 1 times
  • in line 48
STDIN_MASK defined in line 23; used 2 times
Last modified: 1986-03-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1153
Valid CSS Valid XHTML 1.0 Strict