13 #define RAW_MAX_BACKLOG 4096
15 typedef struct raw_backend_data {
16 const struct plug_function_table *fn;
17 /* the above field _must_ be first in the structure */
24 static void raw_size(void *handle, int width, int height);
26 static void c_write(Raw raw, char *buf, int len)
28 int backlog = from_backend(raw->frontend, 0, buf, len);
29 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
32 static int raw_closing(Plug plug, const char *error_msg, int error_code,
42 /* A socket error has occurred. */
43 logevent(raw->frontend, error_msg);
44 connection_fatal(raw->frontend, "%s", error_msg);
45 } /* Otherwise, the remote side closed the connection normally. */
49 static int raw_receive(Plug plug, int urgent, char *data, int len)
52 c_write(raw, data, len);
56 static void raw_sent(Plug plug, int bufsize)
59 raw->bufsize = bufsize;
63 * Called to set up the raw connection.
65 * Returns an error message, or NULL on success.
67 * Also places the canonical host name into `realhost'. It must be
68 * freed by the caller.
70 static const char *raw_init(void *frontend_handle, void **backend_handle,
72 char *host, int port, char **realhost, int nodelay,
75 static const struct plug_function_table fn_table = {
84 raw = snew(struct raw_backend_data);
87 *backend_handle = raw;
89 raw->frontend = frontend_handle;
96 buf = dupprintf("Looking up host \"%s\"", host);
97 logevent(raw->frontend, buf);
100 addr = name_lookup(host, port, realhost, cfg);
101 if ((err = sk_addr_error(addr)) != NULL) {
107 port = 23; /* default telnet port */
113 char *buf, addrbuf[100];
114 sk_getaddr(addr, addrbuf, 100);
115 buf = dupprintf("Connecting to %s port %d", addrbuf, port);
116 logevent(raw->frontend, buf);
119 raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
121 if ((err = sk_socket_error(raw->s)) != NULL)
127 static void raw_free(void *handle)
129 Raw raw = (Raw) handle;
137 * Stub routine (we don't have any need to reconfigure this backend).
139 static void raw_reconfig(void *handle, Config *cfg)
144 * Called to send data down the raw connection.
146 static int raw_send(void *handle, char *buf, int len)
148 Raw raw = (Raw) handle;
153 raw->bufsize = sk_write(raw->s, buf, len);
159 * Called to query the current socket sendability status.
161 static int raw_sendbuffer(void *handle)
163 Raw raw = (Raw) handle;
168 * Called to set the size of the window
170 static void raw_size(void *handle, int width, int height)
177 * Send raw special codes.
179 static void raw_special(void *handle, Telnet_Special code)
186 * Return a list of the special codes that make sense in this
189 static const struct telnet_special *raw_get_specials(void *handle)
194 static Socket raw_socket(void *handle)
196 Raw raw = (Raw) handle;
200 static int raw_sendok(void *handle)
205 static void raw_unthrottle(void *handle, int backlog)
207 Raw raw = (Raw) handle;
208 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
211 static int raw_ldisc(void *handle, int option)
213 if (option == LD_EDIT || option == LD_ECHO)
218 static void raw_provide_ldisc(void *handle, void *ldisc)
220 /* This is a stub. */
223 static void raw_provide_logctx(void *handle, void *logctx)
225 /* This is a stub. */
228 static int raw_exitcode(void *handle)
230 Raw raw = (Raw) handle;
232 return -1; /* still connected */
234 /* Exit codes are a meaningless concept in the Raw protocol */
238 Backend raw_backend = {