14 #define RAW_MAX_BACKLOG 4096
16 typedef struct raw_backend_data
{
17 const struct plug_function_table
*fn
;
18 /* the above field _must_ be first in the structure */
25 static void raw_size(void *handle
, int width
, int height
);
27 static void c_write(Raw raw
, char *buf
, int len
)
29 int backlog
= from_backend(raw
->frontend
, 0, buf
, len
);
30 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
33 static int raw_closing(Plug plug
, char *error_msg
, int error_code
,
43 /* A socket error has occurred. */
45 connection_fatal("%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 char *raw_init(void *frontend_handle
, void **backend_handle
,
72 char *host
, int port
, char **realhost
, int nodelay
)
74 static const struct plug_function_table fn_table
= {
83 raw
= smalloc(sizeof(*raw
));
86 *backend_handle
= raw
;
88 raw
->frontend
= frontend_handle
;
95 sprintf(buf
, "Looking up host \"%.170s\"", host
);
98 addr
= sk_namelookup(host
, realhost
);
99 if ((err
= sk_addr_error(addr
)))
103 port
= 23; /* default telnet port */
109 char buf
[200], addrbuf
[100];
110 sk_getaddr(addr
, addrbuf
, 100);
111 sprintf(buf
, "Connecting to %.100s port %d", addrbuf
, port
);
114 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, (Plug
) raw
);
115 if ((err
= sk_socket_error(raw
->s
)))
124 * Called to send data down the raw connection.
126 static int raw_send(void *handle
, char *buf
, int len
)
128 Raw raw
= (Raw
) handle
;
133 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
139 * Called to query the current socket sendability status.
141 static int raw_sendbuffer(void *handle
)
143 Raw raw
= (Raw
) handle
;
148 * Called to set the size of the window
150 static void raw_size(void *handle
, int width
, int height
)
157 * Send raw special codes.
159 static void raw_special(void *handle
, Telnet_Special code
)
165 static Socket
raw_socket(void *handle
)
167 Raw raw
= (Raw
) handle
;
171 static int raw_sendok(void *handle
)
176 static void raw_unthrottle(void *handle
, int backlog
)
178 Raw raw
= (Raw
) handle
;
179 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
182 static int raw_ldisc(void *handle
, int option
)
184 if (option
== LD_EDIT
|| option
== LD_ECHO
)
189 static void raw_provide_ldisc(void *handle
, void *ldisc
)
191 /* This is a stub. */
194 static int raw_exitcode(void *handle
)
196 /* Exit codes are a meaningless concept in the Raw protocol */
200 Backend raw_backend
= {