--------------------- PatchSet 1611 Date: 2001/02/19 21:39:10 Author: hno Branch: eventio Tag: (none) Log: Specification of the new improved network I/O model being implemented. Members: doc/Programming-Guide/prog-guide.sgml:1.9->1.9.8.1 Index: squid/doc/Programming-Guide/prog-guide.sgml =================================================================== RCS file: /cvsroot/squid-sf//squid/doc/Programming-Guide/prog-guide.sgml,v retrieving revision 1.9 retrieving revision 1.9.8.1 diff -u -r1.9 -r1.9.8.1 --- squid/doc/Programming-Guide/prog-guide.sgml 31 Jan 2001 22:20:26 -0000 1.9 +++ squid/doc/Programming-Guide/prog-guide.sgml 19 Feb 2001 21:39:10 -0000 1.9.8.1 @@ -2,7 +2,7 @@
Squid Programmers Guide Duane Wessels, Squid Developers -$Id: prog-guide.sgml,v 1.9 2001/01/31 22:20:26 hno Exp $ +$Id: prog-guide.sgml,v 1.9.8.1 2001/02/19 21:39:10 hno Exp $ Squid is a WWW Cache application developed by the National Laboratory @@ -2988,4 +2988,175 @@ that pointer was last accessed. If there is a leak, then the bug occurs somewhere after that point of the code. +Network I/O + +

+ The networking I/O layer is responsible for all network I/O (duh!). + +

+ It is implemented as a set of asyncronous operations for opening / + acception connections and reading/writing data on those connections. + The asyncronous operation means that each API call will only initiate + the operation, and when the operation s finished a supplied callback + function will be called. + +

+ Created filehandles are cbdata enabled, and any links / pointers to + filehandles should be properly managed as cbdata. + +

+ The return value of is 0 on success or -1 on error. On error, errno + will be set to a suitable error code. + +API + +ncomm_close + +

+ int + ncomm_close(filehandle *fh); + + +

+ Closes down the socket once all pending data has been sent. + +ncomm_abort + +

+ int + ncomm_abort(filehandle *fh); + + +

+ Aborts the given network connection immediately. Any pending I/O + requests will be aborted. + +ncomm_listen + +

+ int + ncomm_listen(int sock_type, int proto, struct sockaddr *where, int addrsize, COMMNEWCB *callback, void *cbdata) + + +

+ start listening for new connections on the given address/port. + +ncomm_accept + +

+ int + ncomm_accept(int sock_type, int proto, struct sockaddr *where, struct sockaddr *from, int addrsize, COMMNEWCB callback, void *cbdata) + + +

+ Like comm_listen, but only accept connections from the given source + +ncomm_connect + +

+ int + ncomm_connect(int sock_type, int proto, const struct sockaddr *local, const struct sockaddr *remote, int addrsize, COMMNEWCB *callback, void *data) + + +

+ Creates a new network connection to the given remote address, + optionally using a specified local source address. + +ncomm_read + +

+ void + ncomm_read(filehandle *fh, IOBUF *buf, size_t min_size, size_t max_size, COMMIOCB *callback, void *data); + + +

+ request to read some data. buf might be specified as NULL in which case + a IOBUF will be allocated to keep the data read from the network. + +

+ Any errors will be signalled to the callback function. + +ncomm_write + +

+ void + ncomm_write(filehandle *fh, IOBUF *buf, off_t offset, size_t size, COMMIOCB *callback, void *data); + + +

+ request to write some data. + +

+ if size is 0 then all data in the buffer will be written. + +

+ it is allowable to queue more write requests before the first has + finished. The requests will be processed in the order requested. + +

+ Any errors will be signalled to the callback function. + +ncomm_add_close_handler + +

+ int + ncomm_add_close_handler(filehandle *fh, COMMCLOSECB *handler, void *cbdata); + + +

+ Registers a close handler what will be called when the socket is closed. + For example to clean up associated data structures or keep relations + proper. + +ncomm_abort_all_connections + +

+ void + ncomm_abort_all_connections(void); + + +

+ Aborts all currently open network connections. + +callbacks + +COMMNEWCB + +

+ typedef void + COMMNEWCB(filehandle *fh, struct sockaddr *local, struct sockaddr *peer, void *cbdata); + + +

+ Called when a new filehandle is created (ncomm_listen / ncomm_accept + / ncomm_connect) + +COMMIOCB + +

+ typedef void + COMMIOCB(filehandle *fh, IOBUF *buf, int offset, int size, int errno, void *cbdata); + + +

+ Called when an I/O operation has finished. + +

+ On error, errno will be set to the error verb. + +COMMCLOSECB + +

+ typedef void + COMMCLOSECB(filehandle *fh, void *cbdata); + + +

+ Called when the filehandle is closed (ncomm_close / ncomm_abort), as + requested (ncomm_add_close_handler) +