diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-22 17:09:36 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-22 17:09:36 +0000 |
commit | 87c96dd4d04f1046447430f700d2406e25f2b8d8 (patch) | |
tree | 97efdb1323ea8cb3038a987daaded8806e5b4213 /main/manager.c | |
parent | 7d7c94a817bb12cdf92e82d9e03df25fc5340bc5 (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: http://svn.digium.com/svn/asterisk/trunk@166282 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/manager.c')
-rw-r--r-- | main/manager.c | 25 |
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); } /*! |