version 1.4, 1998/04/27 15:45:50 |
version 1.5, 1998/04/28 22:13:28 |
|
|
* ctl.c |
* ctl.c |
*/ |
*/ |
|
|
|
#include "talk.h" |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <errno.h> |
#include <errno.h> |
#include <string.h> |
#include <unistd.h> |
#include "talk.h" |
|
|
|
#define A_LONG_TIME 10000000 |
#define A_LONG_TIME 10000000 |
#define STDIN_MASK (1<<fileno(stdin)) /* the bit mask for standard |
|
input */ |
|
|
|
/* |
/* |
* The routine to do the actual talking |
* The routine to do the actual talking |
*/ |
*/ |
|
void |
talk() |
talk() |
{ |
{ |
register int read_template, sockt_mask; |
fd_set read_template, read_set; |
int read_set, nb; |
int nb; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
struct timeval wait; |
struct timeval wait; |
|
|
|
|
message("Connection established\007\007\007"); |
message("Connection established\007\007\007"); |
#endif |
#endif |
current_line = 0; |
current_line = 0; |
sockt_mask = (1<<sockt); |
|
|
|
/* |
/* |
* Wait on both the other process (sockt_mask) and |
* Wait on both the other process (sockt_mask) and |
* standard input ( STDIN_MASK ) |
* standard input ( STDIN_MASK ) |
*/ |
*/ |
read_template = sockt_mask | STDIN_MASK; |
FD_ZERO(&read_template); |
|
FD_SET(sockt, &read_template); |
|
FD_SET(fileno(stdin), &read_template); |
for (;;) { |
for (;;) { |
read_set = read_template; |
read_set = read_template; |
wait.tv_sec = A_LONG_TIME; |
wait.tv_sec = A_LONG_TIME; |
|
|
p_error("Unexpected error from select"); |
p_error("Unexpected error from select"); |
quit(); |
quit(); |
} |
} |
if (read_set & sockt_mask) { |
if (FD_ISSET(sockt, &read_set)) { |
/* There is data on sockt */ |
/* There is data on sockt */ |
nb = read(sockt, buf, sizeof buf); |
nb = read(sockt, buf, sizeof buf); |
if (nb <= 0) { |
if (nb <= 0) { |
|
|
} |
} |
display(&his_win, buf, nb); |
display(&his_win, buf, nb); |
} |
} |
if (read_set & STDIN_MASK) { |
if (FD_ISSET(fileno(stdin), &read_set)) { |
/* |
/* |
* We can't make the tty non_blocking, because |
* We can't make the tty non_blocking, because |
* curses's output routines would screw up |
* curses's output routines would screw up |
|
|
} |
} |
} |
} |
|
|
extern int errno; |
|
extern int sys_nerr; |
|
|
|
/* |
/* |
* p_error prints the system error message on the standard location |
* p_error prints the system error message on the standard location |
* on the screen and then exits. (i.e. a curses version of perror) |
* on the screen and then exits. (i.e. a curses version of perror) |
*/ |
*/ |
|
void |
p_error(string) |
p_error(string) |
char *string; |
char *string; |
{ |
{ |
|
|
/* |
/* |
* Display string in the standard location |
* Display string in the standard location |
*/ |
*/ |
|
void |
message(string) |
message(string) |
char *string; |
char *string; |
{ |
{ |