allow write timeout to be set on a per-user basis in AMI (issue #5352)
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 4 Oct 2005 22:25:15 +0000 (22:25 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 4 Oct 2005 22:25:15 +0000 (22:25 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6716 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configs/manager.conf.sample
include/asterisk/manager.h
manager.c

index e2d9270..4141aa4 100755 (executable)
@@ -30,6 +30,12 @@ bindaddr = 0.0.0.0
 ;deny=0.0.0.0/0.0.0.0
 ;permit=209.16.236.73/255.255.255.0
 ;
+; If the device connected via this user accepts input slowly,
+; the timeout for writes to it can be increased to keep it
+; from being disconnected (value is in milliseconds)
+;
+; writetimeout = 100
+;
 ; Authorization for various classes 
 ;read = system,call,log,verbose,command,agent,user
 ;write = system,call,log,verbose,command,agent,user
index 6ee977b..ea8f91d 100755 (executable)
@@ -100,6 +100,8 @@ struct mansession {
        int send_events;
        /* Queued events that we've not had the ability to send yet */
        struct eventqent *eventq;
+       /* Timeout for ast_carefulwrite() */
+       int writetimeout;
        struct mansession *next;
 };
 
index 386dd70..83f4969 100755 (executable)
--- a/manager.c
+++ b/manager.c
@@ -495,7 +495,14 @@ static int authenticate(struct mansession *s, struct message *m)
                                        } else if (!strcasecmp(v->name, "permit") ||
                                                   !strcasecmp(v->name, "deny")) {
                                                ha = ast_append_ha(v->name, v->value, ha);
-                                       }       
+                                       } else if (!strcasecmp(v->name, "writetimeout")) {
+                                               int val = atoi(v->value);
+
+                                               if (val < 100)
+                                                       ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", v->value, v->lineno);
+                                               else
+                                                       s->writetimeout = val;
+                                       }
                                                
                                        v = v->next;
                                }
@@ -1286,7 +1293,7 @@ static int process_message(struct mansession *s, struct message *m)
                ast_mutex_lock(&s->__lock);
                s->busy = 0;
                while(s->eventq) {
-                       if (ast_carefulwrite(s->fd, s->eventq->eventdata, strlen(s->eventq->eventdata), 100)) {
+                       if (ast_carefulwrite(s->fd, s->eventq->eventdata, strlen(s->eventq->eventdata), s->writetimeout)) {
                                ret = -1;
                                break;
                        }
@@ -1427,6 +1434,7 @@ static void *accept_thread(void *ignore)
                } 
                memset(s, 0, sizeof(struct mansession));
                memcpy(&s->sin, &sin, sizeof(sin));
+               s->writetimeout = 100;
 
                if(! block_sockets) {
                        /* For safety, make sure socket is non-blocking */
@@ -1499,7 +1507,7 @@ int manager_event(int category, char *event, char *fmt, ...)
                ast_mutex_lock(&s->__lock);
                if (s->busy) {
                        append_event(s, tmp);
-               } else if (ast_carefulwrite(s->fd, tmp, tmp_next - tmp, 100) < 0) {
+               } else if (ast_carefulwrite(s->fd, tmp, tmp_next - tmp, s->writetimeout) < 0) {
                        ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n");
                        s->dead = 1;
                        pthread_kill(s->t, SIGURG);