From bf5210bf72d6c4b0d9b599a5a07ee59a9c947436 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Tue, 30 Dec 2014 13:16:28 +0800 Subject: [PATCH] retry send when the socket sent less than we want --- src/mod/endpoints/mod_verto/mod_verto.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index ae9d9a9e2f..7616416982 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1456,6 +1456,9 @@ 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); @@ -1464,7 +1467,17 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v break; } - ws_raw_write(&jsock->ws, chunk, flen); +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; + } } switch_file_close(fd); } else {