Doc: Fix broken link
[TortoiseGit.git] / src / TortoisePlink / errsock.c
blob521aa36f7a00a5b894265cfb95e0410036e1e561
1 /*
2 * A dummy Socket implementation which just holds an error message.
3 */
5 #include <stdio.h>
6 #include <assert.h>
8 #define DEFINE_PLUG_METHOD_MACROS
9 #include "tree234.h"
10 #include "putty.h"
11 #include "network.h"
13 typedef struct Socket_error_tag *Error_Socket;
15 struct Socket_error_tag {
16 const struct socket_function_table *fn;
17 /* the above variable absolutely *must* be the first in this structure */
19 char *error;
20 Plug plug;
23 static Plug sk_error_plug(Socket s, Plug p)
25 Error_Socket ps = (Error_Socket) s;
26 Plug ret = ps->plug;
27 if (p)
28 ps->plug = p;
29 return ret;
32 static void sk_error_close(Socket s)
34 Error_Socket ps = (Error_Socket) s;
36 sfree(ps->error);
37 sfree(ps);
40 static const char *sk_error_socket_error(Socket s)
42 Error_Socket ps = (Error_Socket) s;
43 return ps->error;
46 static char *sk_error_peer_info(Socket s)
48 return NULL;
51 Socket new_error_socket(const char *errmsg, Plug plug)
53 static const struct socket_function_table socket_fn_table = {
54 sk_error_plug,
55 sk_error_close,
56 NULL /* write */,
57 NULL /* write_oob */,
58 NULL /* write_eof */,
59 NULL /* flush */,
60 NULL /* set_frozen */,
61 sk_error_socket_error,
62 sk_error_peer_info,
65 Error_Socket ret;
67 ret = snew(struct Socket_error_tag);
68 ret->fn = &socket_fn_table;
69 ret->plug = plug;
70 ret->error = dupstr(errmsg);
72 return (Socket) ret;