/* -*-C-*-
-$Id: ntfile.c,v 1.8 1997/01/05 23:38:12 cph Exp $
+$Id: ntfile.c,v 1.9 1997/06/19 05:55:34 cph Exp $
Copyright (c) 1992-97 Massachusetts Institute of Technology
Tchannel channel;
// if (hFile == STDIN_HANDLE) {
-// MAKE_CHANNEL (STDIN_HANDLE, channel_type_terminal, channel=);
+// channel = (NT_make_channel (STDIN_HANDLE, channel_type_terminal));
// CHANNEL_COOKED(channel) = 1;
// }
//
// else if (hFile == STDOUT_HANDLE) {
-// MAKE_CHANNEL (STDOUT_HANDLE, channel_type_terminal, channel=);
+// channel = (NT_make_channel (STDOUT_HANDLE, channel_type_terminal));
// CHANNEL_COOKED(channel) = 1;
// }
//
// else if (hFile == STDERR_HANDLE) {
-// MAKE_CHANNEL (STDERR_HANDLE, channel_type_terminal, channel=);
+// channel = (NT_make_channel (STDERR_HANDLE, channel_type_terminal));
// CHANNEL_COOKED(channel) = 1;
// }
// else
{
type = handle_channel_type (hFile);
- MAKE_CHANNEL (hFile, type, channel =);
+ channel = (NT_make_channel (hFile, type));
/* Like Unix, all terminals initialize to cooked mode. */
if (type == channel_type_terminal)
DEFUN (make_load_channel, (handle), HANDLE handle)
{
enum channel_type type = handle_channel_type (handle);
- if ((type == channel_type_terminal)
- || (type == channel_type_directory)
- )
- return (NO_CHANNEL);
- MAKE_CHANNEL (handle, type, return);
+ return
+ (((type == channel_type_terminal)
+ || (type == channel_type_directory))
+ ? NO_CHANNEL
+ : (NT_make_channel (handle, type)));
}
Tchannel
/* -*-C-*-
-$Id: ntio.c,v 1.14 1997/01/02 05:21:38 cph Exp $
+$Id: ntio.c,v 1.15 1997/06/19 05:55:43 cph Exp $
Copyright (c) 1992-97 Massachusetts Institute of Technology
#ifndef fileno
#define fileno(fp) ((fp)->_file)
#endif
+
+static Tchannel channel_allocate (void);
\f
+#ifndef NT_DEFAULT_CHANNEL_TABLE_SIZE
+#define NT_DEFAULT_CHANNEL_TABLE_SIZE 1024
+#endif
+
size_t OS_channel_table_size;
struct channel * channel_table;
HANDLE STDIN_HANDLE, STDOUT_HANDLE, STDERR_HANDLE;
#endif
+Tchannel
+NT_make_channel (HANDLE handle, enum channel_type type)
+{
+ Tchannel channel;
+ transaction_begin ();
+ NT_handle_close_on_abort (handle);
+ channel = (channel_allocate ());
+ NT_initialize_channel (channel, handle, type);
+ transaction_commit ();
+ return (channel);
+}
+
+void
+NT_initialize_channel (Tchannel channel, HANDLE handle, enum channel_type type)
+{
+ (CHANNEL_HANDLE (channel)) = handle;
+ (CHANNEL_TYPE (channel)) = type;
+ (CHANNEL_INTERNAL (channel)) = 0;
+ (CHANNEL_NONBLOCKING (channel)) = 0;
+ (CHANNEL_BUFFERED (channel)) = 1;
+ (CHANNEL_COOKED (channel)) = 0;
+}
+
static void
DEFUN_VOID (NT_channel_close_all)
{
}
#endif /* GUI */
-Tchannel
-DEFUN_VOID (channel_allocate)
+static Tchannel
+channel_allocate (void)
{
Tchannel channel = 0;
while (1)
DEFUN (channel_close_on_abort_1, (cp), PTR cp)
{
OS_channel_close (* ((Tchannel *) cp));
- return;
}
void
Tchannel * cp = ((Tchannel *) (dstack_alloc (sizeof (Tchannel))));
(*cp) = (channel);
transaction_record_action (tat_abort, channel_close_on_abort_1, cp);
- return;
+}
+
+static void
+NT_handle_close_on_abort_1 (void * hp)
+{
+ (void) CloseHandle (* ((HANDLE *) hp));
+}
+
+void
+NT_handle_close_on_abort (HANDLE h)
+{
+ HANDLE * hp = (dstack_alloc (sizeof (HANDLE)));
+ (*hp) = h;
+ transaction_record_action (tat_abort, NT_handle_close_on_abort_1, hp);
}
enum channel_type
OS_have_select_p = 0;
else
OS_have_select_p = 1;
- OS_channel_table_size = (NT_SC_OPEN_MAX ());
+ /* The following API call boosts the number of available handles to
+ its maximum value. This has no effect under NT, which does not
+ place a limit on the number of handles. */
+ (void) SetHandleCount (255);
+ OS_channel_table_size = NT_DEFAULT_CHANNEL_TABLE_SIZE;
channel_table = (malloc (OS_channel_table_size * (sizeof (struct channel))));
if (channel_table == 0)
{
/* -*-C-*-
-$Id: ntio.h,v 1.6 1994/11/14 00:54:27 cph Exp $
+$Id: ntio.h,v 1.7 1997/06/19 05:55:51 cph Exp $
-Copyright (c) 1992-94 Massachusetts Institute of Technology
+Copyright (c) 1992-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
#define CHANNEL_BUFFERED(channel) ((channel_table [(channel)]) . buffered)
#define CHANNEL_COOKED(channel) ((channel_table [(channel)]) . cooked)
-#define MAKE_CHANNEL(descriptor, type, receiver) \
-{ \
- Tchannel MAKE_CHANNEL_temp = (channel_allocate ()); \
- (CHANNEL_HANDLE (MAKE_CHANNEL_temp)) = (descriptor); \
- (CHANNEL_TYPE (MAKE_CHANNEL_temp)) = (type); \
- (CHANNEL_INTERNAL (MAKE_CHANNEL_temp)) = 0; \
- (CHANNEL_NONBLOCKING (MAKE_CHANNEL_temp)) = 0; \
- (CHANNEL_BUFFERED (MAKE_CHANNEL_temp)) = 1; \
- (CHANNEL_COOKED (MAKE_CHANNEL_temp)) = 0; \
- receiver (MAKE_CHANNEL_temp); \
-}
-
extern struct channel * channel_table;
-extern Tchannel EXFUN (channel_allocate, (void));
+extern Tchannel NT_make_channel (HANDLE, enum channel_type);
+extern void NT_initialize_channel (Tchannel, HANDLE, enum channel_type);
+extern void NT_handle_close_on_abort (HANDLE);
#define BACKSPACE '\b'
#define SPACE ' '