CVS update: php3/functions

From: Date: Sun, 24 Jan 1999 23:53:19 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-3708@lists.php.net to get a copy of this message
Date: Sunday January 24, 1999 @ 18:53 Author: sas Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv10227/functions Modified Files: basic_functions.c file.c fsock.c fsock.h Log Message: Add persistent fsockopen() support Index: php3/functions/basic_functions.c diff -c php3/functions/basic_functions.c:1.251 php3/functions/basic_functions.c:1.252 *** php3/functions/basic_functions.c:1.251 Fri Jan 22 16:24:42 1999 --- php3/functions/basic_functions.c Sun Jan 24 18:53:18 1999 *************** *** 28,34 **** +----------------------------------------------------------------------+ */ ! /* $Id: basic_functions.c,v 1.251 1999/01/22 21:24:42 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 28,34 ---- +----------------------------------------------------------------------+ */ ! /* $Id: basic_functions.c,v 1.252 1999/01/24 23:53:18 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 155,161 **** {"rtrim", php3_chop, NULL}, {"pos", array_current, first_arg_force_ref}, - {"fsockopen", php3_fsockopen, third_and_fourth_args_force_ref}, {"getimagesize", php3_getimagesize, NULL}, {"htmlspecialchars", php3_htmlspecialchars, NULL}, {"htmlentities", php3_htmlentities, NULL}, --- 155,160 ---- Index: php3/functions/file.c diff -c php3/functions/file.c:1.195 php3/functions/file.c:1.196 *** php3/functions/file.c:1.195 Fri Jan 22 16:29:06 1999 --- php3/functions/file.c Sun Jan 24 18:53:18 1999 *************** *** 26,32 **** | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: file.c,v 1.195 1999/01/22 21:29:06 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 26,32 ---- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: file.c,v 1.196 1999/01/24 23:53:18 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 424,434 **** --- 424,436 ---- static void _php3_closesocket(int *sock) { int socketd=*sock; if (socketd){ + if(!_php3_is_persistent_sock(socketd)) { #if WIN32|WINNT closesocket(socketd); #else close(socketd); #endif + } efree(sock); } } Index: php3/functions/fsock.c diff -c php3/functions/fsock.c:1.79 php3/functions/fsock.c:1.80 *** php3/functions/fsock.c:1.79 Fri Jan 22 15:55:49 1999 --- php3/functions/fsock.c Sun Jan 24 18:53:18 1999 *************** *** 27,33 **** | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.c,v 1.79 1999/01/22 20:55:49 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 27,33 ---- | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.c,v 1.80 1999/01/24 23:53:18 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 70,76 **** extern int le_fp; #endif ! #define FREE_SOCK efree(sock) #if WIN32|WINNT #define EWOULDBLOCK WSAEWOULDBLOCK --- 70,76 ---- extern int le_fp; #endif ! #define FREE_SOCK efree(sock); if (key) efree(key) #if WIN32|WINNT #define EWOULDBLOCK WSAEWOULDBLOCK *************** *** 78,83 **** --- 78,103 ---- #include "build-defs.h" #endif + function_entry fsock_functions[] = { + PHP_FE(fsockopen, NULL) + PHP_FE(pfsockopen, NULL) + {NULL, NULL, NULL} + }; + + static int php3_minit_fsock(INIT_FUNC_ARGS); + static int php3_mshutdown_fsock(void); + + php3_module_entry fsock_module_entry = { + "Socket functions", fsock_functions, php3_minit_fsock, php3_mshutdown_fsock, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES + }; + + #ifndef THREAD_SAFE + static HashTable ht_keys; + static HashTable ht_socks; + #endif + + /* {{{ lookup_hostname */ + /* * Converts a host name to an IP address. */ *************** *** 95,113 **** } return 0; } /* This function takes an optional third argument which should be passed by reference. The error code from the connect call is written to this variable. */ ! /* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr]]) ! Open Internet or Unix domain socket connection */ ! void php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS) { pval *args[4]; int *sock=emalloc(sizeof(int)); int id, socketd, arg_count=ARG_COUNT(ht); unsigned short portno; TLS_VARS; if (arg_count > 4 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) { --- 115,148 ---- } return 0; } + /* }}} */ + /* {{{ _php3_is_persistent_sock */ + + int _php3_is_persistent_sock(int sock) + { + char *key; + + if (_php3_hash_find(&ht_socks, (char *) &sock, sizeof(sock), + (void **) &key) == SUCCESS) { + return 1; + } + return 0; + } + /* }}} */ + /* {{{ _php3_fsockopen() */ /* This function takes an optional third argument which should be passed by reference. The error code from the connect call is written to this variable. */ ! static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) { pval *args[4]; int *sock=emalloc(sizeof(int)); + int *sockp; int id, socketd, arg_count=ARG_COUNT(ht); unsigned short portno; + char *key = NULL; TLS_VARS; if (arg_count > 4 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) { *************** *** 136,141 **** --- 171,186 ---- convert_to_long(args[1]); portno = (unsigned short) args[1]->value.lval; + key = emalloc(args[0]->value.str.len + 10); + sprintf(key, "%s:%d", args[0]->value.str.val, portno); + + if (persistent && _php3_hash_find(&ht_keys, key, strlen(key) + 1, + (void *) &sockp) == SUCCESS) { + efree(key); + *sock = *sockp; + RETURN_LONG(php3_list_insert(sock, GLOBAL(wsa_fp))); + } + if (portno) { struct sockaddr_in server; *************** *** 203,213 **** --- 248,280 ---- #endif *sock=socketd; + if (persistent) { + _php3_hash_update(&ht_keys, key, strlen(key) + 1, + sock, sizeof(*sock), NULL); + _php3_hash_update(&ht_socks, (char *) sock, sizeof(*sock), + key, strlen(key) + 1, NULL); + } + if(key) efree(key); id = php3_list_insert(sock,GLOBAL(wsa_fp)); RETURN_LONG(id); } /* }}} */ + /* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr]]) + Open Internet or Unix domain socket connection */ + PHP_FUNCTION(fsockopen) + { + _php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + } + /* }}} */ + + /* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr]]) + Open persistent Internet or Unix domain socket connection */ + PHP_FUNCTION(pfsockopen) + { + _php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + } + /* }}} */ int _php3_sock_fgets(char *buf, int maxlen, int socket) { *************** *** 242,247 **** --- 309,351 ---- *buf = '\0'; return count; } + + /* {{{ module start/shutdown functions */ + + /* {{{ _php3_sock_destroy */ + #ifndef THREAD_SAFE + static void _php3_sock_destroy(void *data) + { + int *sock = (int *) data; + + close(*sock); + } + #endif + /* }}} */ + /* {{{ php3_minit_fsock */ + + static int php3_minit_fsock(INIT_FUNC_ARGS) + { + #ifndef THREAD_SAFE + _php3_hash_init(&ht_keys, 0, NULL, NULL, 1); + _php3_hash_init(&ht_socks, 0, NULL, _php3_sock_destroy, 1); + #endif + return SUCCESS; + } + /* }}} */ + /* {{{ php3_mshutdown_fsock */ + + static int php3_mshutdown_fsock(void) + { + #ifndef THREAD_SAFE + _php3_hash_destroy(&ht_socks); + _php3_hash_destroy(&ht_keys); + #endif + return SUCCESS; + } + /* }}} */ + /* }}} */ + /* * Local variables: * tab-width: 4 Index: php3/functions/fsock.h diff -c php3/functions/fsock.h:1.15 php3/functions/fsock.h:1.16 *** php3/functions/fsock.h:1.15 Thu Jan 21 16:20:23 1999 --- php3/functions/fsock.h Sun Jan 24 18:53:19 1999 *************** *** 27,40 **** | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.h,v 1.15 1999/01/21 21:20:23 sas Exp $ */ #ifndef _FSOCK_H #define _FSOCK_H ! extern void php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS); extern int lookup_hostname(const char *addr, struct in_addr *in); extern int _php3_sock_fgets(char *buf, int maxlen, int socket); extern int _php3_sock_fread(char *buf, int maxlen, int socket); #endif /* _FSOCK_H */ --- 27,45 ---- | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.h,v 1.16 1999/01/24 23:53:19 sas Exp $ */ #ifndef _FSOCK_H #define _FSOCK_H ! extern php3_module_entry fsock_module_entry; ! #define fsock_module_ptr &fsock_module_entry ! ! extern PHP_FUNCTION(fsockopen); ! extern PHP_FUNCTION(pfsockopen); extern int lookup_hostname(const char *addr, struct in_addr *in); extern int _php3_sock_fgets(char *buf, int maxlen, int socket); extern int _php3_sock_fread(char *buf, int maxlen, int socket); + extern int _php3_is_persistent_sock(int); #endif /* _FSOCK_H */ -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3708) next »