/* inet_ntop should be used instead of inet_ntoa */
int inet_ntoa_lock = 0;
-static void php_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;
close(php_sock->bsd_socket);
efree(php_sock);
}
+/* }}} */
-static int php_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;
return 1;
}
+/* }}} */
-static int php_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));
return 1;
}
+/* }}} */
/* {{{ php_read -- wrapper around read() so that it only reads to a \r or \n. */
static 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;
return (buf ? (char *) buf : "");
}
+/* }}} */
#if HAVE_IPV6
/* Sets addr by hostname, or by ip in string form (AF_INET6) */
-static int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC)
+static int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC) /* {{{ */
{
struct in6_addr tmp;
#if HAVE_GETADDRINFO
return 1;
}
+/* }}} */
#endif
/* Sets addr by hostname, or by ip in string form (AF_INET) */
-static 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;
return 1;
}
+/* }}} */
+/* {{{ PHP_GINIT_FUNCTION */
static PHP_GINIT_FUNCTION(sockets)
{
sockets_globals->last_error = 0;
sockets_globals->strerror_buf = NULL;
}
+/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
}
/* }}} */
-static int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, PHP_SOCKET *max_fd TSRMLS_DC)
+static int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, PHP_SOCKET *max_fd TSRMLS_DC) /* {{{ */
{
zval **element;
php_socket *php_sock;
return num ? 1 : 0;
}
+/* }}} */
-static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC)
+static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) /* {{{ */
{
zval **element;
zval **dest_element;
return num ? 1 : 0;
}
+/* }}} */
-/* {{{ proto int socket_select(array &read_fds, array &write_fds, &array except_fds, int tv_sec[, int tv_usec])
+/* {{{ proto int socket_select(array &read_fds, array &write_fds, &array except_fds, int tv_sec[, int tv_usec]) U
Runs the select() system call on the sets mentioned with a timeout specified by tv_sec and tv_usec */
PHP_FUNCTION(socket_select)
{
int retval, sets = 0;
long usec = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) {
return;
+ }
FD_ZERO(&rfds);
FD_ZERO(&wfds);
}
/* }}} */
-/* {{{ proto resource socket_create_listen(int port[, int backlog])
+/* {{{ proto resource socket_create_listen(int port[, int backlog]) U
Opens a socket on port to accept connections */
PHP_FUNCTION(socket_create_listen)
{
php_socket *php_sock;
long port, backlog = 128;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &backlog) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &backlog) == FAILURE) {
return;
+ }
if (!php_open_listen_sock(&php_sock, port, backlog TSRMLS_CC)) {
RETURN_FALSE;
}
/* }}} */
-/* {{{ proto resource socket_accept(resource socket)
+/* {{{ proto resource socket_accept(resource socket) U
Accepts a connection on the listening socket fd */
PHP_FUNCTION(socket_accept)
{
php_socket *php_sock, *new_sock;
struct sockaddr_in sa;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto bool socket_set_nonblock(resource socket)
+/* {{{ proto bool socket_set_nonblock(resource socket) U
Sets nonblocking mode on a socket resource */
PHP_FUNCTION(socket_set_nonblock)
{
php_socket *php_sock;
int flags;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto bool socket_set_block(resource socket)
+/* {{{ proto bool socket_set_block(resource socket) U
Sets blocking mode on a socket resource */
PHP_FUNCTION(socket_set_block)
{
php_socket *php_sock;
int flags;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto bool socket_listen(resource socket[, int backlog])
+/* {{{ proto bool socket_listen(resource socket[, int backlog]) U
Sets the maximum number of connections allowed to be waited for on the socket specified by fd */
PHP_FUNCTION(socket_listen)
{
zval *arg1;
php_socket *php_sock;
- long backlog = 0;
+ long backlog = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &backlog) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &backlog) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto void socket_close(resource socket)
+/* {{{ proto void socket_close(resource socket) U
Closes a file descriptor */
PHP_FUNCTION(socket_close)
{
zval *arg1;
php_socket *php_sock;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
zend_list_delete(Z_RESVAL_P(arg1));
zval *arg1;
php_socket *php_sock;
int retval, str_len;
- long length;
+ long length;
char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &str, &str_len, &length) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &str, &str_len, &length) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto string socket_read(resource socket, int length [, int type])
+/* {{{ proto string socket_read(resource socket, int length [, int type]) U
Reads a maximum of length bytes from socket */
PHP_FUNCTION(socket_read)
{
int retval;
long length, type = PHP_BINARY_READ;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &length, &type) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &length, &type) == FAILURE) {
return;
+ }
/* overflow check */
if ((length + 1) < 2) {
char *addr_string;
socklen_t salen = sizeof(php_sockaddr_storage);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &addr, &port) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &addr, &port) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
char *addr_string;
socklen_t salen = sizeof(php_sockaddr_storage);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &arg2, &arg3) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &arg2, &arg3) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto resource socket_create(int domain, int type, int protocol)
+/* {{{ proto resource socket_create(int domain, int type, int protocol) U
Creates an endpoint for communication in the domain specified by domain, of type specified by type */
PHP_FUNCTION(socket_create)
{
long port;
int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE)
+ if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
{
long arg1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &arg1) == FAILURE) {
return;
+ }
RETURN_STRING(php_strerror(arg1 TSRMLS_CC), 1);
}
long port = 0;
long retval = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
int retval;
long len, flags;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzll", &php_sock_res, &buf, &len, &flags) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzll", &php_sock_res, &buf, &len, &flags) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &php_sock_res, -1, le_socket_name, le_socket);
long len, flags;
char *buf;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsll", &arg1, &buf, &buf_len, &len, &flags) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsll", &arg1, &buf, &buf_len, &len, &flags) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
long arg3, arg4;
char *recv_buf, *address;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzllz|z", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzllz|z", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
char *buf, *addr;
int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE)
+ if (zend_parse_parameters(argc TSRMLS_CC, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto mixed socket_get_option(resource socket, int level, int optname)
+/* {{{ proto mixed socket_get_option(resource socket, int level, int optname) U
Gets socket options for the socket */
PHP_FUNCTION(socket_get_option)
{
int other_val;
long level, optname;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &arg1, &level, &optname) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &arg1, &level, &optname) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
char *sec_key = "sec";
char *usec_key = "usec";
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllZ", &arg1, &level, &optname, &arg4) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllZ", &arg1, &level, &optname, &arg4) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto bool socket_create_pair(int domain, int type, int protocol, array &fd)
+/* {{{ proto bool socket_create_pair(int domain, int type, int protocol, array &fd) U
Creates a pair of indistinguishable sockets and stores them in fds. */
PHP_FUNCTION(socket_create_pair)
{
PHP_SOCKET fds_array[2];
long domain, type, protocol;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz", &domain, &type, &protocol, &fds_array_zval) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz", &domain, &type, &protocol, &fds_array_zval) == FAILURE) {
return;
+ }
php_sock[0] = (php_socket*)emalloc(sizeof(php_socket));
php_sock[1] = (php_socket*)emalloc(sizeof(php_socket));
}
/* }}} */
-/* {{{ proto bool socket_shutdown(resource socket[, int how])
+/* {{{ proto bool socket_shutdown(resource socket[, int how]) U
Shuts down a socket for receiving, sending, or both. */
PHP_FUNCTION(socket_shutdown)
{
long how_shutdown = 2;
php_socket *php_sock;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &how_shutdown) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &how_shutdown) == FAILURE) {
return;
+ }
ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto int socket_last_error([resource socket])
+/* {{{ proto int socket_last_error([resource socket]) U
Returns the last socket error (either the last used or the provided socket resource) */
PHP_FUNCTION(socket_last_error)
{
zval *arg1 = NULL;
php_socket *php_sock;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE) {
return;
+ }
if (arg1) {
ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket);
}
/* }}} */
-/* {{{ proto void socket_clear_error([resource socket])
+/* {{{ proto void socket_clear_error([resource socket]) U
Clears the error on the socket or the last error code. */
PHP_FUNCTION(socket_clear_error)
{
zval *arg1 = NULL;
php_socket *php_sock;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE) {
return;
+ }
if (arg1) {
ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket);