samples/c/1/mod_fastcgi.c
static int fcgi_establish_connection(server *srv, handler_ctx *hctx) {
	struct sockaddr *fcgi_addr;
	struct sockaddr_in fcgi_addr_in;
#ifdef HAVE_SYS_UN_H
	struct sockaddr_un fcgi_addr_un;
#endif
	socklen_t servlen;
	
	fcgi_extension_host *host = hctx->host;
	fcgi_proc *proc   = hctx->proc;
	int fcgi_fd       = hctx->fd;
	
	memset(&fcgi_addr, 0, sizeof(fcgi_addr));
	
	if (!buffer_is_empty(proc->socket)) {
#ifdef HAVE_SYS_UN_H
		/* use the unix domain socket */
		fcgi_addr_un.sun_family = AF_UNIX;
		strcpy(fcgi_addr_un.sun_path, proc->socket->ptr);
#ifdef SUN_LEN
		servlen = SUN_LEN(&fcgi_addr_un);
#else
		/* stevens says: */
		servlen = proc->socket->used - 1 + sizeof(fcgi_addr_un.sun_family);
#endif
		fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
#else
		return -1;
#endif
	} else {
		fcgi_addr_in.sin_family = AF_INET;
		if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) {
			log_error_write(srv, __FILE__, __LINE__, "sbs", 
					"converting IP-adress failed for", host->host, 
					"\nBe sure to specify an IP address here");
			
			return -1;
		}
		fcgi_addr_in.sin_port = htons(proc->port);
		servlen = sizeof(fcgi_addr_in);
		
		fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
	}
	
	if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
		if (errno == EINPROGRESS || 
		    errno == EALREADY ||
		    errno == EINTR) {
			if (hctx->conf.debug) {
				log_error_write(srv, __FILE__, __LINE__, "sd", 
						"connect delayed, will continue later:", fcgi_fd);
			}
			
			return 1;
		} else {
			log_error_write(srv, __FILE__, __LINE__, "sdsddb", 
					"connect failed:", fcgi_fd, 
					strerror(errno), errno,
					proc->port, proc->socket);

			if (errno == EAGAIN) {
				log_error_write(srv, __FILE__, __LINE__, "sd", 
						"This means that the you have more incoming requests than your fastcgi-backend can handle in parallel. "
						"Perhaps it helps to spawn more fastcgi backend or php-children, if not decrease server.max-connections."
						"The load for this fastcgi backend is:", proc->load);
			} 
			
			return -1;
		}
	}
	if (hctx->conf.debug > 1) {
		log_error_write(srv, __FILE__, __LINE__, "sd", 
				"connect succeeded: ", fcgi_fd);
	}


	
	return 0;
}
/**
 * 
 * returns
 *   -1 error
 *    0 connected
 *    1 not connected yet
 */
1 error
0 connected
1 not connected yet
1 error 0 connected 1 not connected yet
static int fcgi_establish_connection(server *srv, handler_ctx *hctx) {
	struct sockaddr *fcgi_addr;
	struct sockaddr_in fcgi_addr_in;
#ifdef HAVE_SYS_UN_H
	struct sockaddr_un fcgi_addr_un;
#endif
	socklen_t servlen;
	fcgi_extension_host *host = hctx->host;
	fcgi_proc *proc   = hctx->proc;
	int fcgi_fd       = hctx->fd;
	memset(&fcgi_addr, 0, sizeof(fcgi_addr));
	if (!buffer_is_empty(proc->socket)) {
#ifdef HAVE_SYS_UN_H
		fcgi_addr_un.sun_family = AF_UNIX;
		strcpy(fcgi_addr_un.sun_path, proc->socket->ptr);
#ifdef SUN_LEN
		servlen = SUN_LEN(&fcgi_addr_un);
#else
		servlen = proc->socket->used - 1 + sizeof(fcgi_addr_un.sun_family);
#endif
		fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
#else
		return -1;
#endif
	} else {
		fcgi_addr_in.sin_family = AF_INET;
		if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) {
			log_error_write(srv, __FILE__, __LINE__, "sbs", 
					"converting IP-adress failed for", host->host, 
					"\nBe sure to specify an IP address here");
			return -1;
		}
		fcgi_addr_in.sin_port = htons(proc->port);
		servlen = sizeof(fcgi_addr_in);
		fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
	}
	if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
		if (errno == EINPROGRESS || 
		    errno == EALREADY ||
		    errno == EINTR) {
			if (hctx->conf.debug) {
				log_error_write(srv, __FILE__, __LINE__, "sd", 
						"connect delayed, will continue later:", fcgi_fd);
			}
			return 1;
		} else {
			log_error_write(srv, __FILE__, __LINE__, "sdsddb", 
					"connect failed:", fcgi_fd, 
					strerror(errno), errno,
					proc->port, proc->socket);
			if (errno == EAGAIN) {
				log_error_write(srv, __FILE__, __LINE__, "sd", 
						"This means that the you have more incoming requests than your fastcgi-backend can handle in parallel. "
						"Perhaps it helps to spawn more fastcgi backend or php-children, if not decrease server.max-connections."
						"The load for this fastcgi backend is:", proc->load);
			} 
			return -1;
		}
	}
	if (hctx->conf.debug > 1) {
		log_error_write(srv, __FILE__, __LINE__, "sd", 
				"connect succeeded: ", fcgi_fd);
	}
	return 0;
}
static int fcgi_establish_connection ( server * srv , handler_ctx * hctx ) { struct sockaddr * fcgi_addr ; struct sockaddr_in fcgi_addr_in ; #ifdef HAVE_SYS_UN_H struct sockaddr_un fcgi_addr_un ; #endif socklen_t servlen ; fcgi_extension_host * host = hctx -> host ; fcgi_proc * proc = hctx -> proc ; int fcgi_fd = hctx -> fd ; memset ( & fcgi_addr , 0 , sizeof ( fcgi_addr ) ) ; if ( ! buffer_is_empty ( proc -> socket ) ) { #ifdef HAVE_SYS_UN_H fcgi_addr_un . sun_family = AF_UNIX ; strcpy ( fcgi_addr_un . sun_path , proc -> socket -> ptr ) ; #ifdef SUN_LEN servlen = SUN_LEN ( & fcgi_addr_un ) ; #else servlen = proc -> socket -> used - 1 + sizeof ( fcgi_addr_un . sun_family ) ; #endif fcgi_addr = ( struct sockaddr * ) & fcgi_addr_un ; #else return -1 ; #endif } else { fcgi_addr_in . sin_family = AF_INET ; if ( 0 == inet_aton ( host -> host -> ptr , & ( fcgi_addr_in . sin_addr ) ) ) { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " , host -> host , " \n " ) ; return -1 ; } fcgi_addr_in . sin_port = htons ( proc -> port ) ; servlen = sizeof ( fcgi_addr_in ) ; fcgi_addr = ( struct sockaddr * ) & fcgi_addr_in ; } if ( -1 == connect ( fcgi_fd , fcgi_addr , servlen ) ) { if ( errno == EINPROGRESS || errno == EALREADY || errno == EINTR ) { if ( hctx -> conf . debug ) { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " , fcgi_fd ) ; } return 1 ; } else { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " , fcgi_fd , strerror ( errno ) , errno , proc -> port , proc -> socket ) ; if ( errno == EAGAIN ) { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " " " " " , proc -> load ) ; } return -1 ; } } if ( hctx -> conf . debug > 1 ) { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " , fcgi_fd ) ; } return 0 ; }
returns
   -1 error
    0 connected
    1 not connected yet
returns - 1 error 0 connected 1 not connected yet
/* use the unix domain socket */ /* stevens says: */