1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00
putty-source/nullplug.c
Simon Tatham b4e1bca2c3 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.
2020-03-10 21:06:29 +00:00

43 lines
1.1 KiB
C

/*
* nullplug.c: provide a null implementation of the Plug vtable which
* ignores all calls. Occasionally useful in cases where we want to
* make a network connection just to see if it works, but not do
* anything with it afterwards except close it again.
*/
#include "putty.h"
static void nullplug_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
int port, const char *err_msg, int err_code)
{
}
static void nullplug_closing(Plug *plug, const char *error_msg, int error_code,
bool calling_back)
{
}
static void nullplug_receive(
Plug *plug, int urgent, const char *data, size_t len)
{
}
static void nullplug_sent(Plug *plug, size_t bufsize)
{
}
static const PlugVtable nullplug_plugvt = {
.log = nullplug_socket_log,
.closing = nullplug_closing,
.receive = nullplug_receive,
.sent = nullplug_sent,
};
static Plug nullplug_plug = { &nullplug_plugvt };
/*
* There's a singleton instance of nullplug, because it's not
* interesting enough to worry about making more than one of them.
*/
Plug *const nullplug = &nullplug_plug;