Fix typos
[TortoiseGit.git] / src / TortoisePlink / errsock.c
blobfd56913dd72273b5fcbdd2928e87daf976c5ce2e
1 /*
2 * A dummy Socket implementation which just holds an error message.
3 */
5 #include <stdio.h>
6 #include <assert.h>
8 #include "tree234.h"
9 #include "putty.h"
10 #include "network.h"
12 typedef struct {
13 char *error;
14 Plug *plug;
16 Socket sock;
17 } ErrorSocket;
19 static Plug *sk_error_plug(Socket *s, Plug *p)
21 ErrorSocket *es = container_of(s, ErrorSocket, sock);
22 Plug *ret = es->plug;
23 if (p)
24 es->plug = p;
25 return ret;
28 static void sk_error_close(Socket *s)
30 ErrorSocket *es = container_of(s, ErrorSocket, sock);
32 sfree(es->error);
33 sfree(es);
36 static const char *sk_error_socket_error(Socket *s)
38 ErrorSocket *es = container_of(s, ErrorSocket, sock);
39 return es->error;
42 static SocketPeerInfo *sk_error_peer_info(Socket *s)
44 return NULL;
47 static const SocketVtable ErrorSocket_sockvt = {
48 .plug = sk_error_plug,
49 .close = sk_error_close,
50 .socket_error = sk_error_socket_error,
51 .peer_info = sk_error_peer_info,
52 /* other methods are NULL */
55 Socket *new_error_socket_consume_string(Plug *plug, char *errmsg)
57 ErrorSocket *es = snew(ErrorSocket);
58 es->sock.vt = &ErrorSocket_sockvt;
59 es->plug = plug;
60 es->error = errmsg;
61 return &es->sock;
64 Socket *new_error_socket_fmt(Plug *plug, const char *fmt, ...)
66 va_list ap;
67 char *msg;
69 va_start(ap, fmt);
70 msg = dupvprintf(fmt, ap);
71 va_end(ap);
73 return new_error_socket_consume_string(plug, msg);