summaryrefslogtreecommitdiff
path: root/main/manager.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2008-12-22 17:09:36 +0000
committerRussell Bryant <russell@russellbryant.com>2008-12-22 17:09:36 +0000
commitc2999a8366b0738f14b2d4493cda496ff65bcc09 (patch)
tree97efdb1323ea8cb3038a987daaded8806e5b4213 /main/manager.c
parent77b1fe0cebbecbbf104f4ed5b3b81fbd0d8bce7c (diff)
Introduce ast_careful_fwrite() and use in AMI to prevent partial writes.
This patch introduces a function to do careful writes on a file stream which will handle timeouts and partial writes. It is currently used in AMI to address the issue that has been reported. However, there are probably a few other places where this could be used. (closes issue #13546) Reported by: srt Tested by: russell http://reviewboard.digium.com/r/104/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@166282 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/manager.c')
-rw-r--r--main/manager.c25
1 files changed, 1 insertions, 24 deletions
diff --git a/main/manager.c b/main/manager.c
index 2069cb882..d1c3d3494 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -899,30 +899,7 @@ struct ast_variable *astman_get_variables(const struct message *m)
*/
static int send_string(struct mansession *s, char *string)
{
- int len = strlen(string); /* residual length */
- char *src = string;
- struct timeval start = ast_tvnow();
- int n = 0;
-
- for (;;) {
- int elapsed;
- struct pollfd fd;
- n = fwrite(src, 1, len, s->f); /* try to write the string, non blocking */
- if (n == len /* ok */ || n < 0 /* error */)
- break;
- len -= n; /* skip already written data */
- src += n;
- fd.fd = s->fd;
- fd.events = POLLOUT;
- n = -1; /* error marker */
- elapsed = ast_tvdiff_ms(ast_tvnow(), start);
- if (elapsed > s->writetimeout)
- break;
- if (poll(&fd, 1, s->writetimeout - elapsed) < 1)
- break;
- }
- fflush(s->f);
- return n < 0 ? -1 : 0;
+ return ast_careful_fwrite(s->f, s->fd, string, strlen(string), s->writetimeout);
}
/*!