/*
- * $Id: comm.cc,v 1.386 2003/08/04 22:14:41 robertc Exp $
+ * $Id: comm.cc,v 1.387 2003/08/15 13:06:34 robertc Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
CommRead read;
+ bool hasIncompleteWrite();
+
+ template<class P>
+ bool findCallback(P predicate);
+
CommWrite write;
class Accept
*
* Assumptions: the fd is open (ie, its not closing)
*/
+
+struct FindReadCallback
+{
+ bool operator () (CommCallbackData *cd)
+ {
+ return cd->getType() == COMM_CB_READ;
+ }
+};
+
+
int
comm_has_pending_read_callback(int fd)
{
- dlink_node *node;
- CommCallbackData *cd;
-
requireOpenAndActive(fd);
+ if (fdc_table[fd].findCallback(FindReadCallback()))
+ return 1;
+
+ return 0;
+}
+
+template <class P>
+bool
+fdc_t::findCallback(P predicate)
+{
/*
* XXX I don't like having to walk the list!
* Instead, if this routine is called often enough, we should
* check if the list head a HEAD..
* - adrian
*/
- node = fdc_table[fd].CommCallbackList.head;
+ dlink_node *node = CommCallbackList.head;
while (node != NULL) {
- cd = (CommCallbackData *)node->data;
-
- if (cd->getType() == COMM_CB_READ)
- return 1;
+ if (predicate((CommCallbackData *)node->data))
+ return true;
node = node->next;
}
/* Not found */
- return 0;
+ return false;
}
/*
/*
* The new-style comm_write magic
*/
+
+struct FindWriteCallback
+{
+ bool operator () (CommCallbackData *cd)
+ {
+ return dynamic_cast<CommWriteCallbackData *>(cd) != NULL;
+ }
+};
+
+bool
+comm_has_incomplete_write(int fd)
+{
+ requireOpenAndActive(fd);
+
+ if (fdc_table[fd].hasIncompleteWrite())
+ return true;
+
+ return (fdc_table[fd].findCallback(FindWriteCallback()));
+}
+
+bool
+fdc_t::hasIncompleteWrite()
+{
+ return write.handler != NULL;
+}
+
/*
* Attempt a write
*
assert(fdc_table[fd].write.handler == NULL);
assert(!fd_table[fd].flags.closing);
+ /* Can't queue a write with no callback */
+ assert(handler);
+
/* Queue a read */
fdc_table[fd].write.buf = buf;
fdc_table[fd].write.size = size;
/*
- * $Id: pconn.cc,v 1.39 2003/06/23 12:11:45 robertc Exp $
+ * $Id: pconn.cc,v 1.40 2003/08/15 13:06:34 robertc Exp $
*
* DEBUG: section 48 Persistent Connections
* AUTHOR: Duane Wessels
xfree(old);
}
+ assert(!comm_has_incomplete_write(fd));
p->fds[p->nfds++] = fd;
comm_read(fd, p->buf, BUFSIZ, pconnRead, p);
commSetTimeout(fd, Config.Timeout.pconn, pconnTimeout, p);