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 ed652a70e8 Get rid of #ifdef DEFINE_PLUG_METHOD_MACROS.
I don't actually know why this was ever here; it appeared in the very
first commit that invented Plug in the first place (7b0e08270) without
explanation. Perhaps Dave's original idea was that sometimes you'd
need those macros _not_ to be defined so that the same names could be
reused as the methods for a particular Plug instance? But I don't
think that ever actually happened, and the code base builds just fine
with those macros defined unconditionally just like all the other sets
of method macros we now have, so let's get rid of this piece of cruft
that was apparently unnecessary all along.
2018-10-06 07:28:51 +01:00

67 lines
1.2 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 = FROMFIELD(s, ErrorSocket, sock);
Plug *ret = es->plug;
if (p)
es->plug = p;
return ret;
}
static void sk_error_close(Socket *s)
{
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock);
sfree(es->error);
sfree(es);
}
static const char *sk_error_socket_error(Socket *s)
{
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock);
return es->error;
}
static char *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 /* flush */,
NULL /* set_frozen */,
sk_error_socket_error,
sk_error_peer_info,
};
Socket *new_error_socket(const char *errmsg, Plug *plug)
{
ErrorSocket *es = snew(ErrorSocket);
es->sock.vt = &ErrorSocket_sockvt;
es->plug = plug;
es->error = dupstr(errmsg);
return &es->sock;
}