cvs: php4 /ext/standard fsock.c

From: Date: Fri, 17 Aug 2001 06:53:26 +0000
Subject: cvs: php4 /ext/standard fsock.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6906@lists.php.net to get a copy of this message
sterling Fri Aug 17 02:53:26 2001 EDT Modified files: /php4/ext/standard fsock.c Log: Clean up the function for the Zend API (php3, early php4 relics removed). Use PF_INET, instead of AF_INET, if present. remove some code enclosed in #if 0 ... #endif that made no sense Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.76 php4/ext/standard/fsock.c:1.77 --- php4/ext/standard/fsock.c:1.76 Sat Aug 11 13:03:37 2001 +++ php4/ext/standard/fsock.c Fri Aug 17 02:53:26 2001 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.76 2001/08/11 17:03:37 zeev Exp $ */ +/* $Id: fsock.c,v 1.77 2001/08/17 06:53:26 sterling Exp $ */ /* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ /* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ @@ -62,6 +62,14 @@ #include <sys/select.h> #endif +#ifndef PF_INET +#define PF_INET AF_INET +#endif + +#ifndef PF_UNIX +#define PF_UNIX AF_UNIX +#endif + #include <string.h> #include <errno.h> @@ -168,25 +176,25 @@ switch(arg_count) { case 5: convert_to_double_ex(args[4]); - conv = (unsigned long) ((*args[4])->value.dval * 1000000.0); + conv = (unsigned long) (Z_DVAL_PP(args[4]) * 1000000.0); timeout.tv_sec = conv / 1000000; timeout.tv_usec = conv % 1000000; /* fall-through */ case 4: - zval_dtor(*args[3]); + zval_ptr_dtor(args[3]); ZVAL_STRING(*args[3], "", 1); /* fall-through */ case 3: - zval_dtor(*args[2]); + zval_ptr_dtor(args[2]); ZVAL_LONG(*args[2], 0); break; } convert_to_string_ex(args[0]); convert_to_long_ex(args[1]); - portno = (unsigned short) (*args[1])->value.lval; + portno = (unsigned short) Z_LVAL_PP(args[1]); - key = emalloc((*args[0])->value.str.len + 10); - sprintf(key, "%s:%d", (*args[0])->value.str.val, portno); + key = emalloc(Z_STRLEN_PP(args[0]) + 10); + sprintf(key, "%s:%d", Z_STRVAL_PP(args[0]), portno); if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1, (void *) &sockp) == SUCCESS) { @@ -204,8 +212,7 @@ udp = 1; } - socketd = socket(AF_INET, udp ? SOCK_DGRAM : SOCK_STREAM, 0); - + socketd = socket(PF_INET, udp ? SOCK_DGRAM : SOCK_STREAM, 0); if (socketd == SOCK_ERR) { CLOSE_SOCK(1); RETURN_FALSE; @@ -213,22 +220,22 @@ server.sin_family = AF_INET; - if(php_lookup_hostname(udp ? &(*args[0])->value.str.val[6] : (*args[0])->value.str.val, &server.sin_addr)) { + if(php_lookup_hostname(udp ? &Z_STRVAL_PP(args[0])[6] : Z_STRVAL_PP(args[0]), &server.sin_addr)) { CLOSE_SOCK(1); RETURN_FALSE; } server.sin_port = htons(portno); - if (php_connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) { + if (php_connect_nonb(socketd, (struct sockaddr *) &server, sizeof(server), &timeout) == SOCK_CONN_ERR) { CLOSE_SOCK(1); if (arg_count>2) { - zval_dtor(*args[2]); + zval_ptr_dtor(args[2]); ZVAL_LONG(*args[2], errno); } if (arg_count>3) { - zval_dtor(*args[3]); + zval_ptr_dtor(args[3]); ZVAL_STRING(*args[3], strerror(errno), 1); } RETURN_FALSE; @@ -237,24 +244,24 @@ } else { /* Unix domain socket. s->strval is socket name. */ struct sockaddr_un unix_addr; - socketd = socket(AF_UNIX, SOCK_STREAM, 0); + socketd = socket(PF_UNIX, SOCK_STREAM, 0); if (socketd == SOCK_ERR) { CLOSE_SOCK(1); RETURN_FALSE; } - memset(&unix_addr, (char)0, sizeof(unix_addr)); + memset(&unix_addr, 0, sizeof(unix_addr)); unix_addr.sun_family = AF_UNIX; - strlcpy(unix_addr.sun_path, (*args[0])->value.str.val, sizeof(unix_addr.sun_path)); + strlcpy(unix_addr.sun_path, Z_STRVAL_PP(args[0]), sizeof(unix_addr.sun_path)); if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) { CLOSE_SOCK(1); if (arg_count>2) { - zval_dtor(*args[2]); + zval_ptr_dtor(args[2]); ZVAL_LONG(*args[2], errno); } if (arg_count>3) { - zval_dtor(*args[3]); + zval_ptr_dtor(args[3]); ZVAL_STRING(*args[3], strerror(errno), 1); } RETURN_FALSE; @@ -262,26 +269,16 @@ #endif /* AF_UNIX */ } -#if 0 - if ((fp = fdopen (socketd, "r+")) == NULL){ - RETURN_LONG(-6); /* FIXME */ - } - -#ifdef HAVE_SETVBUF - if ((setvbuf(fp, NULL, _IONBF, 0)) != 0){ - RETURN_LONG(-7); /* FIXME */ - } -#endif -#endif - - *sock=socketd; + *sock = socketd; if (persistent) { zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1, sock, sizeof(*sock), NULL); zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock), key, strlen(key) + 1, NULL); } - if(key) efree(key); + + if(key) + efree(key); ZEND_REGISTER_RESOURCE(return_value, sock, php_file_le_socket()); }

« previous php.cvs (#6906) next »