1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00
putty-source/network.h
Simon Tatham 988c1974ea Created a shiny new abstraction for the socket handling. Has many
advantages:
 - protocol modules can call sk_write() without having to worry
   about writes blocking, because blocking writes are handled in the
   abstraction layer and retried later.
 - `Lost connection while sending' is a thing of the past.
 - <winsock.h> is no longer needed in most modules, because
   "putty.h" doesn't have to declare `SOCKET' variables any more,
   only the abstracted `Socket' type.
 - select()-equivalent between multiple sockets will now be handled
   sensibly, which opens the way for things like SSH port
   forwarding.

[originally from svn r745]
2000-10-23 11:55:11 +00:00

45 lines
1.6 KiB
C

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