cvs: php4 /ext/ftp ftp.c /ext/standard fsock.c ftp_fopen_wrapper.c http_fopen_wrapper.c /main network.c php_network.h

From: Date: Mon, 22 Jul 2002 18:46:26 +0000
Subject: cvs: php4 /ext/ftp ftp.c /ext/standard fsock.c ftp_fopen_wrapper.c http_fopen_wrapper.c /main network.c php_network.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12936@lists.php.net to get a copy of this message
jason Mon Jul 22 14:46:26 2002 EDT Modified files: /php4/ext/ftp ftp.c /php4/ext/standard fsock.c ftp_fopen_wrapper.c http_fopen_wrapper.c /php4/main network.c php_network.h Log: Switch streams socket abstraction to use a timeval structure instead of an integer to allow subsecond timeouts. This supports the previous behavior of fsockopen() Fixes bug #16261

Index: php4/ext/ftp/ftp.c diff -u php4/ext/ftp/ftp.c:1.51 php4/ext/ftp/ftp.c:1.52 --- php4/ext/ftp/ftp.c:1.51 Wed Jul 10 22:48:00 2002 +++ php4/ext/ftp/ftp.c Mon Jul 22 14:46:26 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ftp.c,v 1.51 2002/07/11 02:48:00 sniper Exp $ */ +/* $Id: ftp.c,v 1.52 2002/07/22 18:46:26 jason Exp $ */ #include "php.h" @@ -105,6 +105,7 @@ { ftpbuf_t *ftp; int size; + struct timeval tv; /* alloc the ftp structure */ @@ -113,8 +114,11 @@ perror("calloc"); return NULL; } + + tv.tv_sec = timeout_sec; + tv.tv_usec = 0; - ftp->fd = php_hostconnect(host, (unsigned short) (port ? port : 21), SOCK_STREAM, (int) timeout_sec); + ftp->fd = php_hostconnect(host, (unsigned short) (port ? port : 21), SOCK_STREAM, &tv); if (ftp->fd == -1) { goto bail; } Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.98 php4/ext/standard/fsock.c:1.99 --- php4/ext/standard/fsock.c:1.98 Sat Jul 13 05:26:36 2002 +++ php4/ext/standard/fsock.c Mon Jul 22 14:46:26 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.98 2002/07/13 09:26:36 sander Exp $ */ +/* $Id: fsock.c,v 1.99 2002/07/22 18:46:26 jason Exp $ */ /* converted to PHP Streams and moved much code to main/network.c [wez] */ @@ -194,7 +194,7 @@ } else #endif - stream = php_stream_sock_open_host(host, (unsigned short)port, socktype, (int)timeout, persistent); + stream = php_stream_sock_open_host(host, (unsigned short)port, socktype, &tv, persistent); #ifdef PHP_WIN32 /* Preserve error */ Index: php4/ext/standard/ftp_fopen_wrapper.c diff -u php4/ext/standard/ftp_fopen_wrapper.c:1.23 php4/ext/standard/ftp_fopen_wrapper.c:1.24 --- php4/ext/standard/ftp_fopen_wrapper.c:1.23 Tue Apr 16 18:14:23 2002 +++ php4/ext/standard/ftp_fopen_wrapper.c Mon Jul 22 14:46:26 2002 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: ftp_fopen_wrapper.c,v 1.23 2002/04/16 22:14:23 wez Exp $ */ +/* $Id: ftp_fopen_wrapper.c,v 1.24 2002/07/22 18:46:26 jason Exp $ */ #include "php.h" #include "php_globals.h" @@ -124,7 +124,7 @@ if (resource->port == 0) resource->port = 21; - stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, 0, 0); + stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); if (stream == NULL) goto errexit; Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.36 php4/ext/standard/http_fopen_wrapper.c:1.37 --- php4/ext/standard/http_fopen_wrapper.c:1.36 Wed Jul 10 22:35:45 2002 +++ php4/ext/standard/http_fopen_wrapper.c Mon Jul 22 14:46:26 2002 @@ -18,7 +18,7 @@ | Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: http_fopen_wrapper.c,v 1.36 2002/07/11 02:35:45 sniper Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.37 2002/07/22 18:46:26 jason Exp $ */ #include "php.h" #include "php_globals.h" @@ -98,7 +98,7 @@ else if (resource->port == 0) resource->port = 80; - stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, 0, 0); + stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); if (stream == NULL) goto out; Index: php4/main/network.c diff -u php4/main/network.c:1.53 php4/main/network.c:1.54 --- php4/main/network.c:1.53 Fri Jul 19 16:34:35 2002 +++ php4/main/network.c Mon Jul 22 14:46:26 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: network.c,v 1.53 2002/07/19 20:34:35 jason Exp $ */ +/* $Id: network.c,v 1.54 2002/07/22 18:46:26 jason Exp $ */ /*#define DEBUG_MAIN_NETWORK 1*/ #define MAX_CHUNKS_PER_READ 10 @@ -366,11 +366,12 @@ * port, returns the created socket on success, else returns -1. * timeout gives timeout in seconds, 0 means blocking mode. */ -int php_hostconnect(const char *host, unsigned short port, int socktype, int timeout) +int php_hostconnect(const char *host, unsigned short port, int socktype, struct timeval *timeout) { int n, repeatto, s; struct sockaddr **sal, **psal; - struct timeval timeoutval; + struct timeval individual_timeout; + int set_timeout = 0; #ifdef PHP_WIN32 int err; #endif @@ -380,14 +381,24 @@ if (n == 0) return -1; - /* is this a good idea? 5s? */ - repeatto = timeout / n > 5; - if (repeatto) { - timeout /= n; - } - timeoutval.tv_sec = timeout; - timeoutval.tv_usec = 0; + if (timeout != NULL) { + /* is this a good idea? 5s? */ + repeatto = timeout->tv_sec / n > 5; + if (repeatto) { + individual_timeout.tv_sec = timeout->tv_sec / n; + } else { + individual_timeout.tv_sec = timeout->tv_sec; + } + individual_timeout.tv_usec = timeout->tv_usec; + } else { + individual_timeout.tv_sec = 0; + individual_timeout.tv_usec = 0; + } + + /* Boolean indicating whether to pass a timeout */ + set_timeout = individual_timeout.tv_sec + individual_timeout.tv_usec; + psal = sal; while (*sal != NULL) { s = socket((*sal)->sa_family, socktype, 0); @@ -402,7 +413,7 @@ sa->sin6_family = (*sal)->sa_family; sa->sin6_port = htons(port); if (php_connect_nonb(s, (struct sockaddr *) sa, - sizeof(*sa), timeout ? &timeoutval : NULL) != SOCK_CONN_ERR) + sizeof(*sa), (set_timeout) ? &individual_timeout : NULL) != SOCK_CONN_ERR) goto ok; } break; @@ -415,7 +426,7 @@ sa->sin_family = (*sal)->sa_family; sa->sin_port = htons(port); if (php_connect_nonb(s, (struct sockaddr *) sa, - sizeof(*sa), timeout ? &timeoutval : NULL) != SOCK_CONN_ERR) + sizeof(*sa), (set_timeout) ? &individual_timeout : NULL) != SOCK_CONN_ERR) goto ok; } @@ -428,10 +439,6 @@ close (s); } sal++; - if (repeatto) { - timeoutval.tv_sec = timeout; - timeoutval.tv_usec = 0; - } } php_network_freeaddresses(psal); php_error(E_WARNING, "php_hostconnect: connect failed"); @@ -520,7 +527,7 @@ } PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port, - int socktype, int timeout, int persistent STREAMS_DC TSRMLS_DC) + int socktype, struct timeval *timeout, int persistent STREAMS_DC TSRMLS_DC) { int socket; Index: php4/main/php_network.h diff -u php4/main/php_network.h:1.22 php4/main/php_network.h:1.23 --- php4/main/php_network.h:1.22 Fri Jul 19 16:34:35 2002 +++ php4/main/php_network.h Mon Jul 22 14:46:26 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: php_network.h,v 1.22 2002/07/19 20:34:35 jason Exp $ */ +/* $Id: php_network.h,v 1.23 2002/07/22 18:46:26 jason Exp $ */ #ifndef _PHP_NETWORK_H #define _PHP_NETWORK_H @@ -91,7 +91,7 @@ #endif -int php_hostconnect(const char *host, unsigned short port, int socktype, int timeout); +int php_hostconnect(const char *host, unsigned short port, int socktype, struct timeval *timeout); PHPAPI int php_connect_nonb(int sockfd, const struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout); #ifdef PHP_WIN32 @@ -128,7 +128,7 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, int persistent STREAMS_DC TSRMLS_DC ); /* open a connection to a host using php_hostconnect and return a stream */ PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port, - int socktype, int timeout, int persistent STREAMS_DC TSRMLS_DC); + int socktype, struct timeval *timeout, int persistent STREAMS_DC TSRMLS_DC); PHPAPI php_stream *_php_stream_sock_open_unix(const char *path, int pathlen, int persistent, struct timeval *timeout STREAMS_DC TSRMLS_DC);
« previous php.cvs (#12936) next »