--------------------- PatchSet 6303 Date: 2007/12/16 21:37:53 Author: chtsanti Branch: async-calls Tag: (none) Log: Adding the functions comm_write_mbuf and comm_write which can accept as argument an AsyncCall Members: src/comm.cc:1.81.4.9->1.81.4.10 src/comm.h:1.26.4.6->1.26.4.7 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.81.4.9 retrieving revision 1.81.4.10 diff -u -r1.81.4.9 -r1.81.4.10 --- squid3/src/comm.cc 15 Dec 2007 15:37:51 -0000 1.81.4.9 +++ squid3/src/comm.cc 16 Dec 2007 21:37:53 -0000 1.81.4.10 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.81.4.9 2007/12/15 15:37:51 chtsanti Exp $ + * $Id: comm.cc,v 1.81.4.10 2007/12/16 21:37:53 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1657,9 +1657,18 @@ void comm_write(int fd, const char *buf, int size, IOCB * handler, void *handler_data, FREE * free_func) { + AsyncCall *call = commCbCall(5,5, "SomeCommWriteHander", + CommIoCbPtrFun(handler, handler_data)); + + comm_write(fd, buf, size, call, free_func); +} + +void +comm_write(int fd, const char *buf, int size, AsyncCall *callback, FREE * free_func) +{ assert(!fd_table[fd].flags.closing); - debugs(5, 5, "comm_write: FD " << fd << ": sz " << size << ": hndl " << handler << ": data " << handler_data << "."); + debugs(5, 5, "comm_write: FD " << fd << ": sz " << size << ": asynCall " << callback << "."); if (commio_has_callback(fd, IOCB_WRITE, COMMIO_FD_WRITECB(fd))) { /* This means that the write has been scheduled, but has not @@ -1667,19 +1676,24 @@ */ fatalf ("comm_write: fd %d: pending callback!\n", fd); } - AsyncCall *call = commCbCall(5,5, "SomeCommWriteHander", - CommIoCbPtrFun(handler, handler_data)); + commio_set_callback(fd, IOCB_WRITE, COMMIO_FD_WRITECB(fd), - call, (char *)buf, free_func, size); + callback, (char *)buf, free_func, size); commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, COMMIO_FD_WRITECB(fd), 0); } + /* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */ void comm_write_mbuf(int fd, MemBuf *mb, IOCB * handler, void *handler_data) { comm_write(fd, mb->buf, mb->size, handler, handler_data, mb->freeFunc()); } +void +comm_write_mbuf(int fd, MemBuf *mb, AsyncCall *callback) { + comm_write(fd, mb->buf, mb->size, callback, mb->freeFunc()); +} + /* * hm, this might be too general-purpose for all the places we'd Index: squid3/src/comm.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.h,v retrieving revision 1.26.4.6 retrieving revision 1.26.4.7 diff -u -r1.26.4.6 -r1.26.4.7 --- squid3/src/comm.h 15 Dec 2007 15:37:51 -0000 1.26.4.6 +++ squid3/src/comm.h 16 Dec 2007 21:37:53 -0000 1.26.4.7 @@ -59,7 +59,9 @@ SQUIDCEXTERN int comm_udp_sendto(int, const struct sockaddr_in *, int, const void *, int); extern void comm_write(int fd, const char *buf, int len, IOCB *callback, void *callback_data, FREE *func); +extern void comm_write(int fd, const char *buf, int size, AsyncCall *callback, FREE * free_func = NULL); SQUIDCEXTERN void comm_write_mbuf(int fd, MemBuf *mb, IOCB * handler, void *handler_data); +extern void comm_write_mbuf(int fd, MemBuf *mb, AsyncCall *callback); SQUIDCEXTERN void commCallCloseHandlers(int fd); SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *); SQUIDCEXTERN int ignoreErrno(int);