# 2.11BSD#431 - /usr/src/ucb/talk/io.c

##### Functions

    message           X
    p_error           X
    talk              X

##### Macros

    A_LONG_TIME       X
    STDIN_MASK        X

       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: #if !defined(lint) && defined(DOSCCS)
       8: static char sccsid[] = "@(#)io.c	5.1.1 (2.11BSD) 1996/3/22";
       9: #endif
      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 <string.h>
      21: #include <sys/time.h>
      22:
      23: #define A_LONG_TIME 10000000
      24: #define STDIN_MASK (1L<<fileno(stdin))  /* the bit mask for standard
      25: 					   input */
      26: extern int errno;
      27:
      28: /*
      29:  * The routine to do the actual talking
      30:  */
      31: talk()
      32: {
      33:     register long read_template, sockt_mask;
      34:     long read_set;
      35:     int nb;
      36:     long nbl;
      37:     char buf[BUFSIZ];
      38:     struct timeval wait;
      39:
      40:     message("Connection established\007\007\007");
      41:     current_line = 0;
      42:     sockt_mask = (1L<<sockt);
      43:
      44:     /*
      45: 	 * Wait on both the other process (sockt_mask) and
      46: 	 * standard input ( STDIN_MASK )
      47: 	 */
      48:     read_template = sockt_mask | STDIN_MASK;
      49:     forever {
      50:         read_set = read_template;
      51:         wait.tv_sec = A_LONG_TIME;
      52:         wait.tv_usec = 0;
      53:         nb = select(32, &read_set, (long *)0, (long *)0, &wait);
      54:         if (nb <= 0) {
      55:             if (errno == EINTR) {
      56:                 read_set = read_template;
      57:                 continue;
      58:             }
      59:             /* panic, we don't know what happened */
      60:             p_error("Unexpected error from select");
      61:             quit();
      62:         }
      63:         if (read_set & sockt_mask) {
      64:             /* There is data on sockt */
      65:             nb = read(sockt, buf, sizeof buf);
      66:             if (nb <= 0) {
      67:                 message("Connection closed. Exiting");
      68:                 quit();
      69:             }
      70:             display(&his_win, buf, nb);
      71:         }
      72:         if (read_set & STDIN_MASK) {
      73:             /*
      74: 			 * We can't make the tty non_blocking, because
      75: 			 * curses's output routines would screw up
      76: 			 */
      77:             ioctl(0, FIONREAD, (struct sgttyb *) &nbl);
      78:             nb = read(0, buf, (int)nbl);
      79:             display(&my_win, buf, nb);
      80:             /* might lose data here because sockt is non-blocking */
      81:             write(sockt, buf, nb);
      82:         }
      83:     }
      84: }
      85:
      86: /*
      87:  * p_error prints the system error message on the standard location
      88:  * on the screen and then exits. (i.e. a curses version of perror)
      89:  */
      90: p_error(string)
      91:     char *string;
      92: {
      93:     char *sys;
      94:
      95:     sys = strerror(errno);
      96:     wmove(my_win.x_win, current_line%my_win.x_nlines, 0);
      97:     wprintw(my_win.x_win, "[%s : %s (%d)]\n", string, sys, errno);
      98:     wrefresh(my_win.x_win);
      99:     move(LINES-1, 0);
     100:     refresh();
     101:     quit();
     102: }
     103:
     104: /*
     105:  * Display string in the standard location
     106:  */
     107: message(string)
     108:     char *string;
     109: {
     110:
     111:     wmove(my_win.x_win, current_line%my_win.x_nlines, 0);
     112:     wprintw(my_win.x_win, "[%s]\n", string);
     113:     wrefresh(my_win.x_win);
     114: }

#### Defined functions

message defined in line 107; used 8 times

- in line 40, 67
- in /usr/src/ucb/talk/init_disp.c line 98
- in /usr/src/ucb/talk/invite.c line 54, 86, 119
- in /usr/src/ucb/talk/msgs.c line 34, 40

p_error defined in line 90; used 16 times

- in line 60
- in /usr/src/ucb/talk/ctl.c line 43-48(3), 60-65(3)
- in /usr/src/ucb/talk/ctl_transact.c line 50, 57, 70
- in /usr/src/ucb/talk/init_disp.c line 85-88(2)
- in /usr/src/ucb/talk/invite.c line 42, 60
- in /usr/src/ucb/talk/look_up.c line 34, 51

talk defined in line 31; used 1 times

- in /usr/src/ucb/talk/talk.c line 47

#### Defined variables

sccsid defined in line 8; never used

#### Defined macros

A_LONG_TIME defined in line 23; used 1 times

- in line 51

STDIN_MASK defined in line 24; used 2 times

- in line 48, 72

Last modified: 1996-03-23 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1310 |