4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * this file contains the I/O handling and the exchange of
44 * edit characters. This connection itself is established in ctl.c
51 #include <sys/filio.h>
54 #define A_LONG_TIME 10000000
55 #define STDIN_MASK (1<<fileno(stdin)) /* the bit mask for standard input */
58 * The routine to do the actual talking
64 int read_template
, sockt_mask
;
69 message(gettext("Connection established"));
70 beep(); beep(); beep();
73 sockt_mask
= (1<<sockt
);
76 * wait on both the other process (sockt_mask) and
77 * standard input ( STDIN_MASK )
80 read_template
= sockt_mask
| STDIN_MASK
;
84 read_set
= read_template
;
86 wait
.tv_sec
= A_LONG_TIME
;
89 nb
= select(32, (fd_set
*)&read_set
, 0, 0, &wait
);
93 /* We may be returning from an interrupt handler */
96 read_set
= read_template
;
99 /* panic, we don't know what happened */
101 gettext("Unexpected error from select"));
106 if (read_set
& sockt_mask
) {
108 /* There is data on sockt */
109 nb
= read(sockt
, buf
, sizeof (buf
));
112 message(gettext("Connection closed. Exiting"));
113 pause(); /* wait for Ctrl-C */
116 display(&rem_win
, buf
, nb
);
120 if (read_set
& STDIN_MASK
) {
123 * we can't make the tty non_blocking, because
124 * curses's output routines would screw up
127 ioctl(0, FIONREAD
, (struct sgttyb
*)&nb
);
128 nb
= read(0, buf
, nb
);
129 display(&my_win
, buf
, nb
);
130 write(sockt
, buf
, nb
);
133 * We might lose data here because sockt is
142 * p_error prints the system error message on the standard location
143 * on the screen and then exits. (i.e. a curses version of perror)
147 p_error(char *string
)
149 wmove(my_win
.x_win
, current_line
%my_win
.x_nlines
, 0);
150 wprintw(my_win
.x_win
, "[%s : %s]\n", string
, strerror(errno
));
151 wrefresh(my_win
.x_win
);
157 /* display string in the standard location */
160 message(char *string
)
162 wmove(my_win
.x_win
, current_line
%my_win
.x_nlines
, 0);
163 wprintw(my_win
.x_win
, "[%s]\n", string
);
164 wrefresh(my_win
.x_win
);