mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
MFH
This commit is contained in:
@@ -102,9 +102,10 @@ typedef struct {
|
||||
} php_sockets_globals;
|
||||
|
||||
/* Prototypes */
|
||||
int open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC);
|
||||
int accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC);
|
||||
int php_read(int bsd_socket, void *buf, size_t maxlen, int flags);
|
||||
static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC);
|
||||
static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC);
|
||||
static int php_read(int bsd_socket, void *buf, size_t maxlen, int flags);
|
||||
static char *php_strerror(int error TSRMLS_DC);
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(sockets)
|
||||
int last_error;
|
||||
|
||||
@@ -181,7 +181,7 @@ ZEND_GET_MODULE(sockets)
|
||||
/* inet_ntop should be used instead of inet_ntoa */
|
||||
int inet_ntoa_lock = 0;
|
||||
|
||||
static void destroy_iovec(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
static void php_destroy_iovec(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
{
|
||||
unsigned int i;
|
||||
php_iovec_t *iov = (php_iovec_t *) rsrc->ptr;
|
||||
@@ -196,7 +196,7 @@ static void destroy_iovec(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
}
|
||||
}
|
||||
|
||||
static void destroy_socket(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
static void php_destroy_socket(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
{
|
||||
php_socket *php_sock = (php_socket *) rsrc->ptr;
|
||||
|
||||
@@ -204,9 +204,7 @@ static void destroy_socket(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
efree(php_sock);
|
||||
}
|
||||
|
||||
static char *php_strerror(int error TSRMLS_DC);
|
||||
|
||||
int open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC)
|
||||
static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC)
|
||||
{
|
||||
struct sockaddr_in la;
|
||||
struct hostent *hp;
|
||||
@@ -254,7 +252,7 @@ int open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC)
|
||||
static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC)
|
||||
{
|
||||
socklen_t salen;
|
||||
php_socket *out_sock = (php_socket*)emalloc(sizeof(php_socket));
|
||||
@@ -274,7 +272,7 @@ int accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *
|
||||
}
|
||||
|
||||
/* {{{ php_read -- wrapper around read() so that it only reads to a \r or \n. */
|
||||
int php_read(int bsd_socket, void *buf, size_t maxlen, int flags)
|
||||
static int php_read(int bsd_socket, void *buf, size_t maxlen, int flags)
|
||||
{
|
||||
int m = 0;
|
||||
size_t n = 0;
|
||||
@@ -335,7 +333,8 @@ int php_read(int bsd_socket, void *buf, size_t maxlen, int flags)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static char *php_strerror(int error TSRMLS_DC) {
|
||||
static char *php_strerror(int error TSRMLS_DC)
|
||||
{
|
||||
const char *buf;
|
||||
|
||||
#ifndef PHP_WIN32
|
||||
@@ -372,7 +371,8 @@ static char *php_strerror(int error TSRMLS_DC) {
|
||||
}
|
||||
|
||||
/* Sets addr by hostname, or by ip in string form (AF_INET) */
|
||||
int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock TSRMLS_DC) {
|
||||
static int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock TSRMLS_DC)
|
||||
{
|
||||
struct in_addr tmp;
|
||||
struct hostent *host_entry;
|
||||
|
||||
@@ -398,13 +398,13 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void php_sockets_init_globals(zend_sockets_globals *sockets_globals TSRMLS_DC)
|
||||
{
|
||||
sockets_globals->last_error = 0;
|
||||
sockets_globals->strerror_buf = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* {{{ PHP_MINIT_FUNCTION
|
||||
*/
|
||||
PHP_MINIT_FUNCTION(sockets)
|
||||
@@ -413,8 +413,8 @@ PHP_MINIT_FUNCTION(sockets)
|
||||
|
||||
ZEND_INIT_MODULE_GLOBALS(sockets, php_sockets_init_globals, NULL);
|
||||
|
||||
le_socket = zend_register_list_destructors_ex(destroy_socket, NULL, le_socket_name, module_number);
|
||||
le_iov = zend_register_list_destructors_ex(destroy_iovec, NULL, le_iov_name, module_number);
|
||||
le_socket = zend_register_list_destructors_ex(php_destroy_socket, NULL, le_socket_name, module_number);
|
||||
le_iov = zend_register_list_destructors_ex(php_destroy_iovec, NULL, le_iov_name, module_number);
|
||||
|
||||
REGISTER_LONG_CONSTANT("AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT);
|
||||
@@ -623,7 +623,7 @@ PHP_FUNCTION(socket_create_listen)
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &backlog) == FAILURE)
|
||||
return;
|
||||
|
||||
if (!open_listen_sock(&php_sock, port, backlog TSRMLS_CC)) {
|
||||
if (!php_open_listen_sock(&php_sock, port, backlog TSRMLS_CC)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ PHP_FUNCTION(socket_accept)
|
||||
|
||||
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
|
||||
|
||||
if (!accept_connect(php_sock, &new_sock, (struct sockaddr *) &sa TSRMLS_CC)) {
|
||||
if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr *) &sa TSRMLS_CC)) {
|
||||
php_error(E_WARNING, "%s() unable to accept socket connection [%d]: %s",
|
||||
get_active_function_name(TSRMLS_C), errno, php_strerror(errno TSRMLS_CC));
|
||||
RETURN_FALSE;
|
||||
|
||||
Reference in New Issue
Block a user