1 /* tty.h: shared tty info for cygwin
3 Copyright 2000, 2001, 2002 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #define INP_BUFFER_SIZE 256
14 #define OUT_BUFFER_SIZE 256
16 #define real_tty_attached(p) ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
18 /* Input/Output/ioctl events */
20 #define OUTPUT_DONE_EVENT "cygtty.output.done"
21 #define IOCTL_REQUEST_EVENT "cygtty.ioctl.request"
22 #define IOCTL_DONE_EVENT "cygtty.ioctl.done"
23 #define RESTART_OUTPUT_EVENT "cygtty.output.restart"
24 #define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
25 #define OUTPUT_MUTEX "cygtty.output.mutex"
26 #define INPUT_MUTEX "cygtty.input.mutex"
27 #define TTY_SLAVE_ALIVE "cygtty.slave_alive"
28 #define TTY_MASTER_ALIVE "cygtty.master_alive"
30 #include <sys/termios.h>
32 #ifndef MIN_CTRL_C_SLOP
33 #define MIN_CTRL_C_SLOP 50
38 pid_t sid; /* Session ID of tty */
41 unsigned initialized : 1; /* Set if tty is initialized */
42 unsigned rstcons : 1; /* Set if console needs to be set to "non-cooked" */
49 DWORD last_ctrl_c; // tick count of last ctrl-c
51 IMPLEMENT_STATUS_FLAG (bool, initialized)
52 IMPLEMENT_STATUS_FLAG (bool, rstcons)
54 tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {}
55 void setntty (int n) {ntty = n;}
56 pid_t getpgid () {return pgid;}
57 void setpgid (int pid) {pgid = pid;}
58 int getsid () {return sid;}
59 void setsid (pid_t tsid) {sid = tsid;}
60 void kill_pgrp (int sig);
62 struct winsize winsize;
64 /* ioctl requests buffer */
68 struct termios termios;
69 struct winsize winsize;
73 /* XXX_retval variables holds master's completion codes. Error are stored as
81 class fhandler_pty_master;
83 class tty: public tty_min
85 HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
86 __attribute__ ((regparm (3)));
88 HWND hwnd; /* Console window handle tty belongs to */
90 DWORD master_pid; /* Win32 PID of tty master process */
92 HANDLE from_master, to_slave;
93 HANDLE from_slave, to_master;
96 bool was_opened; /* True if opened at least once. */
99 HANDLE create_inuse (const char *);
100 bool common_init (fhandler_pty_master *);
101 bool alive (const char *fmt);
103 bool master_alive ();
104 HWND gethwnd () {return hwnd;}
105 void sethwnd (HWND wnd) {hwnd = wnd;}
106 bool make_pipes (fhandler_pty_master *ptym);
107 HANDLE open_mutex (const char *mutex);
108 HANDLE open_output_mutex ();
109 HANDLE open_input_mutex ();
112 HANDLE h = open_output_mutex ();
118 return slave_alive ();
127 tty * operator [](int n) {return ttys + n;}
128 int allocate_tty (bool); /* true if allocate a tty, pty otherwise */
129 int connect_tty (int);
132 tty_min *get_tty (int n);
135 void __stdcall tty_init ();
136 void __stdcall tty_terminate ();
137 int __stdcall attach_tty (int);
138 void __stdcall create_tty_master (int);
139 extern "C" int ttyslot (void);