$Log$
+ Revision 611.1 2003/11/06 04:25:30 ajc
+ * For certain IMAP outputs (such as BODYSTRUCTURE), buffer all output until
+ we've got the whole thing, then spew it all at once to avoid lots of
+ tiny TCP packets.
+ * New API calls buffer_output() (to start buffering) and unbuffer_output()
+ (to dump the buffer and stop buffering) are available to do this.
+
Revision 611.0 2003/10/21 04:20:41 ajc
* THIS IS 6.11
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
1, msg);
}
else if (!strcasecmp(itemlist[i], "BODYSTRUCTURE")) {
+ buffer_output();
imap_fetch_bodystructure(IMAP->msgids[seq-1],
itemlist[i], msg);
+ unbuffer_output();
}
else if (!strcasecmp(itemlist[i], "ENVELOPE")) {
+ buffer_output();
imap_fetch_envelope(IMAP->msgids[seq-1], msg);
+ unbuffer_output();
}
else if (!strcasecmp(itemlist[i], "FLAGS")) {
+ buffer_output();
imap_fetch_flags(seq-1);
+ unbuffer_output();
}
else if (!strcasecmp(itemlist[i], "INTERNALDATE")) {
imap_fetch_internaldate(msg);
int redirect_ssl;
#endif
+ int buffering;
+ char *output_buffer; /* hold output for one big dump */
+ int buffer_len;
+
/* A linked list of all express messages sent to us. */
struct ExpressMessage *FirstExpressMessage;
int disable_exp; /* Set to 1 to disable incoming pages */
}
+/*
+ * buffer_output() ... tell client_write to buffer all output until
+ * instructed to dump it all out later
+ */
+void buffer_output(void) {
+ if (CC->buffering == 0) {
+ CC->buffering = 1;
+ CC->buffer_len = 0;
+ CC->output_buffer = mallok(SIZ);
+ }
+}
+
+/*
+ * unbuffer_output() ... dump out all that output we've been buffering.
+ */
+void unbuffer_output(void) {
+ if (CC->buffering == 1) {
+ CC->buffering = 0;
+ client_write(CC->output_buffer, CC->buffer_len);
+ phree(CC->output_buffer);
+ CC->output_buffer = NULL;
+ CC->buffer_len = 0;
+ }
+}
+
+
+
/*
* client_write() ... Send binary data to the client.
*/
int bytes_written = 0;
int retval;
int sock;
+ int old_buffer_len = 0;
if (CC->redirect_fp != NULL) {
fwrite(buf, nbytes, 1, CC->redirect_fp);
sock = CC->client_socket;
}
+ /* If we're buffering for later, do that now. */
+ if (CC->buffering) {
+ old_buffer_len = CC->buffer_len;
+ CC->buffer_len += nbytes;
+ CC->output_buffer = reallok(CC->output_buffer, CC->buffer_len);
+ memcpy(&CC->output_buffer[old_buffer_len], buf, nbytes);
+ return;
+ }
+
+ /* Ok, at this point we're not buffering. Go ahead and write. */
+
#ifdef HAVE_OPENSSL
if (CC->redirect_ssl) {
client_write_ssl(buf, nbytes);
inline struct CitContext *MyContext (void);
struct CitContext *CreateNewContext (void);
void InitMyContext (struct CitContext *con);
+void buffer_output(void);
+void unbuffer_output(void);
void client_write (char *buf, int nbytes);
int client_read_to (char *buf, int bytes, int timeout);
int client_read (char *buf, int bytes);
/* Do modular stuff... */
PerformSessionHooks(EVT_LOGOUT);
+
+ /* Free any output buffers */
+ if (who->output_buffer != NULL) {
+ unbuffer_output();
+ }
}
#ifdef ENABLE_CHKPWD