2 * Networking abstraction in PuTTY.
4 * The way this works is: a back end can choose to open any number
5 * of sockets - including zero, which might be necessary in some.
6 * It can register a function to be called when data comes in on
7 * any given one, and it can call the networking abstraction to
8 * send data without having to worry about blocking. The stuff
9 * behind the abstraction takes care of selects and nonblocking
10 * writes and all that sort of painful gubbins.
12 * If urgent data comes in on a socket, the back end will read and
13 * discard up to the urgent pointer, then read the urgent byte and
14 * send _that_ to the receiver function with `urgent' set.
17 typedef struct Socket_tag
*Socket
;
18 typedef struct SockAddr_tag
*SockAddr
;
19 typedef int (*sk_receiver_t
)(Socket s
, int urgent
, char *data
, int len
);
21 void sk_init(void); /* called once at program startup */
23 SockAddr
sk_namelookup(char *host
, char **canonicalname
);
24 void sk_addr_free(SockAddr addr
);
26 Socket
sk_new(SockAddr addr
, int port
, sk_receiver_t receiver
);
27 void sk_close(Socket s
);
28 void sk_write(Socket s
, char *buf
, int len
);
29 void sk_write_oob(Socket s
, char *buf
, int len
);
32 * Each socket abstraction contains a `void *' private field in
33 * which the client can keep state.
35 void sk_set_private_ptr(Socket s
, void *ptr
);
36 void *sk_get_private_ptr(Socket s
);
39 * Special error values are returned from sk_namelookup and sk_new
40 * if there's a problem. These functions extract an error message,
41 * or return NULL if there's no problem.
43 char *sk_addr_error(SockAddr addr
);
44 char *sk_socket_error(Socket addr
);