]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - network.h
Created a shiny new abstraction for the socket handling. Has many
[PuTTY.git] / network.h
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
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);
20
21 void sk_init(void);                    /* called once at program startup */
22
23 SockAddr sk_namelookup(char *host, char **canonicalname);
24 void sk_addr_free(SockAddr addr);
25
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);
30
31 /*
32  * Each socket abstraction contains a `void *' private field in
33  * which the client can keep state.
34  */
35 void sk_set_private_ptr(Socket s, void *ptr);
36 void *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  */
43 char *sk_addr_error(SockAddr addr);
44 char *sk_socket_error(Socket addr);