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
, char *error_msg
, int error_code
,
42 /* A socket error has occurred. */
43 logevent(raw
->frontend
, error_msg
);
44 connection_fatal("%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 char *raw_init(void *frontend_handle
, void **backend_handle
,
71 char *host
, int port
, char **realhost
, int nodelay
)
73 static const struct plug_function_table fn_table
= {
82 raw
= smalloc(sizeof(*raw
));
85 *backend_handle
= raw
;
87 raw
->frontend
= frontend_handle
;
94 sprintf(buf
, "Looking up host \"%.170s\"", host
);
95 logevent(raw
->frontend
, buf
);
97 addr
= sk_namelookup(host
, realhost
);
98 if ((err
= sk_addr_error(addr
)))
102 port
= 23; /* default telnet port */
108 char buf
[200], addrbuf
[100];
109 sk_getaddr(addr
, addrbuf
, 100);
110 sprintf(buf
, "Connecting to %.100s port %d", addrbuf
, port
);
111 logevent(raw
->frontend
, buf
);
113 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, (Plug
) raw
);
114 if ((err
= sk_socket_error(raw
->s
)))
123 * Called to send data down the raw connection.
125 static int raw_send(void *handle
, char *buf
, int len
)
127 Raw raw
= (Raw
) handle
;
132 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
138 * Called to query the current socket sendability status.
140 static int raw_sendbuffer(void *handle
)
142 Raw raw
= (Raw
) handle
;
147 * Called to set the size of the window
149 static void raw_size(void *handle
, int width
, int height
)
156 * Send raw special codes.
158 static void raw_special(void *handle
, Telnet_Special code
)
164 static Socket
raw_socket(void *handle
)
166 Raw raw
= (Raw
) handle
;
170 static int raw_sendok(void *handle
)
175 static void raw_unthrottle(void *handle
, int backlog
)
177 Raw raw
= (Raw
) handle
;
178 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
181 static int raw_ldisc(void *handle
, int option
)
183 if (option
== LD_EDIT
|| option
== LD_ECHO
)
188 static void raw_provide_ldisc(void *handle
, void *ldisc
)
190 /* This is a stub. */
193 static void raw_provide_logctx(void *handle
, void *logctx
)
195 /* This is a stub. */
198 static int raw_exitcode(void *handle
)
200 /* Exit codes are a meaningless concept in the Raw protocol */
204 Backend raw_backend
= {