FS-7117 #comment revert bf5210bf72
and implement it in ws.c please be sure to learn to use git commit hooks to properly associate commits with jiras
This commit is contained in:
parent
23c1829382
commit
5187aaed79
|
@ -311,7 +311,10 @@ int ws_handshake(wsh_t *wsh)
|
|||
proto_buf);
|
||||
respond[511] = 0;
|
||||
|
||||
ws_raw_write(wsh, respond, strlen(respond));
|
||||
if (ws_raw_write(wsh, respond, strlen(respond)) != strlen(respond)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
wsh->handshake = 1;
|
||||
|
||||
return 0;
|
||||
|
@ -403,10 +406,16 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
ssize_t r;
|
||||
int sanity = 2000;
|
||||
int ssl_err = 0;
|
||||
ssize_t wrote = 0;
|
||||
|
||||
if (wsh->ssl) {
|
||||
do {
|
||||
r = SSL_write(wsh->ssl, data, bytes);
|
||||
r = SSL_write(wsh->ssl, (void *)((unsigned char *)data + wrote), bytes - wrote);
|
||||
|
||||
if (r > 0) {
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
}
|
||||
|
@ -415,7 +424,7 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
ssl_err = SSL_get_error(wsh->ssl, r);
|
||||
}
|
||||
|
||||
} while (--sanity > 0 && r == -1 && ssl_err == SSL_ERROR_WANT_WRITE);
|
||||
} while (--sanity > 0 && ((r == -1 && ssl_err == SSL_ERROR_WANT_WRITE) || (wsh->block && wrote < bytes)));
|
||||
|
||||
if (ssl_err) {
|
||||
r = ssl_err * -1;
|
||||
|
@ -425,12 +434,18 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
}
|
||||
|
||||
do {
|
||||
r = send(wsh->sock, data, bytes, 0);
|
||||
r = send(wsh->sock, (void *)((unsigned char *)data + wrote), bytes - wrote, 0);
|
||||
|
||||
if (r > 0) {
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
}
|
||||
} while (--sanity > 0 && r == -1 && xp_is_blocking(xp_errno()));
|
||||
|
||||
|
||||
} while (--sanity > 0 && ((r == -1 && xp_is_blocking(xp_errno())) || (wsh->block && wrote < bytes)));
|
||||
|
||||
//if (r<0) {
|
||||
//printf("wRITE FAIL: %s\n", strerror(errno));
|
||||
//}
|
||||
|
|
|
@ -1480,9 +1480,6 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
|
|||
|
||||
for (;;) {
|
||||
switch_status_t status;
|
||||
ssize_t written = 0;
|
||||
ssize_t ret = 0;
|
||||
int sanity = 3;
|
||||
|
||||
flen = sizeof(chunk);
|
||||
status = switch_file_read(fd, chunk, &flen);
|
||||
|
@ -1491,17 +1488,7 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
|
|||
break;
|
||||
}
|
||||
|
||||
again:
|
||||
ret = ws_raw_write(&jsock->ws, chunk + written, flen);
|
||||
if (ret == -1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error write %" SWITCH_SIZE_T_FMT " bytes!\n", flen);
|
||||
ws_close(&jsock->ws, WS_NONE);
|
||||
} else if (ret > 0 && ret < flen && sanity > 0) {
|
||||
switch_yield(1000);
|
||||
flen -= ret;
|
||||
written += ret;
|
||||
goto again;
|
||||
}
|
||||
ws_raw_write(&jsock->ws, chunk, flen);
|
||||
}
|
||||
switch_file_close(fd);
|
||||
} else {
|
||||
|
|
|
@ -311,7 +311,10 @@ int ws_handshake(wsh_t *wsh)
|
|||
proto_buf);
|
||||
respond[511] = 0;
|
||||
|
||||
ws_raw_write(wsh, respond, strlen(respond));
|
||||
if (ws_raw_write(wsh, respond, strlen(respond)) != strlen(respond)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
wsh->handshake = 1;
|
||||
|
||||
return 0;
|
||||
|
@ -403,10 +406,16 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
ssize_t r;
|
||||
int sanity = 2000;
|
||||
int ssl_err = 0;
|
||||
ssize_t wrote = 0;
|
||||
|
||||
if (wsh->ssl) {
|
||||
do {
|
||||
r = SSL_write(wsh->ssl, data, bytes);
|
||||
r = SSL_write(wsh->ssl, (void *)((unsigned char *)data + wrote), bytes - wrote);
|
||||
|
||||
if (r > 0) {
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
}
|
||||
|
@ -415,7 +424,7 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
ssl_err = SSL_get_error(wsh->ssl, r);
|
||||
}
|
||||
|
||||
} while (--sanity > 0 && r == -1 && ssl_err == SSL_ERROR_WANT_WRITE);
|
||||
} while (--sanity > 0 && ((r == -1 && ssl_err == SSL_ERROR_WANT_WRITE) || (wsh->block && wrote < bytes)));
|
||||
|
||||
if (ssl_err) {
|
||||
r = ssl_err * -1;
|
||||
|
@ -425,12 +434,18 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
}
|
||||
|
||||
do {
|
||||
r = send(wsh->sock, data, bytes, 0);
|
||||
r = send(wsh->sock, (void *)((unsigned char *)data + wrote), bytes - wrote, 0);
|
||||
|
||||
if (r > 0) {
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
}
|
||||
} while (--sanity > 0 && r == -1 && xp_is_blocking(xp_errno()));
|
||||
|
||||
|
||||
} while (--sanity > 0 && ((r == -1 && xp_is_blocking(xp_errno())) || (wsh->block && wrote < bytes)));
|
||||
|
||||
//if (r<0) {
|
||||
//printf("wRITE FAIL: %s\n", strerror(errno));
|
||||
//}
|
||||
|
|
Loading…
Reference in New Issue