]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
some more ws transport tweaks
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Jun 2013 19:04:13 +0000 (14:04 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Jun 2013 19:04:13 +0000 (14:04 -0500)
libs/sofia-sip/.update
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_ws.c
libs/sofia-sip/libsofia-sip-ua/tport/ws.c
libs/sofia-sip/libsofia-sip-ua/tport/ws.h

index d8abd49c6deb7a050761ecf84a3f0d04e3495da6..932e4da08782c9257ec6112405dab902bc81fcd0 100644 (file)
@@ -1 +1 @@
-Wed Jun 26 23:10:11 EDT 2013
+Thu Jun 27 14:04:11 CDT 2013
index d9ed0b6980d7d764018e4bd6b86eff071bddaa29..8b7ecfaa7baf6d81236d0f7ac6fb8405100ba593 100644 (file)
@@ -432,26 +432,43 @@ int tport_ws_init_secondary(tport_t *self, int socket, int accepted,
   int one = 1;
   tport_ws_primary_t *wspri = (tport_ws_primary_t *)self->tp_pri;
   tport_ws_t *wstp = (tport_ws_t *)self;
+  char *buffer, *wbuffer;
 
   self->tp_has_connection = 1;
 
   if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1)
-    return *return_reason = "TCP_NODELAY", -1;
+         return *return_reason = "TCP_NODELAY", -1;
+
+#if defined(SO_KEEPALIVE)
+  setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof one);
+#endif
+  one = 30;
+#if defined(TCP_KEEPIDLE)
+  setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, (void *)&one, sizeof one);
+#endif
+#if defined(TCP_KEEPINTVL)
+  setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, (void *)&one, sizeof one);
+#endif
+
 
   if (!accepted)
     tport_ws_setsndbuf(socket, 64 * 1024);
 
   if ( wspri->ws_secure ) wstp->ws_secure = 1;
 
-
   memset(&wstp->ws, 0, sizeof(wstp->ws));
-  if (ws_init(&wstp->ws, socket, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0) < 0) {
+  
+  buffer = (char *) su_alloc((su_home_t *)self, 65536);
+  wbuffer = (char *) su_alloc((su_home_t *)self, 65536);
+
+  if (ws_init(&wstp->ws, socket, buffer, wbuffer, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0) < 0) {
          return *return_reason = "WS_INIT", -1;
   }
 
   wstp->ws_initialized = 1;
   self->tp_pre_framed = 1;
 
+
   return 0;
 }
 
index 1a0a2f3250fb11631b951955b6678bcdd282787c..6ee35e54a3088503c80f95ab218e9476174ce284 100644 (file)
@@ -352,7 +352,7 @@ issize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
        return r;
 }
 
-int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int close_sock)
+int ws_init(wsh_t *wsh, ws_socket_t sock, char *buffer, char *wbuffer, size_t buflen, SSL_CTX *ssl_ctx, int close_sock)
 {
        memset(wsh, 0, sizeof(*wsh));
        wsh->sock = sock;
@@ -372,9 +372,20 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c
        wsh->buflen = buflen;
        wsh->secure = ssl_ctx ? 1 : 0;
 
-       if (!wsh->buffer) {
+       if (buffer) {
+               wsh->buffer = buffer;
+       } else if (!wsh->buffer) {
                wsh->buffer = malloc(wsh->buflen);
                assert(wsh->buffer);
+               wsh->free_buffer = 1;
+       }
+
+       if (wbuffer) {
+               wsh->wbuffer = wbuffer;
+       } else if (!wsh->wbuffer) {
+               wsh->wbuffer = malloc(wsh->buflen);
+               assert(wsh->wbuffer);
+               wsh->free_wbuffer = 1;
        }
 
        if (wsh->secure) {
@@ -454,12 +465,12 @@ void ws_destroy(wsh_t *wsh)
                wsh->ssl = NULL;
        }
 
-       if (wsh->buffer) {
+       if (wsh->free_buffer && wsh->buffer) {
                free(wsh->buffer);
                wsh->buffer = NULL;
        }
 
-       if (wsh->wbuffer) {
+       if (wsh->free_wbuffer && wsh->wbuffer) {
                free(wsh->wbuffer);
                wsh->wbuffer = NULL;
        }
@@ -653,13 +664,6 @@ issize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes)
                return -1;
        }
 
-
-       if (!wsh->wbuffer) {
-               wsh->wbuffer = malloc(wsh->buflen);
-               assert(wsh->wbuffer);
-       }
-       
-
        memcpy(wsh->wbuffer + wsh->wdatalen, data, bytes);
        
        wsh->wdatalen += bytes;
index 13e5c27b2ba1d08abe862d8d3525112d95c27201..84aa46fcebb41cfb542056b6c88b873ca57d5e11 100644 (file)
@@ -71,8 +71,9 @@ typedef struct wsh_s {
        int handshake;
        uint8_t down;
        int secure;
-       unsigned close_sock:1;
-       unsigned :0;
+       uint8_t free_buffer;
+       uint8_t free_wbuffer;
+       uint8_t close_sock;
 } wsh_t;
 
 issize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
@@ -83,7 +84,7 @@ issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes);
 issize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
 issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
 issize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
-int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int close_sock);
+int ws_init(wsh_t *wsh, ws_socket_t sock, char *buffer, char *wbuffer, size_t buflen, SSL_CTX *ssl_ctx, int close_sock);
 issize_t ws_close(wsh_t *wsh, int16_t reason);
 void ws_destroy(wsh_t *wsh);
 void init_ssl(void);