diff options
author | Simon Tatham <anakin@pobox.com> | 2020-03-11 00:06:29 +0300 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2020-03-11 00:06:29 +0300 |
commit | b4e1bca2c31b830503921ae96412b2b00aa86fac (patch) | |
tree | cfe1dfad510921fd63d1385402c0a2d11cc67954 /psocks.c | |
parent | ade10f13040474b8fecf0427e14cc34f481d5f0b (diff) |
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.
We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.
The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.
While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
Diffstat (limited to 'psocks.c')
-rw-r--r-- | psocks.c | 65 |
1 files changed, 13 insertions, 52 deletions
@@ -72,31 +72,9 @@ static SshChannel *psocks_lportfwd_open( ConnectionLayer *cl, const char *hostname, int port, const char *description, const SocketPeerInfo *pi, Channel *chan); -static const struct ConnectionLayerVtable psocks_clvt = { - NULL /* rportfwd_alloc */, - NULL /* rportfwd_remove */, - psocks_lportfwd_open, - NULL /* session_open */, - NULL /* serverside_x11_open */, - NULL /* serverside_agent_open */, - NULL /* add_x11_display */, - NULL /* add_sharing_x11_display */, - NULL /* remove_sharing_x11_display */, - NULL /* send_packet_from_downstream */, - NULL /* alloc_sharing_channel */, - NULL /* delete_sharing_channel */, - NULL /* sharing_queue_global_request */, - NULL /* sharing_no_more_downstreams */, - NULL /* agent_forwarding_permitted */, - NULL /* terminal_size */, - NULL /* stdout_unthrottle */, - NULL /* stdin_backlog */, - NULL /* throttle_all_channels */, - NULL /* ldisc_option */, - NULL /* set_ldisc_option */, - NULL /* enable_x_fwd */, - NULL /* enable_agent_fwd */, - NULL /* set_wants_user_input */, +static const ConnectionLayerVtable psocks_clvt = { + .lportfwd_open = psocks_lportfwd_open, + /* everything else is NULL */ }; static size_t psocks_sc_write(SshChannel *sc, bool is_stderr, const void *, @@ -105,28 +83,12 @@ static void psocks_sc_write_eof(SshChannel *sc); static void psocks_sc_initiate_close(SshChannel *sc, const char *err); static void psocks_sc_unthrottle(SshChannel *sc, size_t bufsize); -static const struct SshChannelVtable psocks_scvt = { - psocks_sc_write, - psocks_sc_write_eof, - psocks_sc_initiate_close, - psocks_sc_unthrottle, - NULL /* get_conf */, - NULL /* window_override_removed */, - NULL /* x11_sharing_handover */, - NULL /* send_exit_status */, - NULL /* send_exit_signal */, - NULL /* send_exit_signal_numeric */, - NULL /* request_x11_forwarding */, - NULL /* request_agent_forwarding */, - NULL /* request_pty */, - NULL /* send_env_var */, - NULL /* start_shell */, - NULL /* start_command */, - NULL /* start_subsystem */, - NULL /* send_serial_break */, - NULL /* send_signal */, - NULL /* send_terminal_size_change */, - NULL /* hint_channel_is_simple */, +static const SshChannelVtable psocks_scvt = { + .write = psocks_sc_write, + .write_eof = psocks_sc_write_eof, + .initiate_close = psocks_sc_initiate_close, + .unthrottle = psocks_sc_unthrottle, + /* all the rest are NULL */ }; static void psocks_plug_log(Plug *p, PlugLogType type, SockAddr *addr, @@ -138,11 +100,10 @@ static void psocks_plug_receive(Plug *p, int urgent, static void psocks_plug_sent(Plug *p, size_t bufsize); static const PlugVtable psocks_plugvt = { - psocks_plug_log, - psocks_plug_closing, - psocks_plug_receive, - psocks_plug_sent, - NULL /* accepting */, + .log = psocks_plug_log, + .closing = psocks_plug_closing, + .receive = psocks_plug_receive, + .sent = psocks_plug_sent, }; static void psocks_conn_log(psocks_connection *conn, const char *fmt, ...) |