Browse Source

[core] fdevent_connect_status() shared code

personal/stbuehler/mod-csrf
Glenn Strauss 5 years ago
parent
commit
91d14acfc3
  1. 9
      src/fdevent.c
  2. 2
      src/fdevent.h
  3. 13
      src/mod_fastcgi.c
  4. 11
      src/mod_proxy.c
  5. 11
      src/mod_scgi.c

9
src/fdevent.c

@ -618,6 +618,15 @@ int fdevent_ioctl_fionread (int fd, int fdfmt, int *toread) {
}
int fdevent_connect_status(int fd) {
/* try to finish the connect() */
/*(should be called after connect() only when fd is writable (POLLOUT))*/
int opt;
socklen_t len = sizeof(opt);
return (0 == getsockopt(fd,SOL_SOCKET,SO_ERROR,&opt,&len)) ? opt : errno;
}
#include <netinet/tcp.h>
#if (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__FreeBSD__) || defined(__NetBSD__) \

2
src/fdevent.h

@ -235,6 +235,8 @@ int fdevent_libev_init(fdevents *ev);
int fdevent_ioctl_fionread (int fd, int fdfmt, int *toread);
int fdevent_connect_status(int fd);
/* fd must be TCP socket (AF_INET, AF_INET6), end-of-stream recv() 0 bytes */
int fdevent_is_tcp_half_closed(int fd);

13
src/mod_fastcgi.c

@ -2133,18 +2133,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
/* we can't handle this in the switch as we have to fall through in it */
if (hctx->state == FCGI_STATE_CONNECT_DELAYED) {
int socket_error;
socklen_t socket_error_len = sizeof(socket_error);
/* try to finish the connect() */
if (0 != getsockopt(hctx->fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"getsockopt failed:", strerror(errno));
fcgi_proc_disable(srv, hctx->host, hctx->proc, hctx);
return HANDLER_ERROR;
}
int socket_error = fdevent_connect_status(hctx->fd);
if (socket_error != 0) {
if (!hctx->proc->is_local || hctx->conf.debug) {
/* local procs get restarted */

11
src/mod_proxy.c

@ -1368,16 +1368,7 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
break;
}
} else {
int socket_error;
socklen_t socket_error_len = sizeof(socket_error);
/* try to finish the connect() */
if (0 != getsockopt(hctx->fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"getsockopt failed:", strerror(errno));
return HANDLER_ERROR;
}
int socket_error = fdevent_connect_status(hctx->fd);
if (socket_error != 0) {
log_error_write(srv, __FILE__, __LINE__, "sssd",
"establishing connection failed:", strerror(socket_error),

11
src/mod_scgi.c

@ -1760,16 +1760,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
} else {
int socket_error;
socklen_t socket_error_len = sizeof(socket_error);
/* try to finish the connect() */
if (0 != getsockopt(hctx->fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"getsockopt failed:", strerror(errno));
return HANDLER_ERROR;
}
int socket_error = fdevent_connect_status(hctx->fd);
if (socket_error != 0) {
if (!hctx->proc->is_local || hctx->conf.debug) {
/* local procs get restarted */

Loading…
Cancel
Save