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 #ifndef PUTTY_NETWORK_H
18 #define PUTTY_NETWORK_H
20 typedef struct Socket_tag
*Socket
;
21 typedef struct SockAddr_tag
*SockAddr
;
22 typedef int (*sk_receiver_t
)(Socket s
, int urgent
, char *data
, int len
);
24 void sk_init(void); /* called once at program startup */
26 SockAddr
sk_namelookup(char *host
, char **canonicalname
);
27 void sk_addr_free(SockAddr addr
);
29 Socket
sk_new(SockAddr addr
, int port
, sk_receiver_t receiver
);
30 void sk_close(Socket s
);
31 void sk_write(Socket s
, char *buf
, int len
);
32 void sk_write_oob(Socket s
, char *buf
, int len
);
35 * Each socket abstraction contains a `void *' private field in
36 * which the client can keep state.
38 void sk_set_private_ptr(Socket s
, void *ptr
);
39 void *sk_get_private_ptr(Socket s
);
42 * Special error values are returned from sk_namelookup and sk_new
43 * if there's a problem. These functions extract an error message,
44 * or return NULL if there's no problem.
46 char *sk_addr_error(SockAddr addr
);
47 char *sk_socket_error(Socket addr
);