1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-31 10:34:32 -05:00

Modernise the Socket/Plug vtable system.

Now I've got FROMFIELD, I can rework it so that structures providing
an implementation of the Socket or Plug trait no longer have to have
the vtable pointer as the very first thing in the structure. In
particular, this means that the ProxySocket structure can now directly
implement _both_ the Socket and Plug traits, which is always
_logically_ how it's worked, but previously it had to be implemented
via two separate structs linked to each other.
This commit is contained in:
Simon Tatham
2018-05-27 09:29:33 +01:00
parent 0fc2d3b455
commit 5129c40bea
24 changed files with 675 additions and 734 deletions

View File

@@ -171,9 +171,6 @@ static const struct Opt *const opts[] = {
};
typedef struct telnet_tag {
const struct plug_function_table *fn;
/* the above field _must_ be first in the structure */
Socket s;
int closed_on_socket_error;
@@ -200,6 +197,8 @@ typedef struct telnet_tag {
Conf *conf;
Pinger pinger;
const Plug_vtable *plugvt;
} *Telnet;
#define TELNET_MAX_BACKLOG 4096
@@ -645,7 +644,7 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
static void telnet_log(Plug plug, int type, SockAddr addr, int port,
const char *error_msg, int error_code)
{
Telnet telnet = (Telnet) plug;
Telnet telnet = FROMFIELD(plug, struct telnet_tag, plugvt);
backend_socket_log(telnet->frontend, type, addr, port,
error_msg, error_code, telnet->conf,
telnet->session_started);
@@ -654,7 +653,7 @@ static void telnet_log(Plug plug, int type, SockAddr addr, int port,
static void telnet_closing(Plug plug, const char *error_msg, int error_code,
int calling_back)
{
Telnet telnet = (Telnet) plug;
Telnet telnet = FROMFIELD(plug, struct telnet_tag, plugvt);
/*
* We don't implement independent EOF in each direction for Telnet
@@ -678,7 +677,7 @@ static void telnet_closing(Plug plug, const char *error_msg, int error_code,
static void telnet_receive(Plug plug, int urgent, char *data, int len)
{
Telnet telnet = (Telnet) plug;
Telnet telnet = FROMFIELD(plug, struct telnet_tag, plugvt);
if (urgent)
telnet->in_synch = TRUE;
telnet->session_started = TRUE;
@@ -687,10 +686,17 @@ static void telnet_receive(Plug plug, int urgent, char *data, int len)
static void telnet_sent(Plug plug, int bufsize)
{
Telnet telnet = (Telnet) plug;
Telnet telnet = FROMFIELD(plug, struct telnet_tag, plugvt);
telnet->bufsize = bufsize;
}
static const Plug_vtable Telnet_plugvt = {
telnet_log,
telnet_closing,
telnet_receive,
telnet_sent
};
/*
* Called to set up the Telnet connection.
*
@@ -703,12 +709,6 @@ static const char *telnet_init(void *frontend_handle, void **backend_handle,
Conf *conf, const char *host, int port,
char **realhost, int nodelay, int keepalive)
{
static const struct plug_function_table fn_table = {
telnet_log,
telnet_closing,
telnet_receive,
telnet_sent
};
SockAddr addr;
const char *err;
Telnet telnet;
@@ -716,7 +716,7 @@ static const char *telnet_init(void *frontend_handle, void **backend_handle,
int addressfamily;
telnet = snew(struct telnet_tag);
telnet->fn = &fn_table;
telnet->plugvt = &Telnet_plugvt;
telnet->conf = conf_copy(conf);
telnet->s = NULL;
telnet->closed_on_socket_error = FALSE;
@@ -751,8 +751,8 @@ static const char *telnet_init(void *frontend_handle, void **backend_handle,
/*
* Open socket.
*/
telnet->s = new_connection(addr, *realhost, port, 0, 1,
nodelay, keepalive, (Plug) telnet, telnet->conf);
telnet->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
&telnet->plugvt, telnet->conf);
if ((err = sk_socket_error(telnet->s)) != NULL)
return err;