mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
96ec2c2500
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now describe structure types themselves rather than pointers to them. The same goes for the codebase-wide trait types Socket and Plug, and the supporting types SockAddr and Pinger. All those things that were typedefed as pointers are older types; the newer ones have the explicit * at the point of use, because that's what I now seem to be preferring. But whichever one of those is better, inconsistently using a mixture of the two styles is worse, so let's make everything consistent. A few types are still implicitly pointers, such as Bignum and some of the GSSAPI types; generally this is either because they have to be void *, or because they're typedefed differently on different platforms and aren't always pointers at all. Can't be helped. But I've got rid of the main ones, at least.
68 lines
1.3 KiB
C
68 lines
1.3 KiB
C
/*
|
|
* A dummy Socket implementation which just holds an error message.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
|
|
#define DEFINE_PLUG_METHOD_MACROS
|
|
#include "tree234.h"
|
|
#include "putty.h"
|
|
#include "network.h"
|
|
|
|
typedef struct {
|
|
char *error;
|
|
Plug *plug;
|
|
|
|
const Socket_vtable *sockvt;
|
|
} ErrorSocket;
|
|
|
|
static Plug *sk_error_plug(Socket *s, Plug *p)
|
|
{
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
|
Plug *ret = es->plug;
|
|
if (p)
|
|
es->plug = p;
|
|
return ret;
|
|
}
|
|
|
|
static void sk_error_close(Socket *s)
|
|
{
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
|
|
|
sfree(es->error);
|
|
sfree(es);
|
|
}
|
|
|
|
static const char *sk_error_socket_error(Socket *s)
|
|
{
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
|
return es->error;
|
|
}
|
|
|
|
static char *sk_error_peer_info(Socket *s)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static const Socket_vtable 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->sockvt = &ErrorSocket_sockvt;
|
|
es->plug = plug;
|
|
es->error = dupstr(errmsg);
|
|
return &es->sockvt;
|
|
}
|