static char sccsid
[] = "@(#)io.c 1.2 (Berkeley) %G%";
* This file contains the I/O handling and the exchange of
* edit characters. This connection itself is established in
#define A_LONG_TIME 10000000
#define STDIN_MASK (1<<fileno(stdin)) /* the bit mask for standard
* The routine to do the actual talking
register int read_template
, sockt_mask
;
message("Connection established\007\007\007");
* Wait on both the other process (sockt_mask) and
* standard input ( STDIN_MASK )
read_template
= sockt_mask
| STDIN_MASK
;
read_set
= read_template
;
wait
.tv_sec
= A_LONG_TIME
;
nb
= select(32, &read_set
, 0, 0, &wait
);
read_set
= read_template
;
/* panic, we don't know what happened */
p_error("Unexpected error from select");
if (read_set
& sockt_mask
) {
/* There is data on sockt */
nb
= read(sockt
, buf
, sizeof buf
);
message("Connection closed. Exiting");
display(&his_win
, buf
, nb
);
if (read_set
& STDIN_MASK
) {
* We can't make the tty non_blocking, because
* curses's output routines would screw up
ioctl(0, FIONREAD
, (struct sgttyb
*) &nb
);
display(&my_win
, buf
, nb
);
/* might lose data here because sockt is non-blocking */
extern char *sys_errlist
[];
* p_error prints the system error message on the standard location
* on the screen and then exits. (i.e. a curses version of perror)
sys
= sys_errlist
[errno
];
wmove(my_win
.x_win
, current_line
%my_win
.x_nlines
, 0);
wprintw(my_win
.x_win
, "[%s : %s (%d)]\n", string
, sys
, errno
);
* Display string in the standard location
wmove(my_win
.x_win
, current_line
%my_win
.x_nlines
, 0);
wprintw(my_win
.x_win
, "[%s]\n", string
);