]> granicus.if.org Git - php/commitdiff
Cleanup some multicast code; fix for mac os x?
authorGustavo Lopes <glopes@nebm.ist.utl.pt>
Sun, 17 Feb 2013 12:23:07 +0000 (13:23 +0100)
committerGustavo Lopes <glopes@nebm.ist.utl.pt>
Sun, 17 Feb 2013 21:42:58 +0000 (22:42 +0100)
When I moved some stuff from sockets.c to multicast.c, I did not copy
some conditional defines for systems without the RFC 3678 API.

I moved such defines to multicast.h so both sockets.c and multicast.c
can benefit from them and I prefixed them with PHP_ so that it's less
confusing: now PHP_MCAST_* are defined to either the MCAST_* RFC 3678
APIs or to legacy APIs and MCAST_* always mean the (possibly undefined)
system definitions.

ext/sockets/multicast.c
ext/sockets/multicast.h
ext/sockets/sockets.c

index c6de3198e465825a55bb2a05944e3034a1b90ced..94f845d662ca87cd64347a3da7e24c82513c090e 100644 (file)
@@ -152,10 +152,10 @@ static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *
 #endif
 
        switch (optname) {
-       case MCAST_JOIN_GROUP:
+       case PHP_MCAST_JOIN_GROUP:
                mcast_req_fun = &php_mcast_join;
                goto mcast_req_fun;
-       case MCAST_LEAVE_GROUP:
+       case PHP_MCAST_LEAVE_GROUP:
                {
                        php_sockaddr_storage    group = {0};
                        socklen_t                               glen;
@@ -180,16 +180,16 @@ mcast_req_fun:
                }
 
 #ifdef HAS_MCAST_EXT
-       case MCAST_BLOCK_SOURCE:
+       case PHP_MCAST_BLOCK_SOURCE:
                mcast_sreq_fun = &php_mcast_block_source;
                goto mcast_sreq_fun;
-       case MCAST_UNBLOCK_SOURCE:
+       case PHP_MCAST_UNBLOCK_SOURCE:
                mcast_sreq_fun = &php_mcast_unblock_source;
                goto mcast_sreq_fun;
-       case MCAST_JOIN_SOURCE_GROUP:
+       case PHP_MCAST_JOIN_SOURCE_GROUP:
                mcast_sreq_fun = &php_mcast_join_source;
                goto mcast_sreq_fun;
-       case MCAST_LEAVE_SOURCE_GROUP:
+       case PHP_MCAST_LEAVE_SOURCE_GROUP:
                {
                        php_sockaddr_storage    group = {0},
                                                                        source = {0};
@@ -248,13 +248,13 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
        int                             retval;
 
        switch (optname) {
-       case MCAST_JOIN_GROUP:
-       case MCAST_LEAVE_GROUP:
+       case PHP_MCAST_JOIN_GROUP:
+       case PHP_MCAST_LEAVE_GROUP:
 #ifdef HAS_MCAST_EXT
-       case MCAST_BLOCK_SOURCE:
-       case MCAST_UNBLOCK_SOURCE:
-       case MCAST_JOIN_SOURCE_GROUP:
-       case MCAST_LEAVE_SOURCE_GROUP:
+       case PHP_MCAST_BLOCK_SOURCE:
+       case PHP_MCAST_UNBLOCK_SOURCE:
+       case PHP_MCAST_JOIN_SOURCE_GROUP:
+       case PHP_MCAST_LEAVE_SOURCE_GROUP:
 #endif
                if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
                        return FAILURE;
@@ -316,13 +316,13 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
        int                             retval;
 
        switch (optname) {
-       case MCAST_JOIN_GROUP:
-       case MCAST_LEAVE_GROUP:
+       case PHP_MCAST_JOIN_GROUP:
+       case PHP_MCAST_LEAVE_GROUP:
 #ifdef HAS_MCAST_EXT
-       case MCAST_BLOCK_SOURCE:
-       case MCAST_UNBLOCK_SOURCE:
-       case MCAST_JOIN_SOURCE_GROUP:
-       case MCAST_LEAVE_SOURCE_GROUP:
+       case PHP_MCAST_BLOCK_SOURCE:
+       case PHP_MCAST_UNBLOCK_SOURCE:
+       case PHP_MCAST_JOIN_SOURCE_GROUP:
+       case PHP_MCAST_LEAVE_SOURCE_GROUP:
 #endif
                if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
                        return FAILURE;
index 1ad4673feb7196a41dafa808417691737df56706..3614306bbb2195c36b8fd295736f51be894b087a 100644 (file)
 /* $Id$ */
 
 #if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__)
-#define RFC3678_API 1
+# define RFC3678_API 1
 /* has block/unblock and source membership, in this case for both IPv4 and IPv6 */
-#define HAS_MCAST_EXT 1
+# define HAS_MCAST_EXT 1
 #elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__)
 /* has block/unblock and source membership, but only for IPv4 */
-#define HAS_MCAST_EXT 1
+# define HAS_MCAST_EXT 1
+#endif
+
+#ifndef RFC3678_API
+# define PHP_MCAST_JOIN_GROUP                  IP_ADD_MEMBERSHIP
+# define PHP_MCAST_LEAVE_GROUP                 IP_DROP_MEMBERSHIP
+# ifdef HAS_MCAST_EXT
+#  define PHP_MCAST_BLOCK_SOURCE               IP_BLOCK_SOURCE
+#  define PHP_MCAST_UNBLOCK_SOURCE             IP_UNBLOCK_SOURCE
+#  define PHP_MCAST_JOIN_SOURCE_GROUP  IP_ADD_SOURCE_MEMBERSHIP
+#  define PHP_MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
+# endif
+#else
+# define PHP_MCAST_JOIN_GROUP                  MCAST_JOIN_GROUP
+# define PHP_MCAST_LEAVE_GROUP                 MCAST_LEAVE_GROUP
+# define PHP_MCAST_BLOCK_SOURCE                        MCAST_BLOCK_SOURCE
+# define PHP_MCAST_UNBLOCK_SOURCE              MCAST_UNBLOCK_SOURCE
+# define PHP_MCAST_JOIN_SOURCE_GROUP   MCAST_JOIN_SOURCE_GROUP
+# define PHP_MCAST_LEAVE_SOURCE_GROUP  MCAST_LEAVE_SOURCE_GROUP
 #endif
 
 int php_do_setsockopt_ip_mcast(php_socket *php_sock,
index 5636cd3cdc9d17169859cffd50b92a21bcfed43a..7f5d49e76c3f6c66d18d795996bfc6b720751401 100644 (file)
@@ -688,24 +688,13 @@ PHP_MINIT_FUNCTION(sockets)
        REGISTER_LONG_CONSTANT("PHP_NORMAL_READ", PHP_NORMAL_READ, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PHP_BINARY_READ", PHP_BINARY_READ, CONST_CS | CONST_PERSISTENT);
 
-#ifndef RFC3678_API
-#define MCAST_JOIN_GROUP                       IP_ADD_MEMBERSHIP
-#define MCAST_LEAVE_GROUP                      IP_DROP_MEMBERSHIP
+       REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP",                      PHP_MCAST_JOIN_GROUP,                   CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP",                     PHP_MCAST_LEAVE_GROUP,                  CONST_CS | CONST_PERSISTENT);
 #ifdef HAS_MCAST_EXT
-#define MCAST_BLOCK_SOURCE                     IP_BLOCK_SOURCE
-#define MCAST_UNBLOCK_SOURCE           IP_UNBLOCK_SOURCE
-#define MCAST_JOIN_SOURCE_GROUP                IP_ADD_SOURCE_MEMBERSHIP
-#define MCAST_LEAVE_SOURCE_GROUP       IP_DROP_SOURCE_MEMBERSHIP
-#endif
-#endif
-
-       REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP",                      MCAST_JOIN_GROUP,                       CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP",                     MCAST_LEAVE_GROUP,                      CONST_CS | CONST_PERSISTENT);
-#ifdef HAS_MCAST_EXT
-       REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE",            MCAST_BLOCK_SOURCE,                     CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE",          MCAST_UNBLOCK_SOURCE,           CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP",       MCAST_JOIN_SOURCE_GROUP,        CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP",      MCAST_LEAVE_SOURCE_GROUP,       CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE",            PHP_MCAST_BLOCK_SOURCE,                 CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE",          PHP_MCAST_UNBLOCK_SOURCE,               CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP",       PHP_MCAST_JOIN_SOURCE_GROUP,    CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP",      PHP_MCAST_LEAVE_SOURCE_GROUP,   CONST_CS | CONST_PERSISTENT);
 #endif
 
        REGISTER_LONG_CONSTANT("IP_MULTICAST_IF",                       IP_MULTICAST_IF,                CONST_CS | CONST_PERSISTENT);