From 403135f64685668485616c663fb9f2b8976a000e Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@icir.org>
Date: Tue, 7 Nov 2006 08:34:26 +0000
Subject: [PATCH] explain why ast_carefulwrite is written the way it is, and
 also that it doesn't really work as claimed.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47242 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/utils.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/main/utils.c b/main/utils.c
index 5c08f13729..f930f74c6e 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -604,6 +604,21 @@ int ast_wait_for_input(int fd, int ms)
 	return poll(pfd, 1, ms);
 }
 
+/*!
+ * Try to write string, but wait no more than ms milliseconds before timing out.
+ *
+ * \note The code assumes that the file descriptor has NONBLOCK set,
+ * so there is only one system call made to do a write, unless we actually
+ * have a need to wait.  This way, we get better performance.
+ * If the descriptor is blocking, all assumptions on the guaranteed
+ * detail do not apply anymore.
+ * Also note that in the current implementation, the delay is per-write,
+ * so you still have no guarantees, anyways.
+ * Fortunately the routine is only used in a few places (cli.c, manager.c,
+ * res_agi.c) so it is reasonably easy to check how it behaves there.
+ *
+ * XXX We either need to fix the code, or fix the documentation.
+ */
 int ast_carefulwrite(int fd, char *s, int len, int timeoutms) 
 {
 	/* Try to write string, but wait no more than ms milliseconds
-- 
GitLab