@@ -1957,6 +1957,33 @@ static handler_t gw_write_refill_wb(gw_handler_ctx * const hctx, request_st * co
1957
1957
return HANDLER_GO_ON ;
1958
1958
}
1959
1959
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
+
1960
1987
static handler_t gw_write_request (gw_handler_ctx * const hctx , request_st * const r ) {
1961
1988
switch (hctx -> state ) {
1962
1989
case GW_STATE_INIT :
@@ -2059,46 +2086,18 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
2059
2086
__attribute_fallthrough__
2060
2087
case GW_STATE_WRITE :
2061
2088
if (!chunkqueue_is_empty (& hctx -> wb )) {
2062
- log_error_st * const errh = r -> conf .errh ;
2063
2089
#if 0
2064
2090
if (hctx -> conf .debug > 1 ) {
2065
- log_debug (errh , __FILE__ , __LINE__ , "sdsx" ,
2091
+ log_debug (r -> conf . errh , __FILE__ , __LINE__ ,
2066
2092
"send data to backend (fd=%d), size=%zu" ,
2067
2093
hctx -> fd , chunkqueue_length (& hctx -> wb ));
2068
2094
}
2069
2095
#endif
2070
2096
off_t bytes_out = hctx -> wb .bytes_out ;
2071
2097
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 );
2102
2101
}
2103
2102
else if (hctx -> wb .bytes_out > bytes_out ) {
2104
2103
hctx -> write_ts = hctx -> proc -> last_used = log_monotonic_secs ;
0 commit comments