Skinny: fix up session logging.
authorDamien Wedhorn <voip@facts.com.au>
Mon, 20 Jan 2014 21:56:14 +0000 (21:56 +0000)
committerDamien Wedhorn <voip@facts.com.au>
Mon, 20 Jan 2014 21:56:14 +0000 (21:56 +0000)
Logging from the skinny session loop was providing some incorrect reasons
for exiting the loop. Cleaned up messages and handling so correct reason
displayed.
........

Merged revisions 405924 from http://svn.asterisk.org/svn/asterisk/branches/12

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405925 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_skinny.c

index 917f26c..d8c3d61 100644 (file)
@@ -7471,7 +7471,7 @@ static void skinny_session_cleanup(void *data)
        struct skinny_line *l;
        struct skinny_speeddial *sd;
 
-       ast_verb(3, "Ending Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr));
+       ast_verb(3, "Ending Skinny session from %s at %s\n", d ? d->name : "unknown", ast_inet_ntoa(s->sin.sin_addr));
 
        if (s->lockstate) {
                ast_mutex_unlock(&s->lock);
@@ -7517,6 +7517,7 @@ static void skinny_session_cleanup(void *data)
 static void *skinny_session(void *data)
 {
        int res;
+       int bytesread;
        struct skinny_req *req = NULL;
        struct skinnysession *s = data;
 
@@ -7592,41 +7593,41 @@ static void *skinny_session(void *data)
                                break;
                        }
 
-                       res = 0;
+                       bytesread = 0;
                        while (1) {
-                               int bytesread = res;
                                if ((res = read(s->fd, &req->data+bytesread, dlen-bytesread)) < 0) {
+                                       ast_log(LOG_WARNING, "Data read() returned error: %s\n", strerror(errno));
                                        break;
                                }
-                               res += bytesread;
-                               if (res >= dlen) {
+                               bytesread += res;
+                               if (bytesread >= dlen) {
+                                       if (res < bytesread) {
+                                               ast_log(LOG_WARNING, "Rest of partial data received.\n");
+                                       }
+                                       if (bytesread > dlen) {
+                                               ast_log(LOG_WARNING, "Client sent wrong amount of data (%d), expected (%d).\n", bytesread, dlen);
+                                               res = -1;
+                                       }
                                        break;
                                }
-                               ast_log(LOG_WARNING, "Partial data received, waiting (%d bytes read of %d)\n", res, dlen);
+
+                               ast_log(LOG_WARNING, "Partial data received, waiting (%d bytes read of %d)\n", bytesread, dlen);
                                if (sched_yield() < 0) {
                                        ast_log(LOG_WARNING, "Data yield() returned error: %s\n", strerror(errno));
+                                       res = -1;
                                        break;
                                }
                        }
-                       if (res < 0) {
-                               ast_log(LOG_WARNING, "Data read() returned error: %s\n", strerror(errno));
-                               break;
-                       }
-                       if (res != dlen) {
-                               ast_log(LOG_WARNING, "Client sent wrong amount of data (%d), expected (%d).\n", res, dlen);
-                               break;
-                       }
 
                        s->lockstate = 0;
                        ast_mutex_unlock(&s->lock);
+                       if (res < 0) {
+                               break;
+                       }
 
                        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
                        res = handle_message(req, s);
                        pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-                       if (res < 0) {
-                               ast_verb(3, "Ending Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr));
-                               break;
-                       }
                }
 
                if (req) {