retry send when the socket sent less than we want

This commit is contained in:
Seven Du 2014-12-30 13:16:28 +08:00
parent a961b0e90b
commit bf5210bf72
1 changed files with 14 additions and 1 deletions

View File

@ -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 {