Skip to content

Commit fc7cd36

Browse files
committed
[core] gw_network_backend_write_error() cold func
1 parent abd2bb2 commit fc7cd36

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/gw_backend.c

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,33 @@ static handler_t gw_write_refill_wb(gw_handler_ctx * const hctx, request_st * co
19571957
return HANDLER_GO_ON;
19581958
}
19591959

1960+
__attribute_cold__
1961+
static handler_t gw_network_backend_write_error(gw_handler_ctx * const hctx, request_st * const r) {
1962+
#ifdef _WIN32
1963+
switch(WSAGetLastError())
1964+
#else
1965+
switch(errno)
1966+
#endif
1967+
{
1968+
#ifdef _WIN32
1969+
case WSAENOTCONN:
1970+
case WSAECONNRESET:
1971+
#else
1972+
case EPIPE:
1973+
case ENOTCONN:
1974+
case ECONNRESET:
1975+
#endif
1976+
log_error(r->conf.errh, __FILE__, __LINE__,
1977+
"connection was dropped after accept() "
1978+
"(perhaps the gw process died), write-offset: %lld socket: %s",
1979+
(long long)hctx->wb.bytes_out, hctx->proc->connection_name->ptr);
1980+
return HANDLER_ERROR;
1981+
default:
1982+
log_perror(r->conf.errh, __FILE__, __LINE__, "write failed");
1983+
return HANDLER_ERROR;
1984+
}
1985+
}
1986+
19601987
static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * const r) {
19611988
switch(hctx->state) {
19621989
case GW_STATE_INIT:
@@ -2059,46 +2086,18 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
20592086
__attribute_fallthrough__
20602087
case GW_STATE_WRITE:
20612088
if (!chunkqueue_is_empty(&hctx->wb)) {
2062-
log_error_st * const errh = r->conf.errh;
20632089
#if 0
20642090
if (hctx->conf.debug > 1) {
2065-
log_debug(errh, __FILE__, __LINE__, "sdsx",
2091+
log_debug(r->conf.errh, __FILE__, __LINE__,
20662092
"send data to backend (fd=%d), size=%zu",
20672093
hctx->fd, chunkqueue_length(&hctx->wb));
20682094
}
20692095
#endif
20702096
off_t bytes_out = hctx->wb.bytes_out;
20712097
if (r->con->srv->network_backend_write(hctx->fd, &hctx->wb,
2072-
MAX_WRITE_LIMIT, errh) < 0) {
2073-
#ifdef _WIN32
2074-
switch(WSAGetLastError())
2075-
#else
2076-
switch(errno)
2077-
#endif
2078-
{
2079-
#ifdef _WIN32
2080-
case WSAENOTCONN:
2081-
case WSAECONNRESET:
2082-
#else
2083-
case EPIPE:
2084-
case ENOTCONN:
2085-
case ECONNRESET:
2086-
#endif
2087-
/* the connection got dropped after accept()
2088-
* we don't care about that --
2089-
* if you accept() it, you have to handle it.
2090-
*/
2091-
log_error(errh, __FILE__, __LINE__,
2092-
"connection was dropped after accept() "
2093-
"(perhaps the gw process died), "
2094-
"write-offset: %lld socket: %s",
2095-
(long long)hctx->wb.bytes_out,
2096-
hctx->proc->connection_name->ptr);
2097-
return HANDLER_ERROR;
2098-
default:
2099-
log_perror(errh, __FILE__, __LINE__, "write failed");
2100-
return HANDLER_ERROR;
2101-
}
2098+
MAX_WRITE_LIMIT,
2099+
r->conf.errh) < 0) {
2100+
return gw_network_backend_write_error(hctx, r);
21022101
}
21032102
else if (hctx->wb.bytes_out > bytes_out) {
21042103
hctx->write_ts = hctx->proc->last_used = log_monotonic_secs;

0 commit comments

Comments
 (0)