1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/errsock.c
Simon Tatham 9545199ea5 Completely remove sk_flush().
I've only just noticed that it doesn't do anything at all!

Almost every implementation of the Socket vtable provides a flush()
method which does nothing, optionally with a comment explaining why
it's OK to do nothing. The sole exception is the wrapper Proxy_Socket,
which implements the method during its setup phase by setting a
pending_flush flag, so that when its sub-socket is later created, it
can call sk_flush on that. But since the sub-socket's sk_flush will do
nothing, even that is completely pointless!

Source control history says that sk_flush was introduced by Dave
Hinton in 2001 (commit 7b0e08270), who was going to use it for some
purpose involving the SSL Telnet support he was working on at the
time. That SSL support was never finished, and its vestigial
declarations in network.h were removed in 2015 (commit 42334b65b). So
sk_flush is just another vestige of that abandoned work, which I
should have removed in the latter commit but overlooked.
2019-07-28 10:40:47 +01:00

78 lines
1.4 KiB
C

/*
* A dummy Socket implementation which just holds an error message.
*/
#include <stdio.h>
#include <assert.h>
#include "tree234.h"
#include "putty.h"
#include "network.h"
typedef struct {
char *error;
Plug *plug;
Socket sock;
} ErrorSocket;
static Plug *sk_error_plug(Socket *s, Plug *p)
{
ErrorSocket *es = container_of(s, ErrorSocket, sock);
Plug *ret = es->plug;
if (p)
es->plug = p;
return ret;
}
static void sk_error_close(Socket *s)
{
ErrorSocket *es = container_of(s, ErrorSocket, sock);
sfree(es->error);
sfree(es);
}
static const char *sk_error_socket_error(Socket *s)
{
ErrorSocket *es = container_of(s, ErrorSocket, sock);
return es->error;
}
static SocketPeerInfo *sk_error_peer_info(Socket *s)
{
return NULL;
}
static const SocketVtable ErrorSocket_sockvt = {
sk_error_plug,
sk_error_close,
NULL /* write */,
NULL /* write_oob */,
NULL /* write_eof */,
NULL /* set_frozen */,
sk_error_socket_error,
sk_error_peer_info,
};
static Socket *new_error_socket_internal(char *errmsg, Plug *plug)
{
ErrorSocket *es = snew(ErrorSocket);
es->sock.vt = &ErrorSocket_sockvt;
es->plug = plug;
es->error = errmsg;
return &es->sock;
}
Socket *new_error_socket_fmt(Plug *plug, const char *fmt, ...)
{
va_list ap;
char *msg;
va_start(ap, fmt);
msg = dupvprintf(fmt, ap);
va_end(ap);
return new_error_socket_internal(msg, plug);
}