]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix cpu race on ws poll
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 25 Jan 2013 23:25:26 +0000 (17:25 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Apr 2013 02:27:21 +0000 (21:27 -0500)
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_ws.c
libs/sofia-sip/libsofia-sip-ua/tport/ws.c

index 1f923670cafd43215fda24de6a510a021d42f55a..fabd68e349762fcc9a9eb511e2de1922cc895dbb 100644 (file)
@@ -205,7 +205,9 @@ int tport_recv_stream_ws(tport_t *self)
   ws_opcode_t oc;
 
   if ( !wstp->ws_initialized ) {
-         ws_init(ws, self->tp_socket, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL);
+         if (ws_init(ws, self->tp_socket, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL) == -2) {
+                 return 2;
+         }
          wstp->ws_initialized = 1;
          self->tp_pre_framed = 1;
          return 1;
@@ -213,6 +215,10 @@ int tport_recv_stream_ws(tport_t *self)
 
   N = ws_read_frame(ws, &oc, &data);
 
+  if (N == -2) {
+         return 2;
+  }
+
   if (N == -1000) {
     if (self->tp_msg)
       msg_recv_commit(self->tp_msg, 0, 1);
index b612cf596fafd2cf85250698348fc6577551bbca..bdbef0aebc3ede2000ba3f072eab9bf0be63846c 100644 (file)
@@ -283,18 +283,21 @@ int ws_handshake(wsh_t *wsh)
 ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
 {
        ssize_t r;
+       int x = 0;
 
        if (wsh->ssl) {
                do {
                        r = SSL_read(wsh->ssl, data, bytes);
-               } while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ);
+                       if (x++) {usleep(10000);
+               } while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ && x < 100);
 
                return r;
        }
 
        do {
                r = recv(wsh->sock, data, bytes, 0);
-       } while (r == -1 && (errno == EAGAIN || errno == EINTR));
+               if (x++) {usleep(10000);
+       } while (r == -1 && (errno == EAGAIN || errno == EINTR) && x < 100);
 
        if (r<0) {
                //printf("READ FAIL: %s\n", strerror(errno));