blob: 1b3a88a2560883a5b8809d08383c26827443ee9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* 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 Socket_error_tag *Error_Socket;
struct Socket_error_tag {
const struct socket_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
char *error;
Plug plug;
};
static Plug sk_error_plug(Socket s, Plug p)
{
Error_Socket ps = (Error_Socket) s;
Plug ret = ps->plug;
if (p)
ps->plug = p;
return ret;
}
static void sk_error_close(Socket s)
{
Error_Socket ps = (Error_Socket) s;
sfree(ps->error);
sfree(ps);
}
static const char *sk_error_socket_error(Socket s)
{
Error_Socket ps = (Error_Socket) s;
return ps->error;
}
Socket new_error_socket(const char *errmsg, Plug plug)
{
static const struct socket_function_table socket_fn_table = {
sk_error_plug,
sk_error_close,
NULL /* write */,
NULL /* write_oob */,
NULL /* write_eof */,
NULL /* flush */,
NULL /* set_frozen */,
sk_error_socket_error
};
Error_Socket ret;
ret = snew(struct Socket_error_tag);
ret->fn = &socket_fn_table;
ret->plug = plug;
ret->error = dupstr(errmsg);
return (Socket) ret;
}
|