Created a shiny new abstraction for the socket handling. Has many
[u/mdw/putty] / network.h
CommitLineData
2f75bae1 1/*
2 * Networking abstraction in PuTTY.
3 *
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.
11 *
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.
15 */
16
17typedef struct Socket_tag *Socket;
18typedef struct SockAddr_tag *SockAddr;
19typedef int (*sk_receiver_t)(Socket s, int urgent, char *data, int len);
20
21void sk_init(void); /* called once at program startup */
22
23SockAddr sk_namelookup(char *host, char **canonicalname);
24void sk_addr_free(SockAddr addr);
25
26Socket sk_new(SockAddr addr, int port, sk_receiver_t receiver);
27void sk_close(Socket s);
28void sk_write(Socket s, char *buf, int len);
29void sk_write_oob(Socket s, char *buf, int len);
30
31/*
32 * Each socket abstraction contains a `void *' private field in
33 * which the client can keep state.
34 */
35void sk_set_private_ptr(Socket s, void *ptr);
36void *sk_get_private_ptr(Socket s);
37
38/*
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.
42 */
43char *sk_addr_error(SockAddr addr);
44char *sk_socket_error(Socket addr);