Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 214793) +++ channels/chan_sip.c (working copy) @@ -2916,12 +2916,9 @@ /* Read in headers one line at a time */ while (req.len < 4 || strncmp(REQ_OFFSET_TO_STR(&req, len - 4), "\r\n\r\n", 4)) { - ast_mutex_lock(&tcptls_session->lock); if (!fgets(buf, sizeof(buf), tcptls_session->f)) { - ast_mutex_unlock(&tcptls_session->lock); goto cleanup; } - ast_mutex_unlock(&tcptls_session->lock); if (me->stop) goto cleanup; ast_str_append(&req.data, 0, "%s", buf); @@ -2932,12 +2929,9 @@ /* In order to know how much to read, we need the content-length header */ if (sscanf(get_header(&reqcpy, "Content-Length"), "%30d", &cl)) { while (cl > 0) { - ast_mutex_lock(&tcptls_session->lock); if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, tcptls_session->f)) { - ast_mutex_unlock(&tcptls_session->lock); goto cleanup; } - ast_mutex_unlock(&tcptls_session->lock); if (me->stop) goto cleanup; cl -= strlen(buf); @@ -3415,9 +3409,6 @@ if (sip_prepare_socket(p) < 0) return XMIT_ERROR; - if (p->socket.tcptls_session) - ast_mutex_lock(&p->socket.tcptls_session->lock); - if (p->socket.type & SIP_TRANSPORT_UDP) { res = sendto(p->socket.fd, data->str, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in)); } else if (p->socket.tcptls_session) { @@ -3431,9 +3422,6 @@ return XMIT_ERROR; } - if (p->socket.tcptls_session) - ast_mutex_unlock(&p->socket.tcptls_session->lock); - if (res == -1) { switch (errno) { case EBADF: /* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */ Index: main/http.c =================================================================== --- main/http.c (revision 214793) +++ main/http.c (working copy) @@ -810,12 +810,13 @@ struct ast_variable *v, *cookies=NULL; for (v = headers; v; v = v->next) { - if (!strncasecmp(v->name, "Cookie", 6)) { + if (!strncasecmp(v->name, "Cookie", 6)) { + char *tmp = (char *) v->value; if (cookies) { ast_variables_destroy(cookies); } - cookies = parse_cookies((char *)v->value); + cookies = parse_cookies(tmp); } } return cookies; Index: main/tcptls.c =================================================================== --- main/tcptls.c (revision 214793) +++ main/tcptls.c (working copy) @@ -53,24 +53,42 @@ #ifdef DO_SSL static HOOK_T ssl_read(void *cookie, char *buf, LEN_T len) { - int i = SSL_read(cookie, buf, len-1); -#if 0 - if (i >= 0) - buf[i] = '\0'; - ast_verb(0, "ssl read size %d returns %d <%s>\n", (int)len, i, buf); -#endif + struct ast_tcptls_session_instance *tcptls_session = cookie; + int i; + + ast_mutex_lock(&tcptls_session->lock); +restart_read: + if ((i = SSL_read(tcptls_session->ssl, buf, len - 1)) < 0) { + if (SSL_get_error(tcptls_session->ssl, i) == SSL_ERROR_WANT_READ) { + /* Unlock I/O mutex briefly */ + ast_mutex_unlock(&tcptls_session->lock); + sched_yield(); + ast_mutex_lock(&tcptls_session->lock); + goto restart_read; + } + } + ast_mutex_unlock(&tcptls_session->lock); return i; } static HOOK_T ssl_write(void *cookie, const char *buf, LEN_T len) { -#if 0 - char *s = alloca(len+1); - strncpy(s, buf, len); - s[len] = '\0'; - ast_verb(0, "ssl write size %d <%s>\n", (int)len, s); -#endif - return SSL_write(cookie, buf, len); + struct ast_tcptls_session_instance *tcptls_session = cookie; + int i; + + ast_mutex_lock(&tcptls_session->lock); +restart_write: + if ((i = SSL_write(tcptls_session->ssl, buf, len)) < 0) { + if (SSL_get_error(tcptls_session->ssl, i) == SSL_ERROR_WANT_READ) { + /* Unlock I/O mutex briefly */ + ast_mutex_unlock(&tcptls_session->lock); + sched_yield(); + ast_mutex_lock(&tcptls_session->lock); + goto restart_write; + } + } + ast_mutex_unlock(&tcptls_session->lock); + return i; } static int ssl_close(void *cookie)