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
,
40 notify_remote_exit(raw
->frontend
);
43 /* A socket error has occurred. */
44 logevent(raw
->frontend
, error_msg
);
45 connection_fatal(raw
->frontend
, "%s", error_msg
);
46 } /* Otherwise, the remote side closed the connection normally. */
50 static int raw_receive(Plug plug
, int urgent
, char *data
, int len
)
53 c_write(raw
, data
, len
);
57 static void raw_sent(Plug plug
, int bufsize
)
60 raw
->bufsize
= bufsize
;
64 * Called to set up the raw connection.
66 * Returns an error message, or NULL on success.
68 * Also places the canonical host name into `realhost'. It must be
69 * freed by the caller.
71 static const char *raw_init(void *frontend_handle
, void **backend_handle
,
73 char *host
, int port
, char **realhost
, int nodelay
,
76 static const struct plug_function_table fn_table
= {
85 raw
= snew(struct raw_backend_data
);
88 *backend_handle
= raw
;
90 raw
->frontend
= frontend_handle
;
97 buf
= dupprintf("Looking up host \"%s\"", host
);
98 logevent(raw
->frontend
, buf
);
101 addr
= name_lookup(host
, port
, realhost
, cfg
);
102 if ((err
= sk_addr_error(addr
)) != NULL
) {
108 port
= 23; /* default telnet port */
114 char *buf
, addrbuf
[100];
115 sk_getaddr(addr
, addrbuf
, 100);
116 buf
= dupprintf("Connecting to %s port %d", addrbuf
, port
);
117 logevent(raw
->frontend
, buf
);
120 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, keepalive
,
122 if ((err
= sk_socket_error(raw
->s
)) != NULL
)
128 static void raw_free(void *handle
)
130 Raw raw
= (Raw
) handle
;
138 * Stub routine (we don't have any need to reconfigure this backend).
140 static void raw_reconfig(void *handle
, Config
*cfg
)
145 * Called to send data down the raw connection.
147 static int raw_send(void *handle
, char *buf
, int len
)
149 Raw raw
= (Raw
) handle
;
154 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
160 * Called to query the current socket sendability status.
162 static int raw_sendbuffer(void *handle
)
164 Raw raw
= (Raw
) handle
;
169 * Called to set the size of the window
171 static void raw_size(void *handle
, int width
, int height
)
178 * Send raw special codes.
180 static void raw_special(void *handle
, Telnet_Special code
)
187 * Return a list of the special codes that make sense in this
190 static const struct telnet_special
*raw_get_specials(void *handle
)
195 static Socket
raw_socket(void *handle
)
197 Raw raw
= (Raw
) handle
;
201 static int raw_sendok(void *handle
)
206 static void raw_unthrottle(void *handle
, int backlog
)
208 Raw raw
= (Raw
) handle
;
209 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
212 static int raw_ldisc(void *handle
, int option
)
214 if (option
== LD_EDIT
|| option
== LD_ECHO
)
219 static void raw_provide_ldisc(void *handle
, void *ldisc
)
221 /* This is a stub. */
224 static void raw_provide_logctx(void *handle
, void *logctx
)
226 /* This is a stub. */
229 static int raw_exitcode(void *handle
)
231 Raw raw
= (Raw
) handle
;
233 return -1; /* still connected */
235 /* Exit codes are a meaningless concept in the Raw protocol */
239 Backend raw_backend
= {