mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-05-05 15:47:51 +00:00
fix cpu race on ws poll
This commit is contained in:
parent
99559a3cd3
commit
2ccc771825
@ -205,7 +205,9 @@ int tport_recv_stream_ws(tport_t *self)
|
|||||||
ws_opcode_t oc;
|
ws_opcode_t oc;
|
||||||
|
|
||||||
if ( !wstp->ws_initialized ) {
|
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;
|
wstp->ws_initialized = 1;
|
||||||
self->tp_pre_framed = 1;
|
self->tp_pre_framed = 1;
|
||||||
return 1;
|
return 1;
|
||||||
@ -213,6 +215,10 @@ int tport_recv_stream_ws(tport_t *self)
|
|||||||
|
|
||||||
N = ws_read_frame(ws, &oc, &data);
|
N = ws_read_frame(ws, &oc, &data);
|
||||||
|
|
||||||
|
if (N == -2) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (N == -1000) {
|
if (N == -1000) {
|
||||||
if (self->tp_msg)
|
if (self->tp_msg)
|
||||||
msg_recv_commit(self->tp_msg, 0, 1);
|
msg_recv_commit(self->tp_msg, 0, 1);
|
||||||
|
@ -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 ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
int x = 0;
|
||||||
|
|
||||||
if (wsh->ssl) {
|
if (wsh->ssl) {
|
||||||
do {
|
do {
|
||||||
r = SSL_read(wsh->ssl, data, bytes);
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
r = recv(wsh->sock, data, bytes, 0);
|
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) {
|
if (r<0) {
|
||||||
//printf("READ FAIL: %s\n", strerror(errno));
|
//printf("READ FAIL: %s\n", strerror(errno));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user