From 9d9426785ffd4983b85e50d3df3b91635bc635a3 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 1 Sep 1999 22:16:15 +0000 Subject: [PATCH] Initial simple raw TCP backend [originally from svn r211] --- mac_res.r | 6 +++--- macterm.c | 6 ++++-- testback.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/mac_res.r b/mac_res.r index d6183a12..ad93f082 100644 --- a/mac_res.r +++ b/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.1.2.17 1999/04/02 12:58:02 ben Exp $ */ +/* $Id: mac_res.r,v 1.1.2.18 1999/09/01 22:16:15 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -556,7 +556,7 @@ resource 'pSET' (PREF_settings, "settings", purgeable) { no_implicit_copy, #define PREF_strings 1024 PREF_strings, 1, /* host 'STR#' */ - 23, prot_telnet, /* port, protocol */ + 7, prot_telnet, /* port, protocol */ PREF_strings, 2, /* termtype 'STR#' */ PREF_strings, 3, /* termspeed 'STR#' */ PREF_strings, 4, /* environmt 'STR#' */ @@ -573,7 +573,7 @@ resource 'pSET' (PREF_settings, "settings", purgeable) { resource 'STR#' (PREF_strings, "strings", purgeable) { { - "nowhere.loopback.edu", + "172.17.11.11", "xterm", "38400,38400", "\000", diff --git a/macterm.c b/macterm.c index d310ad57..7a44417f 100644 --- a/macterm.c +++ b/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.1.2.35 1999/07/24 15:51:12 ben Exp $ */ +/* $Id: macterm.c,v 1.1.2.36 1999/09/01 22:16:15 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999 Ben Harris @@ -135,7 +135,7 @@ void mac_newsession(void) { s = smalloc(sizeof(*s)); memset(s, 0, sizeof(*s)); mac_loadconfig(&s->cfg); - s->back = &null_backend; + s->back = &rawtcp_backend; /* XXX: Own storage management? */ if (HAVE_COLOR_QD()) @@ -156,11 +156,13 @@ void mac_newsession(void) { } ShowWindow(s->window); s->back->init(s); +#if 0 starttime = TickCount(); display_resource(s, 'pTST', 128); sprintf(msg, "Elapsed ticks: %d\015\012", TickCount() - starttime); inbuf_putstr(s, msg); term_out(s); +#endif } static void mac_initfont(Session *s) { diff --git a/testback.c b/testback.c index b5299a47..b3f01e90 100644 --- a/testback.c +++ b/testback.c @@ -1,4 +1,4 @@ -/* $Id: testback.c,v 1.1.2.7 1999/08/02 08:04:31 ben Exp $ */ +/* $Id: testback.c,v 1.1.2.8 1999/09/01 22:16:15 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999 Ben Harris @@ -40,6 +40,8 @@ static void loop_send(Session *, char *, int); static void hexdump_send(Session *, char *, int); static void null_size(Session *); static void null_special(Session *, Telnet_Special); +static char *rawtcp_init(Session *); +static int rawtcp_msg(Session *, SOCKET, Net_Event_Type); Backend null_backend = { null_init, null_msg, null_send, null_size, null_special @@ -53,6 +55,10 @@ Backend hexdump_backend = { null_init, null_msg, hexdump_send, null_size, null_special }; +Backend rawtcp_backend = { + rawtcp_init, rawtcp_msg, null_send, null_size, null_special +}; + static char *null_init(Session *s) { return NULL; @@ -99,6 +105,56 @@ static void null_special(Session *s, Telnet_Special code) { } +struct rawtcp_private { + SOCKET s; +}; + +static char *rawtcp_init(Session *sess) { + struct rawtcp_private *rp; + + sess->back_priv = smalloc(sizeof(struct rawtcp_private)); + rp = (struct rawtcp_private *)sess->back_priv; + rp->s = net_open(sess, sess->cfg.host, sess->cfg.port); + if (rp->s == INVALID_SOCKET) + fatalbox("Open failed"); +} + +static int rawtcp_msg(Session *sess, SOCKET sock, Net_Event_Type ne) { + struct rawtcp_private *rp = (struct rawtcp_private *)sess->back_priv; + + switch (ne) { + case NE_NULL: + break; + case NE_OPEN: + break; + case NE_NOHOST: + case NE_REFUSED: + case NE_NOOPEN: + rp->s = INVALID_SOCKET; + fatalbox("Open failed"); + break; + case NE_DATA: + break; + case NE_URGENT: + break; + case NE_CLOSING: + /* net_close(rp->s);*/ + break; + case NE_CLOSED: + rp->s = INVALID_SOCKET; + fatalbox("Connection closed"); + break; + case NE_TIMEOUT: + case NE_ABORT: + case NE_DIED: + fatalbox("Connection died"); + rp->s = INVALID_SOCKET; + break; + } +} + + + /* * Emacs magic: * Local Variables: -- 2.45.2