mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-30 15:14:17 +00:00
FS-9810 fix ws write fail on slow network
This commit is contained in:
1 parent
89063a1a4c
commit
b26fa6e17c
4 files changed
+84
-21
No files matched your search
@@ -20,6 +20,9 @@
|
||||
#define WS_BLOCK 1
|
||||
#define WS_NOBLOCK 0
|
||||
|
||||
#define WS_INIT_SANITY 5000
|
||||
#define WS_WRITE_SANITY 2000
|
||||
|
||||
#define SHA1_HASH_SIZE 20
|
||||
struct ws_globals_s ws_globals;
|
||||
|
||||
@@ -407,7 +410,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block)
|
||||
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
||||
{
|
||||
ssize_t r;
|
||||
int sanity = 2000;
|
||||
int sanity = WS_WRITE_SANITY;
|
||||
int ssl_err = 0;
|
||||
size_t wrote = 0;
|
||||
|
||||
@@ -419,8 +422,17 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
if (sanity < WS_WRITE_SANITY) {
|
||||
int ms = 1;
|
||||
|
||||
if (wsh->block) {
|
||||
if (sanity < WS_WRITE_SANITY * 3 / 4) {
|
||||
ms = 60;
|
||||
} else if (sanity < WS_WRITE_SANITY / 2) {
|
||||
ms = 10;
|
||||
}
|
||||
}
|
||||
ms_sleep(ms);
|
||||
}
|
||||
|
||||
if (r == -1) {
|
||||
@@ -443,8 +455,17 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
||||
wrote += r;
|
||||
}
|
||||
|
||||
if (sanity < 2000) {
|
||||
ms_sleep(1);
|
||||
if (sanity < WS_WRITE_SANITY) {
|
||||
int ms = 1;
|
||||
|
||||
if (wsh->block) {
|
||||
if (sanity < WS_WRITE_SANITY * 3 / 4) {
|
||||
ms = 60;
|
||||
} else if (sanity < WS_WRITE_SANITY / 2) {
|
||||
ms = 10;
|
||||
}
|
||||
}
|
||||
ms_sleep(ms);
|
||||
}
|
||||
|
||||
} while (--sanity > 0 && ((r == -1 && xp_is_blocking(xp_errno())) || (wsh->block && wrote < bytes)));
|
||||
@@ -453,7 +474,7 @@ ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
||||
//printf("wRITE FAIL: %s\n", strerror(errno));
|
||||
//}
|
||||
|
||||
return r;
|
||||
return r < 0 ? r : wrote;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -587,7 +608,7 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int
|
||||
|
||||
wsh->sock = sock;
|
||||
wsh->block = block;
|
||||
wsh->sanity = 5000;
|
||||
wsh->sanity = WS_INIT_SANITY;
|
||||
wsh->ssl_ctx = ssl_ctx;
|
||||
wsh->stay_open = stay_open;
|
||||
|
||||
|
||||
Reference in new issue
Block a user