]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] new function stream_int_cond_close()
authorWilly Tarreau <w@1wt.eu>
Sun, 27 Dec 2009 21:51:06 +0000 (22:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 27 Dec 2009 21:51:06 +0000 (22:51 +0100)
This one will be used to conditionally send a message upon a
close on a stream interface. It will not overwrite any existing
data.

include/proto/stream_interface.h
src/stream_interface.c

index 4e7f7341959e1e20c6f0df9124fc546cb4b8fef7..e63e1361808dfa4b97a165084648c211cbb4591d 100644 (file)
@@ -32,6 +32,7 @@
 int stream_int_check_timeouts(struct stream_interface *si);
 void stream_int_report_error(struct stream_interface *si);
 void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg);
+void stream_int_cond_close(struct stream_interface *si, const struct chunk *msg);
 
 /* functions used when running a stream interface as a task */
 void stream_int_update(struct stream_interface *si);
index fcfa117b8ba859c3d42e179feaa8751c6e7b36c7..9b7277fad690656425c425fcbc036c9f0cd4350b 100644 (file)
@@ -80,6 +80,28 @@ void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg)
        buffer_auto_close(si->ob);
 }
 
+/* This function aborts all of the client's requests and stops the server's
+ * response with the data that are already present. If the response buffer
+ * empty, then the message in arguments will be sent. This ensures that
+ * we won't mix an HTTP response with pending data. The buffer is marked for
+ * read shutdown on the server side to protect the message or any pending
+ * data, and the buffer write is enabled. The message is contained in a
+ * "chunk". If it is null, then an empty message is used. The reply buffer
+ * doesn't need to be empty before this. The goal of this function is to
+ * return error messages to a client but only when it is possible.
+ */
+void stream_int_cond_close(struct stream_interface *si, const struct chunk *msg)
+{
+       buffer_abort(si->ib);
+       buffer_erase(si->ib); /* remove any pending request */
+       buffer_shutr_now(si->ob);
+       if (!si->ob->l && msg && msg->len)
+               buffer_write(si->ob, msg->str, msg->len);
+
+       si->ob->wex = tick_add_ifset(now_ms, si->ob->wto);
+       buffer_auto_close(si->ob);
+}
+
 /* default update function for scheduled tasks, not used for embedded tasks */
 void stream_int_update(struct stream_interface *si)
 {