SOCKOPT_RCVTIMEO and SOCKOPT_SENDTIMEO should be allowed for zmq 2.2 #60

Closed
mcvella opened this Issue Jun 27, 2012 · 3 comments

Comments

Projects
None yet
2 participants

mcvella commented Jun 27, 2012

ZeroMQ 2.2 supports the options SOCKOPT_RCVTIMEO and SOCKOPT_SENDTIMEO. zmq_sockopt.c should be updated to reflect this.

see patch below:

--- zmq_sockopt.c.old 2012-06-27 17:09:51.873279868 -0400
+++ zmq_sockopt.c 2012-06-27 17:12:12.845281036 -0400
@@ -678,6 +678,683 @@

#endif

+#if ZMQ_VERSION_MAJOR == 2 & ZMQ_VERSION_MINOR == 2
+
+/* {{{ proto mixed ZMQSocket::getSockOpt()

  • Get a socket option
    +*/
    +PHP_METHOD(zmqsocket, getsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • size_t value_len;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_HWM value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SWAP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL_MSEC value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_MCAST_LOOP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_EVENTS:
    
  •   {
    
  •       uint32_t value;
    
  •       value_len = sizeof(uint32_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_FD:
    
  •   {
    
  •       php_stream *stm = php_zmq_create_zmq_fd(getThis() TSRMLS_CC);
    
  •       if (stm) {
    
  •           php_stream_to_zval(stm, return_value);
    
  •           return;
    
  •       }
    
  •       RETURN_FALSE;
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       unsigned char value[PHP_ZMQ_IDENTITY_LEN];
    
  •       value_len = PHP_ZMQ_IDENTITY_LEN;
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_STRINGL((char *) value, value_len, 1);
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  • }
    +}
    +/* {{{ proto ZMQSocket ZMQSocket::setSockOpt(integer $SOCKOPT, mixed $value)
  • Set a socket option
    +*/
    +PHP_METHOD(zmqsocket, setsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • zval *pz_value;
  • int status;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &pz_value) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SWAP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL_MSEC option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_MCAST_LOOP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  • }
  • ZMQ_RETURN_THIS;
    +}

    +void php_zmq_register_sockopt_constants (zend_class_entry *php_zmq_sc_entry TSRMLS_DC)
    +{
    +#define PHP_ZMQ_REGISTER_SOCKOPT(const_name, value) \

  • zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SWAP", ZMQ_SWAP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL_MSEC", ZMQ_RECOVERY_IVL_MSEC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MCAST_LOOP", ZMQ_MCAST_LOOP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO);

  • +#undef PHP_ZMQ_REGISTER_SOCKOPT
    +}

  • +#endif
    +

    if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0

    /* {{{ proto mixed ZMQSocket::getSockOpt()

mcvella commented Jun 28, 2012

Sorry, bad diff, the following works:

--- ../zmq-1.0.3/zmq_sockopt.c 2012-02-17 05:35:58.000000000 -0500
+++ zmq_sockopt.c 2012-06-27 22:15:01.683036465 -0400
@@ -32,7 +32,7 @@
#include "php_zmq.h"
#include "php_zmq_private.h"

-#if ZMQ_VERSION_MAJOR == 2
+#if ZMQ_VERSION_MAJOR == 2 && ZMQ_VERSION_MINOR < 2

/* {{{ proto mixed ZMQSocket::getSockOpt()
Get a socket option
@@ -675,6 +675,683 @@

#undef PHP_ZMQ_REGISTER_SOCKOPT
}

+#endif
+
+
+#if ZMQ_VERSION_MAJOR == 2 && ZMQ_VERSION_MINOR == 2
+
+/* {{{ proto mixed ZMQSocket::getSockOpt()

  • Get a socket option
    +*/
    +PHP_METHOD(zmqsocket, getsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • size_t value_len;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_HWM value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SWAP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL_MSEC value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_MCAST_LOOP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_EVENTS:
    
  •   {
    
  •       uint32_t value;
    
  •       value_len = sizeof(uint32_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_FD:
    
  •   {
    
  •       php_stream *stm = php_zmq_create_zmq_fd(getThis() TSRMLS_CC);
    
  •       if (stm) {
    
  •           php_stream_to_zval(stm, return_value);
    
  •           return;
    
  •       }
    
  •       RETURN_FALSE;
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       unsigned char value[PHP_ZMQ_IDENTITY_LEN];
    
  •       value_len = PHP_ZMQ_IDENTITY_LEN;
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_STRINGL((char *) value, value_len, 1);
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  • }
    +}
    +/* {{{ proto ZMQSocket ZMQSocket::setSockOpt(integer $SOCKOPT, mixed $value)
  • Set a socket option
    +*/
    +PHP_METHOD(zmqsocket, setsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • zval *pz_value;
  • int status;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &pz_value) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SWAP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL_MSEC option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_MCAST_LOOP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  • }
  • ZMQ_RETURN_THIS;
    +}

    +void php_zmq_register_sockopt_constants (zend_class_entry *php_zmq_sc_entry TSRMLS_DC)
    +{
    +#define PHP_ZMQ_REGISTER_SOCKOPT(const_name, value) \

  • zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SWAP", ZMQ_SWAP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL_MSEC", ZMQ_RECOVERY_IVL_MSEC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MCAST_LOOP", ZMQ_MCAST_LOOP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO);

  • +#undef PHP_ZMQ_REGISTER_SOCKOPT
    +}

    #endif

mcvella commented Jun 28, 2012

Sorry, I have been quite careless. The patch, one last time (this one tested):

--- ../zmq-1.0.3/zmq_sockopt.c 2012-02-17 05:35:58.000000000 -0500
+++ zmq_sockopt.c 2012-06-27 22:35:26.083046597 -0400
@@ -32,7 +32,7 @@
#include "php_zmq.h"
#include "php_zmq_private.h"

-#if ZMQ_VERSION_MAJOR == 2
+#if ZMQ_VERSION_MAJOR == 2 && ZMQ_VERSION_MINOR < 2

/* {{{ proto mixed ZMQSocket::getSockOpt()
Get a socket option
@@ -675,6 +675,715 @@

#undef PHP_ZMQ_REGISTER_SOCKOPT
}

+#endif
+
+
+#if ZMQ_VERSION_MAJOR == 2 && ZMQ_VERSION_MINOR >= 2
+
+/* {{{ proto mixed ZMQSocket::getSockOpt()

  • Get a socket option
    +*/
    +PHP_METHOD(zmqsocket, getsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • size_t value_len;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_HWM value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SWAP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL_MSEC value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_MCAST_LOOP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_EVENTS:
    
  •   {
    
  •       uint32_t value;
    
  •       value_len = sizeof(uint32_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_FD:
    
  •   {
    
  •       php_stream *stm = php_zmq_create_zmq_fd(getThis() TSRMLS_CC);
    
  •       if (stm) {
    
  •           php_stream_to_zval(stm, return_value);
    
  •           return;
    
  •       }
    
  •       RETURN_FALSE;
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       unsigned char value[PHP_ZMQ_IDENTITY_LEN];
    
  •       value_len = PHP_ZMQ_IDENTITY_LEN;
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_STRINGL((char *) value, value_len, 1);
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  • }
    +}
    +/* {{{ proto ZMQSocket ZMQSocket::setSockOpt(integer $SOCKOPT, mixed $value)
  • Set a socket option
    +*/
    +PHP_METHOD(zmqsocket, setsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • zval *pz_value;
  • int status;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &pz_value) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SWAP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL_MSEC option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_MCAST_LOOP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDTIMEO:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SNDTIMEO option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVTIMEO:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RCVTIMEO option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  • }
  • ZMQ_RETURN_THIS;
    +}

    +void php_zmq_register_sockopt_constants (zend_class_entry *php_zmq_sc_entry TSRMLS_DC)
    +{
    +#define PHP_ZMQ_REGISTER_SOCKOPT(const_name, value) \

  • zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SWAP", ZMQ_SWAP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL_MSEC", ZMQ_RECOVERY_IVL_MSEC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MCAST_LOOP", ZMQ_MCAST_LOOP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO);

  • +#undef PHP_ZMQ_REGISTER_SOCKOPT
    +}

    #endif

Owner

mkoppanen commented Jul 9, 2012

Can you do a pull request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment