package.xml0000644000076500000240000002615212653534763010135 0ustar zmq pecl.php.net ZeroMQ messaging ZeroMQ is a software library that lets you quickly design and implement a fast message-based applications. Mikko Koppanen mkoppanen mkoppanen@php.net yes 2016-02-01 1.1.3 1.1.0 beta beta BSD License - Introduces PHP7 support. PHP5 compilation should work but receives no updates. - Added new methods: * ZMQSocket::monitor (and related ZMQSocket::recvEvent) * ZMQ::z85Encode/Decode * ZMQ::has - Socket options are now restricted to their valid socket types - Usage pthreads extension is now better supported and tested 5.3.0 1.4.0 zmq zmq-1.1.3/php5/zmq.c0000644000076500000240000023730612653534763011121 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #include "php_zmq_pollset.h" /* PHP 5.4 */ #if PHP_VERSION_ID < 50399 # define object_properties_init(zo, class_type) { \ zval *tmp; \ zend_hash_copy((*zo).properties, \ &class_type->default_properties, \ (copy_ctor_func_t) zval_add_ref, \ (void *) &tmp, \ sizeof(zval *)); \ } #endif ZEND_DECLARE_MODULE_GLOBALS(php_zmq) zend_class_entry *php_zmq_sc_entry; zend_class_entry *php_zmq_context_sc_entry; zend_class_entry *php_zmq_socket_sc_entry; zend_class_entry *php_zmq_poll_sc_entry; zend_class_entry *php_zmq_device_sc_entry; #ifdef HAVE_CZMQ_2 zend_class_entry *php_zmq_cert_sc_entry; zend_class_entry *php_zmq_auth_sc_entry; #endif zend_class_entry *php_zmq_exception_sc_entry; zend_class_entry *php_zmq_context_exception_sc_entry; zend_class_entry *php_zmq_socket_exception_sc_entry; zend_class_entry *php_zmq_poll_exception_sc_entry; zend_class_entry *php_zmq_device_exception_sc_entry; #ifdef HAVE_CZMQ_2 zend_class_entry *php_zmq_cert_exception_sc_entry; zend_class_entry *php_zmq_auth_exception_sc_entry; #endif static zend_object_handlers zmq_object_handlers; static zend_object_handlers zmq_socket_object_handlers; static zend_object_handlers zmq_context_object_handlers; static zend_object_handlers zmq_poll_object_handlers; static zend_object_handlers zmq_device_object_handlers; #ifdef PHP_ZMQ_PTHREADS #include static void *php_zmq_global_context = NULL; static pthread_mutex_t php_zmq_global_context_mutex = PTHREAD_MUTEX_INITIALIZER; #endif #ifdef HAVE_CZMQ_2 static zend_object_handlers zmq_cert_object_handlers; static zend_object_handlers zmq_auth_object_handlers; #endif #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) static const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 }; #endif zend_class_entry *php_zmq_context_exception_sc_entry_get () { return php_zmq_context_exception_sc_entry; } zend_class_entry *php_zmq_socket_exception_sc_entry_get () { return php_zmq_socket_exception_sc_entry; } zend_class_entry *php_zmq_device_exception_sc_entry_get () { return php_zmq_device_exception_sc_entry; } /* list entries */ static int le_zmq_socket, le_zmq_context; /** {{{ static void php_zmq_get_lib_version(char buffer[PHP_ZMQ_VERSION_LEN]) */ static void php_zmq_get_lib_version(char buffer[PHP_ZMQ_VERSION_LEN]) { int major = 0, minor = 0, patch = 0; zmq_version(&major, &minor, &patch); (void) snprintf(buffer, PHP_ZMQ_VERSION_LEN - 1, "%d.%d.%d", major, minor, patch); } /* }}} */ /** {{{ static int php_zmq_socket_list_entry(void) */ static int php_zmq_socket_list_entry(void) { return le_zmq_socket; } /* }}} */ /* {{{ static int php_zmq_context_list_entry(void) */ static int php_zmq_context_list_entry(void) { return le_zmq_context; } /* }}} */ /* {{{ static void php_zmq_context_destroy(php_zmq_context *context) Destroy the context */ static void php_zmq_context_destroy(php_zmq_context *context) { if (!context->is_global) { if(context->pid == getpid()) (void) zmq_term(context->z_ctx); } pefree(context, context->is_persistent); } /* }}} */ /* {{{ static void php_zmq_socket_destroy(php_zmq_socket *zmq_sock) Destroy the socket (note: does not touch context) */ static void php_zmq_socket_destroy(php_zmq_socket *zmq_sock) { zend_hash_destroy(&(zmq_sock->connect)); zend_hash_destroy(&(zmq_sock->bind)); if (zmq_sock->pid == getpid ()) (void) zmq_close(zmq_sock->z_socket); pefree(zmq_sock, zmq_sock->is_persistent); } /* }}} */ /* --- START ZMQContext --- */ /* {{{ static php_zmq_context *php_zmq_context_new(long io_threads, zend_bool is_persistent, zend_bool is_global TSRMLS_DC) Create a new zmq context */ static php_zmq_context *php_zmq_context_new(long io_threads, zend_bool is_persistent, zend_bool is_global TSRMLS_DC) { php_zmq_context *context; context = pecalloc(1, sizeof(php_zmq_context), is_persistent); #ifdef PHP_ZMQ_PTHREADS if (is_global) { /* Guard the context creation */ pthread_mutex_lock (&php_zmq_global_context_mutex); { if (!php_zmq_global_context) { php_zmq_global_context = zmq_init(io_threads); } context->z_ctx = php_zmq_global_context; } pthread_mutex_unlock (&php_zmq_global_context_mutex); } #else if (0) {} #endif else { context->z_ctx = zmq_init(io_threads); } if (!context->z_ctx) { pefree(context, is_persistent); return NULL; } context->io_threads = io_threads; context->is_persistent = is_persistent; context->is_global = is_global; context->pid = getpid(); return context; } /* }}} */ /* {{{ static php_zmq_context *php_zmq_context_get(long io_threads, zend_bool is_persistent TSRMLS_DC) */ static php_zmq_context *php_zmq_context_get(long io_threads, zend_bool is_persistent TSRMLS_DC) { php_zmq_context *context; char plist_key[48]; int plist_key_len; zend_rsrc_list_entry le, *le_p = NULL; if (is_persistent) { plist_key_len = snprintf(plist_key, 48, "zmq_context:[%d]", io_threads); plist_key_len += 1; if (zend_hash_find(&EG(persistent_list), plist_key, plist_key_len, (void *)&le_p) == SUCCESS) { if (le_p->type == php_zmq_context_list_entry()) { return (php_zmq_context *) le_p->ptr; } } } context = php_zmq_context_new(io_threads, is_persistent, 0 TSRMLS_CC); if (!context) { return NULL; } if (is_persistent) { le.type = php_zmq_context_list_entry(); le.ptr = context; if (zend_hash_update(&EG(persistent_list), (char *)plist_key, plist_key_len, (void *)&le, sizeof(le), NULL) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not register persistent entry for the context"); } } return context; } /* }}} */ /* {{{ proto ZMQ ZMQ::__construct() Private constructor */ PHP_METHOD(zmq, __construct) {} /* }}} */ /* {{{ proto integer ZMQ::clock() A monotonic clock */ PHP_METHOD(zmq, clock) { if (zend_parse_parameters_none() == FAILURE) { return; } RETURN_LONG((long) php_zmq_clock (ZMQ_G (clock_ctx))); } /* }}} */ /* {{{ proto ZMQContext ZMQContext::__construct(integer $io_threads[, boolean $is_persistent = true]) Build a new ZMQContext object */ PHP_METHOD(zmqcontext, __construct) { php_zmq_context_object *intern; long io_threads = 1; zend_bool is_persistent = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &io_threads, &is_persistent) == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; intern->context = php_zmq_context_get(io_threads, is_persistent TSRMLS_CC); if (!intern->context) { zend_throw_exception_ex(php_zmq_context_exception_sc_entry, errno TSRMLS_CC, "Error creating context: %s", zmq_strerror(errno)); return; } return; } /* }}} */ #ifdef PHP_ZMQ_PTHREADS /* {{{ proto ZMQContext ZMQContext::acquire() Acquires a handle to the request global context */ PHP_METHOD(zmqcontext, acquire) { php_zmq_context *context; php_zmq_context_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } // Create a request global context context = php_zmq_context_new(1, 1, 1 TSRMLS_CC); object_init_ex(return_value, php_zmq_context_sc_entry); intern = (php_zmq_context_object *)zend_object_store_get_object(return_value TSRMLS_CC); intern->context = context; return; } /* }}} */ #endif #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 /* {{{ proto ZMQContext ZMQContext::setOpt(int option, int value) Set a context option */ PHP_METHOD(zmqcontext, setOpt) { php_zmq_context_object *intern; long option, value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &option, &value) == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; switch (option) { case ZMQ_MAX_SOCKETS: { if (zmq_ctx_set(intern->context->z_ctx, option, value) != 0) { zend_throw_exception_ex(php_zmq_context_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set the option ZMQ::CTXOPT_MAX_SOCKETS value: %s", zmq_strerror(errno)); return; } } break; default: { zend_throw_exception(php_zmq_context_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } } return; } /* }}} */ /* {{{ proto ZMQContext ZMQContext::getOpt(int option) Set a context option */ PHP_METHOD(zmqcontext, getOpt) { php_zmq_context_object *intern; long option; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &option) == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; switch (option) { case ZMQ_MAX_SOCKETS: { int value = zmq_ctx_get(intern->context->z_ctx, option); RETURN_LONG(value); } break; default: { zend_throw_exception(php_zmq_context_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } } return; } /* }}} */ #endif /* {{{ static php_zmq_socket *php_zmq_socket_new(php_zmq_context *context, int type, zend_bool is_persistent TSRMLS_DC) Create a new zmq socket */ static php_zmq_socket *php_zmq_socket_new(php_zmq_context *context, int type, zend_bool is_persistent TSRMLS_DC) { php_zmq_socket *zmq_sock; zmq_sock = pecalloc(1, sizeof(php_zmq_socket), is_persistent); zmq_sock->z_socket = zmq_socket(context->z_ctx, type); zmq_sock->pid = getpid(); if (!zmq_sock->z_socket) { pefree(zmq_sock, is_persistent); return NULL; } zmq_sock->is_persistent = is_persistent; zend_hash_init(&(zmq_sock->connect), 0, NULL, NULL, is_persistent); zend_hash_init(&(zmq_sock->bind), 0, NULL, NULL, is_persistent); return zmq_sock; } /* }}} */ static char *php_zmq_socket_plist_key(int type, const char *persistent_id, int *plist_key_len) { char *plist_key = NULL; *plist_key_len = spprintf(&plist_key, 0, "zmq_socket:[%d]-[%s]", type, persistent_id); return plist_key; } static void php_zmq_socket_store(php_zmq_socket *zmq_sock_p, int type, const char *persistent_id TSRMLS_DC) { zend_rsrc_list_entry le; char *plist_key = NULL; int plist_key_len = 0; plist_key = php_zmq_socket_plist_key(type, persistent_id, &plist_key_len); le.type = php_zmq_socket_list_entry(); le.ptr = zmq_sock_p; if (zend_hash_update(&EG(persistent_list), plist_key, plist_key_len + 1, (void *)&le, sizeof(le), NULL) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not register persistent entry for the socket"); } efree(plist_key); } /* {{{ static php_zmq_socket *php_zmq_socket_get(php_zmq_context *context, int type, const char *persistent_id, zend_bool *is_new TSRMLS_DC) Tries to get context from plist and allocates a new context if context does not exist */ static php_zmq_socket *php_zmq_socket_get(php_zmq_context *context, int type, const char *persistent_id, zend_bool *is_new TSRMLS_DC) { php_zmq_socket *zmq_sock_p; zend_bool is_persistent; is_persistent = (context->is_persistent && persistent_id) ? 1 : 0; *is_new = 0; if (is_persistent) { char *plist_key = NULL; int plist_key_len = 0; zend_rsrc_list_entry *le = NULL; plist_key = php_zmq_socket_plist_key(type, persistent_id, &plist_key_len); if (zend_hash_find(&EG(persistent_list), plist_key, plist_key_len + 1, (void *)&le) == SUCCESS) { if (le->type == php_zmq_socket_list_entry()) { efree(plist_key); return (php_zmq_socket *) le->ptr; } } efree(plist_key); } zmq_sock_p = php_zmq_socket_new(context, type, is_persistent TSRMLS_CC); if (!zmq_sock_p) { return NULL; } *is_new = 1; return zmq_sock_p; } /* }}} */ char *php_zmq_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) { char *buffer = NULL; if (fci->object_ptr) { spprintf (&buffer, 0, "%s::%s", Z_OBJCE_P (fci->object_ptr)->name, fci_cache->function_handler->common.function_name); } else { if (Z_TYPE_P (fci->function_name) == IS_OBJECT) { spprintf (&buffer, 0, "%s", Z_OBJCE_P (fci->function_name)->name); } else { spprintf (&buffer, 0, "%s", Z_STRVAL_P (fci->function_name)); } } return buffer; } static zend_bool php_zmq_connect_callback(zval *socket, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, const char *persistent_id TSRMLS_DC) { zval *retval_ptr, *pid_z; zval **params[2]; zend_bool retval = 1; ALLOC_INIT_ZVAL(pid_z); if (persistent_id) { ZVAL_STRING(pid_z, persistent_id, 1); } else { ZVAL_NULL(pid_z); } /* Call the cb */ params[0] = &socket; params[1] = &pid_z; fci->params = params; fci->param_count = 2; fci->retval_ptr_ptr = &retval_ptr; fci->no_separation = 1; if (zend_call_function(fci, fci_cache TSRMLS_CC) == FAILURE) { if (!EG(exception)) { char *buf = php_zmq_printable_func (fci, fci_cache TSRMLS_CC); zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, 0 TSRMLS_CC, "Failed to invoke 'on_new_socket' callback %s()", buf); efree (buf); } retval = 0; } zval_ptr_dtor(&pid_z); if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } if (EG(exception)) { retval = 0; } return retval; } /* {{{ proto ZMQContext ZMQContext::getSocket(integer $type[, string $persistent_id = null[, callback $on_new_socket = null]]) Build a new ZMQContext object */ PHP_METHOD(zmqcontext, getsocket) { php_zmq_socket *socket; php_zmq_socket_object *interns; php_zmq_context_object *intern; long type; char *persistent_id = NULL; int rc, persistent_id_len; zend_bool is_new; zend_fcall_info fci; zend_fcall_info_cache fci_cache; PHP_ZMQ_ERROR_HANDLING_INIT() PHP_ZMQ_ERROR_HANDLING_THROW() fci.size = 0; rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s!f!", &type, &persistent_id, &persistent_id_len, &fci, &fci_cache); PHP_ZMQ_ERROR_HANDLING_RESTORE() if (rc == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; socket = php_zmq_socket_get(intern->context, type, persistent_id, &is_new TSRMLS_CC); if (!socket) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Error creating socket: %s", zmq_strerror(errno)); return; } object_init_ex(return_value, php_zmq_socket_sc_entry); interns = (php_zmq_socket_object *)zend_object_store_get_object(return_value TSRMLS_CC); interns->socket = socket; /* Need to add refcount if context is not persistent */ if (!intern->context->is_persistent) { zend_objects_store_add_ref(getThis() TSRMLS_CC); interns->context_obj = getThis(); Z_ADDREF_P(interns->context_obj); } if (is_new) { if(fci.size) { if (!php_zmq_connect_callback(return_value, &fci, &fci_cache, persistent_id TSRMLS_CC)) { php_zmq_socket_destroy(socket); interns->socket = NULL; zval_dtor(return_value); return; } } if (socket->is_persistent) { php_zmq_socket_store(socket, type, persistent_id TSRMLS_CC); } } if (socket->is_persistent) { interns->persistent_id = estrdup(persistent_id); } return; } /* }}} */ /* {{{ proto ZMQContext ZMQContext::isPersistent() Whether the context is persistent */ PHP_METHOD(zmqcontext, ispersistent) { php_zmq_context_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; RETURN_BOOL(intern->context->is_persistent); } /* }}} */ /* {{{ proto ZMQContext ZMQContext::__clone() Clones the instance of the ZMQContext class */ PHP_METHOD(zmqcontext, __clone) { } /* }}} */ /* --- END ZMQContext --- */ /* --- START ZMQSocket --- */ /* {{{ proto ZMQSocket ZMQSocket::__construct(ZMQContext $context, integer $type[, string $persistent_id = null[, callback $on_new_socket = null]]) Build a new ZMQSocket object */ PHP_METHOD(zmqsocket, __construct) { php_zmq_socket *socket; php_zmq_socket_object *intern; php_zmq_context_object *internc; long type; char *persistent_id = NULL; int rc, persistent_id_len; zval *obj; zend_bool is_new; zend_fcall_info fci; zend_fcall_info_cache fci_cache; PHP_ZMQ_ERROR_HANDLING_INIT() PHP_ZMQ_ERROR_HANDLING_THROW() fci.size = 0; rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol|s!f!", &obj, php_zmq_context_sc_entry, &type, &persistent_id, &persistent_id_len, &fci, &fci_cache); PHP_ZMQ_ERROR_HANDLING_RESTORE() if (rc == FAILURE) { return; } internc = (php_zmq_context_object *) zend_object_store_get_object(obj TSRMLS_CC); socket = php_zmq_socket_get(internc->context, type, persistent_id, &is_new TSRMLS_CC); if (!socket) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Error creating socket: %s", zmq_strerror(errno)); return; } intern = PHP_ZMQ_SOCKET_OBJECT; intern->socket = socket; /* Need to add refcount if context is not persistent */ if (!internc->context->is_persistent) { intern->context_obj = obj; zend_objects_store_add_ref(intern->context_obj TSRMLS_CC); Z_ADDREF_P(intern->context_obj); } if (is_new) { if (fci.size) { if (!php_zmq_connect_callback(getThis(), &fci, &fci_cache, persistent_id TSRMLS_CC)) { php_zmq_socket_destroy(socket); intern->socket = NULL; return; } } if (socket->is_persistent) { php_zmq_socket_store(socket, type, persistent_id TSRMLS_CC); } } if (socket->is_persistent) { intern->persistent_id = estrdup(persistent_id); } return; } /* }}} */ /* {{{ static zend_bool php_zmq_send(php_zmq_socket_object *intern, char *message_param, int message_param_len, long flags TSRMLS_DC) */ static zend_bool php_zmq_send(php_zmq_socket_object *intern, char *message_param, int message_param_len, long flags TSRMLS_DC) { int rc, errno_; zmq_msg_t message; if (zmq_msg_init_size(&message, message_param_len) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to initialize message structure: %s", zmq_strerror(errno)); return 0; } memcpy(zmq_msg_data(&message), message_param, message_param_len); rc = zmq_sendmsg(intern->socket->z_socket, &message, flags); errno_ = errno; zmq_msg_close(&message); if (rc == -1) { if (errno_ == EAGAIN) { return 0; } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno_ TSRMLS_CC, "Failed to send message: %s", zmq_strerror(errno_)); return 0; } return 1; } /* }}} */ static void php_zmq_sendmsg_impl(INTERNAL_FUNCTION_PARAMETERS) { php_zmq_socket_object *intern; char *message_param; int message_param_len; long flags = 0; zend_bool ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &message_param, &message_param_len, &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; ret = php_zmq_send(intern, message_param, message_param_len, flags TSRMLS_CC); if (ret) { ZMQ_RETURN_THIS; } else { RETURN_FALSE; } } /* {{{ proto ZMQSocket ZMQSocket::send(string $message[, integer $flags = 0]) Send a message. Return true if message was sent and false on EAGAIN */ PHP_METHOD(zmqsocket, send) { php_zmq_sendmsg_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) static int php_zmq_send_cb(zval **ppzval, int num_args, va_list args, zend_hash_key *hash_key) { TSRMLS_FETCH(); #else static int php_zmq_send_cb(zval **ppzval TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { #endif zval tmpcopy; php_zmq_socket_object *intern; int flags, *rc, *to_send; intern = va_arg(args, php_zmq_socket_object *); flags = va_arg(args, int); to_send = va_arg(args, int *); rc = va_arg(args, int *); if (--(*to_send)) { flags = flags | ZMQ_SNDMORE; } else { flags = flags & ~ZMQ_SNDMORE; } tmpcopy = **ppzval; zval_copy_ctor(&tmpcopy); INIT_PZVAL(&tmpcopy); if (Z_TYPE(tmpcopy) != IS_STRING) { convert_to_string(&tmpcopy); } *rc = php_zmq_send(intern, Z_STRVAL(tmpcopy), Z_STRLEN(tmpcopy), flags TSRMLS_CC); zval_dtor(&tmpcopy); if (!*rc) { return ZEND_HASH_APPLY_STOP; } return ZEND_HASH_APPLY_KEEP; } /* {{{ proto ZMQSocket ZMQSocket::sendmulti(arrays $messages[, integer $flags = 0]) Send a multipart message. Return true if message was sent and false on EAGAIN */ PHP_METHOD(zmqsocket, sendmulti) { zval *messages; php_zmq_socket_object *intern; int to_send, ret = 0; long flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &messages, &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; to_send = zend_hash_num_elements(Z_ARRVAL_P(messages)); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) zend_hash_apply_with_arguments(Z_ARRVAL_P(messages), (apply_func_args_t) php_zmq_send_cb, 4, intern, flags, &to_send, &ret); #else zend_hash_apply_with_arguments(Z_ARRVAL_P(messages) TSRMLS_CC, (apply_func_args_t) php_zmq_send_cb, 4, intern, flags, &to_send, &ret); #endif if (ret) { ZMQ_RETURN_THIS; } else { RETURN_FALSE; } } /* {{{ static zend_bool php_zmq_recv(php_zmq_socket_object *intern, long flags, zval *return_value TSRMLS_DC) */ static zend_bool php_zmq_recv(php_zmq_socket_object *intern, long flags, zval *return_value TSRMLS_DC) { int rc, errno_; zmq_msg_t message; if (zmq_msg_init(&message) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to initialize message structure: %s", zmq_strerror(errno)); return 0; } rc = zmq_recvmsg(intern->socket->z_socket, &message, flags); errno_ = errno; if (rc == -1) { zmq_msg_close(&message); if (errno == EAGAIN) { return 0; } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno_ TSRMLS_CC, "Failed to receive message: %s", zmq_strerror(errno_)); return 0; } ZVAL_STRINGL(return_value, zmq_msg_data(&message), zmq_msg_size(&message), 1); zmq_msg_close(&message); return 1; } /* }}} */ static void php_zmq_recvmsg_impl(INTERNAL_FUNCTION_PARAMETERS) { php_zmq_socket_object *intern; zend_bool retval; long flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; retval = php_zmq_recv(intern, flags, return_value TSRMLS_CC); if (retval == 0) { RETURN_FALSE; } return; } /* {{{ proto string ZMQ::recv([integer $flags = 0]) Receive a message */ PHP_METHOD(zmqsocket, recv) { php_zmq_recvmsg_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ /* {{{ proto array ZMQ::recvmulti([integer $flags = 0]) Receive an array of message parts */ PHP_METHOD(zmqsocket, recvmulti) { php_zmq_socket_object *intern; size_t value_len; long flags = 0; zend_bool retval; zval *msg; #if ZMQ_VERSION_MAJOR < 3 int64_t value; #else int value; #endif if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; array_init(return_value); value_len = sizeof (value); do { MAKE_STD_ZVAL(msg); retval = php_zmq_recv(intern, flags, msg TSRMLS_CC); if (retval == 0) { FREE_ZVAL(msg); zval_dtor(return_value); RETURN_FALSE; } add_next_index_zval(return_value, msg); zmq_getsockopt(intern->socket->z_socket, ZMQ_RCVMORE, &value, &value_len); } while (value > 0); return; } /* }}} */ /** {{{ string ZMQ::getPersistentId() Returns the persistent id of the object */ PHP_METHOD(zmqsocket, getpersistentid) { php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (intern->socket->is_persistent && intern->persistent_id) { RETURN_STRING(intern->persistent_id, 1); } RETURN_NULL(); } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::bind(string $dsn[, boolean $force = false]) Bind the socket to an endpoint */ PHP_METHOD(zmqsocket, bind) { php_zmq_socket_object *intern; char *dsn; int dsn_len; zend_bool force = 0; void *dummy = (void *)1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &dsn, &dsn_len, &force) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; /* already connected ? */ if (!force && zend_hash_exists(&(intern->socket->bind), dsn, dsn_len + 1)) { ZMQ_RETURN_THIS; } if (zmq_bind(intern->socket->z_socket, dsn) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to bind the ZMQ: %s", zmq_strerror(errno)); return; } zend_hash_add(&(intern->socket->bind), dsn, dsn_len + 1, (void *)&dummy, sizeof(void *), NULL); ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::connect(string $dsn[, boolean $force = false]) Connect the socket to an endpoint */ PHP_METHOD(zmqsocket, connect) { php_zmq_socket_object *intern; char *dsn; int dsn_len; zend_bool force = 0; void *dummy = (void *)1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &dsn, &dsn_len, &force) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; /* already connected ? */ if (!force && zend_hash_exists(&(intern->socket->connect), dsn, dsn_len + 1)) { ZMQ_RETURN_THIS; } if (zmq_connect(intern->socket->z_socket, dsn) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to connect the ZMQ: %s", zmq_strerror(errno)); return; } (void) zend_hash_add(&(intern->socket->connect), dsn, dsn_len + 1, (void *)&dummy, sizeof(void *), NULL); ZMQ_RETURN_THIS; } /* }}} */ #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 /* {{{ proto ZMQSocket ZMQSocket::unbind(string $dsn) Unbind the socket from an endpoint */ PHP_METHOD(zmqsocket, unbind) { php_zmq_socket_object *intern; char *dsn; int dsn_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dsn, &dsn_len) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (zmq_unbind(intern->socket->z_socket, dsn) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to unbind the ZMQ socket: %s", zmq_strerror(errno)); return; } zend_hash_del(&(intern->socket->bind), dsn, dsn_len + 1); ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::disconnect(string $dsn) Disconnect the socket from an endpoint */ PHP_METHOD(zmqsocket, disconnect) { php_zmq_socket_object *intern; char *dsn; int dsn_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dsn, &dsn_len) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (zmq_disconnect(intern->socket->z_socket, dsn) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno TSRMLS_CC, "Failed to disconnect the ZMQ socket: %s", zmq_strerror(errno)); return; } zend_hash_del(&(intern->socket->connect), dsn, dsn_len + 1); ZMQ_RETURN_THIS; } /* }}} */ #endif #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) static int php_zmq_get_keys(zval **ppzval, int num_args, va_list args, zend_hash_key *hash_key) { TSRMLS_FETCH(); #else static int php_zmq_get_keys(zval **ppzval TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { #endif zval *retval; if (num_args != 1) { /* Incorrect args ? */ return ZEND_HASH_APPLY_KEEP; } retval = va_arg(args, zval *); if (hash_key->nKeyLength == 0) { /* Should not happen */ return ZEND_HASH_APPLY_REMOVE; } add_next_index_stringl(retval, hash_key->arKey, hash_key->nKeyLength - 1, 1); return ZEND_HASH_APPLY_KEEP; } /* }}} */ /* {{{ proto array ZMQ::getEndpoints() Returns endpoints where this socket is connected/bound to. Contains two keys ('bind', 'connect') */ PHP_METHOD(zmqsocket, getendpoints) { php_zmq_socket_object *intern; zval *connect, *bind; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; array_init(return_value); MAKE_STD_ZVAL(connect); MAKE_STD_ZVAL(bind); array_init(connect); array_init(bind); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) zend_hash_apply_with_arguments(&(intern->socket->connect), (apply_func_args_t) php_zmq_get_keys, 1, connect); zend_hash_apply_with_arguments(&(intern->socket->bind), (apply_func_args_t) php_zmq_get_keys, 1, bind); #else zend_hash_apply_with_arguments(&(intern->socket->connect) TSRMLS_CC, (apply_func_args_t) php_zmq_get_keys, 1, connect); zend_hash_apply_with_arguments(&(intern->socket->bind) TSRMLS_CC, (apply_func_args_t) php_zmq_get_keys, 1, bind); #endif add_assoc_zval(return_value, "connect", connect); add_assoc_zval(return_value, "bind", bind); return; } /* }}} */ /* {{{ proto integer ZMQSocket::getSocketType() Returns the socket type */ PHP_METHOD(zmqsocket, getsockettype) { int type; size_t type_siz; php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; type_siz = sizeof (int); if (zmq_getsockopt(intern->socket->z_socket, ZMQ_TYPE, &type, &type_siz) != -1) { RETURN_LONG(type); } RETURN_LONG(-1); } /* }}} */ /* {{{ proto boolean ZMQSocket::isPersistent() Whether the socket is persistent */ PHP_METHOD(zmqsocket, ispersistent) { php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; RETURN_BOOL(intern->socket->is_persistent); } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::__clone() Clones the instance of the ZMQSocket class */ PHP_METHOD(zmqsocket, __clone) { } /* }}} */ /* -- END ZMQSocket--- */ /* -- START ZMQPoll --- */ /* {{{ proto integer ZMQPoll::add(ZMQSocket $object, integer $events) Add a ZMQSocket object into the pollset */ PHP_METHOD(zmqpoll, add) { php_zmq_poll_object *intern; zval *object; long events; int pos, key_len = 35; char key[35]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &object, &events) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; switch (Z_TYPE_P(object)) { case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(object), php_zmq_socket_sc_entry TSRMLS_CC)) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "The first argument must be an instance of ZMQSocket or a resource", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } break; case IS_RESOURCE: /* noop */ break; default: zend_throw_exception(php_zmq_poll_exception_sc_entry, "The first argument must be an instance of ZMQSocket or a resource", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; break; } pos = php_zmq_pollset_add(&(intern->set), object, events TSRMLS_CC); if (pos < 0) { const char *message = NULL; switch (pos) { case PHP_ZMQ_POLLSET_ERR_NO_STREAM: message = "The supplied resource is not a valid stream resource"; break; case PHP_ZMQ_POLLSET_ERR_CANNOT_CAST: message = "The supplied resource is not castable"; break; case PHP_ZMQ_POLLSET_ERR_CAST_FAILED: message = "Failed to cast the supplied stream resource"; break; case PHP_ZMQ_POLLSET_ERR_NO_INIT: message = "The ZMQSocket object has not been initialized properly"; break; case PHP_ZMQ_POLLSET_ERR_NO_POLL: message = "The ZMQSocket object has not been initialized with polling"; break; default: message = "Unknown error"; break; } zend_throw_exception(php_zmq_poll_exception_sc_entry, message, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } if (!php_zmq_pollset_get_key(&(intern->set), pos, key, &key_len TSRMLS_CC)) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "Failed to get the item key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } RETURN_STRINGL(key, key_len, 1); } /* }}} */ /* {{{ proto boolean ZMQPoll::remove(mixed $item) Remove item from poll set */ PHP_METHOD(zmqpoll, remove) { php_zmq_poll_object *intern; zval *item; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; if (intern->set.num_items == 0) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "No sockets assigned to the ZMQPoll", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } switch (Z_TYPE_P(item)) { case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(item), php_zmq_socket_sc_entry TSRMLS_CC)) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "The object must be an instanceof ZMQSocket", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } /* break intentionally missing */ case IS_RESOURCE: RETVAL_BOOL(php_zmq_pollset_delete(&(intern->set), item TSRMLS_CC)); break; default: convert_to_string(item); RETVAL_BOOL(php_zmq_pollset_delete_by_key(&(intern->set), Z_STRVAL_P(item), Z_STRLEN_P(item) TSRMLS_CC)); break; } return; } /* }}} */ /* {{{ proto integer ZMQPoll::poll(array &$readable, array &$writable[, integer $timeout = -1]) Poll the sockets */ PHP_METHOD(zmqpoll, poll) { php_zmq_poll_object *intern; zval *r_array, *w_array; long timeout = -1; int rc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!|l", &r_array, &w_array, &timeout) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; if (intern->set.num_items == 0) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "No sockets assigned to the ZMQPoll", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } rc = php_zmq_pollset_poll(&(intern->set), timeout * PHP_ZMQ_TIMEOUT, r_array, w_array, intern->set.errors); if (rc == -1) { zend_throw_exception_ex(php_zmq_poll_exception_sc_entry, errno TSRMLS_CC, "Poll failed: %s", zmq_strerror(errno)); return; } RETURN_LONG(rc); } /* }}} */ /* {{{ proto integer ZMQPoll::count() Returns the number of items in the set */ PHP_METHOD(zmqpoll, count) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; RETURN_LONG(intern->set.num_items); } /* }}} */ /* {{{ proto ZMQPoll ZMQPoll::clear() Clear the pollset */ PHP_METHOD(zmqpoll, clear) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; php_zmq_pollset_delete_all(&(intern->set) TSRMLS_CC); ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto array ZMQPoll::getLastErrors() Returns last errors */ PHP_METHOD(zmqpoll, getlasterrors) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; Z_ADDREF_P(intern->set.errors); RETVAL_ZVAL(intern->set.errors, 1, 0); return; } /* }}} */ /* {{{ proto ZMQPoll ZMQPoll::__clone() Clones the instance of the ZMQPoll class */ PHP_METHOD(zmqpoll, __clone) { } /* }}} */ /* -- END ZMQPoll */ /* {{{ proto void ZMQDevice::__construct(ZMQSocket frontend, ZMQSocket backend) Construct a device */ PHP_METHOD(zmqdevice, __construct) { php_zmq_device_object *intern; zval *f, *b, *c = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO|O!", &f, php_zmq_socket_sc_entry, &b, php_zmq_socket_sc_entry, &c, php_zmq_socket_sc_entry) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; intern->front = f; intern->back = b; if (c) { intern->capture = c; zend_objects_store_add_ref(c TSRMLS_CC); Z_ADDREF_P(c); } else intern->capture = NULL; zend_objects_store_add_ref(f TSRMLS_CC); Z_ADDREF_P(f); zend_objects_store_add_ref(b TSRMLS_CC); Z_ADDREF_P(b); } /* }}} */ /* {{{ proto void ZMQDevice::run() Start a device */ PHP_METHOD(zmqdevice, run) { php_zmq_device_object *intern; zend_bool rc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; rc = php_zmq_device (intern TSRMLS_CC); if (!rc && !EG (exception)) { zend_throw_exception_ex(php_zmq_device_exception_sc_entry, errno TSRMLS_CC, "Failed to start the device: %s", zmq_strerror (errno)); return; } return; } /* }}} */ static void s_clear_device_callback (php_zmq_device_cb_t *cb) { if (cb->initialized) { zval_ptr_dtor(&cb->fci.function_name); if (cb->user_data) { zval_ptr_dtor(&cb->user_data); } if (cb->fci.object_ptr != NULL) { zval_ptr_dtor(&cb->fci.object_ptr); } memset (cb, 0, sizeof (php_zmq_device_cb_t)); cb->initialized = 0; } } /* {{{ proto void ZMQDevice::setIdleTimeout (int $milliseconds) Set the idle timeout value */ PHP_METHOD(zmqdevice, setidletimeout) { php_zmq_device_object *intern; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &timeout) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; intern->idle_cb.timeout = timeout; ZMQ_RETURN_THIS; } /* }}} */ PHP_METHOD(zmqdevice, getidletimeout) { php_zmq_device_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; RETURN_LONG(intern->idle_cb.timeout); } PHP_METHOD(zmqdevice, settimertimeout) { php_zmq_device_object *intern; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &timeout) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; intern->timer_cb.timeout = timeout; ZMQ_RETURN_THIS; } PHP_METHOD(zmqdevice, gettimertimeout) { php_zmq_device_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; RETURN_LONG(intern->timer_cb.timeout); } static void s_init_device_callback (php_zmq_device_cb_t *cb, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, long timeout, zval *user_data TSRMLS_DC) { if (user_data) { cb->user_data = user_data; Z_ADDREF_P(user_data); } else { MAKE_STD_ZVAL (user_data); ZVAL_NULL(user_data); Z_ADDREF_P(user_data); cb->user_data = user_data; } memcpy (&cb->fci, fci, sizeof (*fci)); memcpy (&cb->fci_cache, fci_cache, sizeof (*fci_cache)); Z_ADDREF_P (fci->function_name); if (fci->object_ptr) { Z_ADDREF_P (fci->object_ptr); } cb->initialized = 1; cb->scheduled_at = php_zmq_clock (ZMQ_G (clock_ctx)) + timeout; cb->timeout = timeout; } /* {{{ proto void ZMQDevice::setIdleCallback (callable $function, integer timeout [, mixed $userdata]) Set the idle timeout value */ PHP_METHOD(zmqdevice, setidlecallback) { php_zmq_device_object *intern; zval *user_data = NULL; zend_fcall_info fci; zend_fcall_info_cache fci_cache; long timeout = 0; if (ZEND_NUM_ARGS() == 2) { php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The signature for setIdleCallback has changed, please update your code"); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|z!", &fci, &fci_cache, &user_data) == FAILURE) { return; } } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "fl|z!", &fci, &fci_cache, &timeout, &user_data) == FAILURE) { return; } } intern = PHP_ZMQ_DEVICE_OBJECT; /* Hack for backwards compatible behaviour */ if (!timeout) { if (intern->idle_cb.timeout) { timeout = intern->idle_cb.timeout; } } s_clear_device_callback (&intern->idle_cb); if (fci.size > 0) { s_init_device_callback (&intern->idle_cb, &fci, &fci_cache, timeout, user_data TSRMLS_CC); } ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto void ZMQDevice::setTimerCallback (callable $function, integer timeout [, mixed $userdata]) Set the timer function */ PHP_METHOD(zmqdevice, settimercallback) { php_zmq_device_object *intern; zval *user_data = NULL; zend_fcall_info fci; zend_fcall_info_cache fci_cache; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "fl|z!", &fci, &fci_cache, &timeout, &user_data) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; s_clear_device_callback (&intern->timer_cb); if (fci.size > 0) { s_init_device_callback (&intern->timer_cb, &fci, &fci_cache, timeout, user_data TSRMLS_CC); } ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto ZMQDevice ZMQDevice::__clone() Clones the instance of the ZMQDevice class */ PHP_METHOD(zmqdevice, __clone) { } /* }}} */ /* -- END ZMQPoll */ #ifdef HAVE_CZMQ_2 /* --- START ZMQCert --- */ static void php_zmq_cert_free_storage(void *object TSRMLS_DC) { php_zmq_cert_object *zmq_cert = (php_zmq_cert_object *) object; zcert_destroy(&zmq_cert->zcert); zend_object_std_dtor(&zmq_cert->zend_object TSRMLS_CC); efree(zmq_cert); } static zend_object_value php_zmq_cert_new(zend_class_entry *class_type TSRMLS_DC) { zend_object_value result; php_zmq_cert_object *zmq_cert; zmq_cert = (php_zmq_cert_object *) emalloc(sizeof(php_zmq_cert_object)); memset(&zmq_cert->zend_object, 0, sizeof(zend_object)); /* zcert is initialised in ZMQCert#__construct. */ zmq_cert->zcert = NULL; zend_object_std_init(&zmq_cert->zend_object, class_type TSRMLS_CC); object_properties_init(&zmq_cert->zend_object, class_type); result.handle = zend_objects_store_put( zmq_cert, NULL, (zend_objects_free_object_storage_t) php_zmq_cert_free_storage, NULL TSRMLS_CC ); result.handlers = &zmq_cert_object_handlers; return result; } PHP_METHOD(zmqcert, __construct) { char *filename; int filename_length; zend_error_handling error_handling; int parse_parameters_result; php_zmq_cert_object *intern; filename = NULL; zend_replace_error_handling(EH_THROW, php_zmq_cert_exception_sc_entry, &error_handling TSRMLS_CC); parse_parameters_result = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &filename, &filename_length); zend_restore_error_handling(&error_handling TSRMLS_CC); if (parse_parameters_result != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); if (filename == NULL) { intern->zcert = zcert_new(); if (intern->zcert == NULL) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to create the underlying zcert object. Is libsodium installed?", filename); } return; } intern->zcert = zcert_load(filename); if (intern->zcert == NULL) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to load the certificate from %s", filename); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert___construct_args, 0, 0, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO(); PHP_METHOD(zmqcert, getPublicKey) { php_zmq_cert_object *intern; byte *public_key; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); public_key = zcert_public_key(intern->zcert); RETURN_STRINGL((char *) public_key, 32, 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getPublicKey_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getSecretKey) { php_zmq_cert_object *intern; byte *secret_key; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); secret_key = zcert_secret_key(intern->zcert); RETURN_STRINGL((char *) secret_key, 32, 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getSecretKey_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getPublicTxt) { php_zmq_cert_object *intern; char *public_txt; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); public_txt = zcert_public_txt(intern->zcert); RETURN_STRING(public_txt, 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getPublicTxt_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getSecretTxt) { php_zmq_cert_object *intern; char *secret_txt; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); secret_txt = zcert_secret_txt(intern->zcert); RETURN_STRING(secret_txt, 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getSecretTxt_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, setMeta) { php_zmq_cert_object *intern; char *name; int name_length; char *format; int format_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_length, &format, &format_length) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zcert_set_meta(intern->zcert, name, format); return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_setMeta_args, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getMeta) { char *name; int name_length; php_zmq_cert_object *intern; char *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_length) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); result = zcert_meta(intern->zcert, name); if (result == NULL) { RETURN_NULL(); } RETURN_STRING(result, 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getMeta_args, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getMetaKeys) { php_zmq_cert_object *intern; zlist_t *meta_keys; char *meta_key; int i; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); meta_keys = zcert_meta_keys(intern->zcert); meta_key = (char *) zlist_first(meta_keys); array_init(return_value); i = 0; while (meta_key) { add_index_string(return_value, i, meta_key, 1); ++i; meta_key = zlist_next(meta_keys); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getMetaKeys_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, save) { php_zmq_cert_object *intern; char *filename; int filename_length; int zcert_save_result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zcert_save_result = zcert_save(intern->zcert, filename); if (zcert_save_result == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to save the certificate to %s", filename); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_save_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, savePublic) { char *filename; int filename_length; php_zmq_cert_object *intern; int zcert_save_public_result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zcert_save_public_result = zcert_save_public(intern->zcert, filename); if (zcert_save_public_result == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to save the public certificate to %s", filename); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_savePublic_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, saveSecret) { char *filename; int filename_length; php_zmq_cert_object *intern; int zcert_save_secret_result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zcert_save_secret_result = zcert_save_secret(intern->zcert, filename); if (zcert_save_secret_result == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to save the secret certificate to %s", filename); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_saveSecret_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, apply) { php_zmq_cert_object *intern; zval *object; php_zmq_socket_object *socket_object; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &object, php_zmq_socket_sc_entry) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); socket_object = (php_zmq_socket_object *) zend_object_store_get_object(object TSRMLS_CC); zcert_apply(intern->zcert, socket_object->socket->z_socket); return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_apply_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQSocket, ZMQSocket, 0) ZEND_END_ARG_INFO() static zend_object_value php_zmq_cert_clone(zval *object TSRMLS_DC) { php_zmq_cert_object *intern; zend_object_value result; php_zmq_cert_object *that; intern = (php_zmq_cert_object *) zend_object_store_get_object(object TSRMLS_CC); result = php_zmq_cert_new(php_zmq_cert_sc_entry TSRMLS_CC); that = (php_zmq_cert_object *) zend_object_store_get_object_by_handle(result.handle TSRMLS_CC); that->zcert = zcert_dup(intern->zcert); return result; } PHP_METHOD(zmqcert, equals) { php_zmq_cert_object *intern; zval *object; php_zmq_cert_object *that; bool result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &object, php_zmq_cert_sc_entry) != SUCCESS) { return; } intern = (php_zmq_cert_object *) zend_object_store_get_object(getThis() TSRMLS_CC); that = (php_zmq_cert_object *) zend_object_store_get_object(object TSRMLS_CC); result = zcert_eq(intern->zcert, that->zcert); RETURN_BOOL(result); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_equals_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQCert, ZMQCert, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_cert_class_methods[] = { PHP_ME(zmqcert, __construct, zmqcert___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqcert, getPublicKey, zmqcert_getPublicKey_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getSecretKey, zmqcert_getSecretKey_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getPublicTxt, zmqcert_getPublicTxt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getSecretTxt, zmqcert_getSecretTxt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, setMeta, zmqcert_setMeta_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getMeta, zmqcert_getMeta_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getMetaKeys, zmqcert_getMetaKeys_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, save, zmqcert_save_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, savePublic, zmqcert_savePublic_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, saveSecret, zmqcert_saveSecret_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, apply, zmqcert_apply_args, ZEND_ACC_PUBLIC) /* PHP_ME(zmqcert, __clone, zmqcert___clone_args, ZEND_ACC_PUBLIC) */ PHP_ME(zmqcert, equals, zmqcert_equals_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* --- END ZMQCert --- */ /* --- START ZMQAuth --- */ static void php_zmq_auth_free_storage(void *object TSRMLS_DC) { php_zmq_auth_object *zmq_auth = (php_zmq_auth_object *) object; zauth_destroy(&zmq_auth->zauth); zctx_destroy(&zmq_auth->shadow_context); zend_object_std_dtor(&zmq_auth->zend_object TSRMLS_CC); efree(zmq_auth); } static zend_object_value php_zmq_auth_new(zend_class_entry *class_type TSRMLS_DC) { zend_object_value result; php_zmq_auth_object *zmq_auth; zmq_auth = (php_zmq_auth_object *) emalloc(sizeof(php_zmq_auth_object)); memset(&zmq_auth->zend_object, 0, sizeof(zend_object)); /* zauth is initialised in ZMQAuth#__construct. */ zmq_auth->zauth = NULL; zend_object_std_init(&zmq_auth->zend_object, class_type TSRMLS_CC); object_properties_init(&zmq_auth->zend_object, class_type); result.handle = zend_objects_store_put( zmq_auth, NULL, (zend_objects_free_object_storage_t) php_zmq_auth_free_storage, NULL TSRMLS_CC ); result.handlers = &zmq_auth_object_handlers; return result; } PHP_METHOD(zmqauth, __construct) { php_zmq_auth_object *intern; zval *object; zend_error_handling error_handling; int parse_parameters_result; php_zmq_context_object *context_object; zend_replace_error_handling(EH_THROW, php_zmq_cert_exception_sc_entry, &error_handling TSRMLS_CC); parse_parameters_result = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &object, php_zmq_context_sc_entry); zend_restore_error_handling(&error_handling TSRMLS_CC); if (parse_parameters_result != SUCCESS) { return; } intern = (php_zmq_auth_object *) zend_object_store_get_object(getThis() TSRMLS_CC); context_object = (php_zmq_context_object *) zend_object_store_get_object(object TSRMLS_CC); // NOTE (phuedx, 2014-05-14): A zauth object needs a context so that it // can take over authentication for all incoming connections in that // context. Creating a shadow context from the specified context allows // us to continue working with CZMQ. intern->shadow_context = zctx_shadow_zmq_ctx(context_object->context->z_ctx); if (intern->shadow_context == NULL) { zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to create the underlying shadow context object."); return; } intern->zauth = zauth_new(intern->shadow_context); if (intern->zauth == NULL) { zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Failed to create the underlying zauth object."); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqauth___construct_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQContext, ZMQContext, 0) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, allow) { char *address; int address_length; php_zmq_auth_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &address, &address_length) != SUCCESS) { return; } intern = (php_zmq_auth_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zauth_allow(intern->zauth, address); RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_allow_args, 0, 0, 1) ZEND_ARG_INFO(0, address) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, deny) { char *address; int address_length; php_zmq_auth_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &address, &address_length) != SUCCESS) { return; } intern = (php_zmq_auth_object *) zend_object_store_get_object(getThis() TSRMLS_CC); zauth_deny(intern->zauth, address); RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_deny_args, 0, 0, 1) ZEND_ARG_INFO(0, address) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, configure) { php_zmq_auth_object *intern; int parse_parameters_result; long type; char *domain; int domain_length; char *filename; int filename_length; intern = (php_zmq_auth_object *) zend_object_store_get_object(getThis() TSRMLS_CC); parse_parameters_result = zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "lss", &type, &domain, &domain_length, &filename, &filename_length ); if (parse_parameters_result != SUCCESS) { return; } switch (type) { case PHP_ZMQ_AUTH_TYPE_PLAIN: zauth_configure_plain(intern->zauth, domain, filename); break; case PHP_ZMQ_AUTH_TYPE_CURVE: zauth_configure_curve(intern->zauth, domain, filename); break; // TODO (phuedx, 2014-05-16): CZMQ now supports GSSAPI (see // zauth_configure_gssapi). default: zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC, "Unknown auth type. Are you using one of the ZMQAuth constants?"); break; } RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_configure_args, 0, 0, 3) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, domain) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO(); static zend_function_entry php_zmq_auth_class_methods[] = { PHP_ME(zmqauth, __construct, zmqauth___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqauth, allow, zmqauth_allow_args, ZEND_ACC_PUBLIC) PHP_ME(zmqauth, deny, zmqauth_deny_args, ZEND_ACC_PUBLIC) PHP_ME(zmqauth, configure, zmqauth_configure_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* --- END ZMQAuth --- */ #endif // HAVE_CZMQ_2 ZEND_BEGIN_ARG_INFO_EX(zmq_construct_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_clock_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_class_methods[] = { PHP_ME(zmq, __construct, zmq_construct_args, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(zmq, clock, zmq_clock_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_context_construct_args, 0, 0, 0) ZEND_ARG_INFO(0, io_threads) ZEND_ARG_INFO(0, persistent) ZEND_END_ARG_INFO() #ifdef PHP_ZMQ_PTHREADS ZEND_BEGIN_ARG_INFO_EX(zmq_context_acquire_args, 0, 0, 0) ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_INFO_EX(zmq_context_getsocket_args, 0, 0, 2) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, on_new_socket) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_ispersistent_args, 0, 0, 2) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 ZEND_BEGIN_ARG_INFO_EX(zmq_context_setopt_args, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_getopt_args, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_END_ARG_INFO() #endif static zend_function_entry php_zmq_context_class_methods[] = { PHP_ME(zmqcontext, __construct, zmq_context_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) #ifdef PHP_ZMQ_PTHREADS PHP_ME(zmqcontext, acquire, zmq_context_acquire_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif PHP_ME(zmqcontext, getsocket, zmq_context_getsocket_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, ispersistent, zmq_context_ispersistent_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, __clone, zmq_context_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 PHP_ME(zmqcontext, setOpt, zmq_context_setopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, getOpt, zmq_context_getopt_args, ZEND_ACC_PUBLIC) #endif {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_socket_construct_args, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, ZMQContext, ZMQContext, 0) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, persistent_id) ZEND_ARG_INFO(0, on_new_socket) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_bind_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_connect_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 ZEND_BEGIN_ARG_INFO_EX(zmq_socket_unbind_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_disconnect_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_INFO_EX(zmq_socket_setsockopt_args, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getendpoints_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getsockettype_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_send_args, 0, 0, 1) ZEND_ARG_INFO(0, message) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_recv_args, 0, 0, 0) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getpersistentid_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getsockopt_args, 0, 0, 1) ZEND_ARG_INFO(0, key) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_ispersistent_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_socket_class_methods[] = { PHP_ME(zmqsocket, __construct, zmq_socket_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqsocket, send, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, recv, zmq_socket_recv_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, sendmulti, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, recvmulti, zmq_socket_recv_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, bind, zmq_socket_bind_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, connect, zmq_socket_connect_args, ZEND_ACC_PUBLIC) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 PHP_ME(zmqsocket, unbind, zmq_socket_unbind_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, disconnect, zmq_socket_disconnect_args, ZEND_ACC_PUBLIC) #endif PHP_ME(zmqsocket, setsockopt, zmq_socket_setsockopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getendpoints, zmq_socket_getendpoints_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getsockettype, zmq_socket_getsockettype_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, ispersistent, zmq_socket_ispersistent_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getpersistentid, zmq_socket_getpersistentid_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getsockopt, zmq_socket_getsockopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, __clone, zmq_socket_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) PHP_MALIAS(zmqsocket, sendmsg, send, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_MALIAS(zmqsocket, recvmsg, recv, zmq_socket_recv_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_poll_add_args, 0, 0, 2) ZEND_ARG_INFO(0, entry) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_poll_args, 0, 0, 2) ZEND_ARG_INFO(1, readable) ZEND_ARG_INFO(1, writable) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_getlasterrors_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_remove_args, 0, 0, 2) ZEND_ARG_INFO(0, remove) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_count_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_clear_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_poll_class_methods[] = { PHP_ME(zmqpoll, add, zmq_poll_add_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, poll, zmq_poll_poll_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, getlasterrors, zmq_poll_getlasterrors_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, remove, zmq_poll_remove_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, count, zmq_poll_count_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, clear, zmq_poll_clear_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, __clone, zmq_poll_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_device_construct_args, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, frontend, ZMQSocket, 0) ZEND_ARG_OBJ_INFO(0, backend, ZMQSocket, 0) ZEND_ARG_OBJ_INFO(0, capture, ZMQSocket, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_run_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_setidlecallback_args, 0, 0, 2) ZEND_ARG_INFO(0, idle_callback) ZEND_ARG_INFO(0, timeout) ZEND_ARG_INFO(0, user_data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_settimercallback_args, 0, 0, 2) ZEND_ARG_INFO(0, idle_callback) ZEND_ARG_INFO(0, timeout) ZEND_ARG_INFO(0, user_data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_setidletimeout_args, 0, 0, 1) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_settimertimeout_args, 0, 0, 1) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_getidletimeout_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_gettimertimeout_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_device_class_methods[] = { PHP_ME(zmqdevice, __construct, zmq_device_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqdevice, run, zmq_device_run_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, setidlecallback, zmq_device_setidlecallback_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, setidletimeout, zmq_device_setidletimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, getidletimeout, zmq_device_getidletimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, settimercallback, zmq_device_settimercallback_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, settimertimeout, zmq_device_settimertimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, gettimertimeout, zmq_device_gettimertimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, __clone, zmq_device_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; zend_function_entry zmq_functions[] = { {NULL, NULL, NULL} }; static void php_zmq_context_object_free_storage(void *object TSRMLS_DC) { php_zmq_context_object *intern = (php_zmq_context_object *)object; if (!intern) { return; } if (intern->context) { if (!intern->context->is_persistent) { php_zmq_context_destroy(intern->context); } } zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); } static void php_zmq_socket_object_free_storage(void *object TSRMLS_DC) { php_zmq_socket_object *intern = (php_zmq_socket_object *)object; if (!intern) { return; } if (intern->socket) { if (intern->socket->is_persistent && intern->persistent_id) { efree(intern->persistent_id); } if (!intern->socket->is_persistent) { php_zmq_socket_destroy(intern->socket); } } if (intern->context_obj) { zend_objects_store_del_ref(intern->context_obj TSRMLS_CC); Z_DELREF_P(intern->context_obj); } zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); } static void php_zmq_poll_object_free_storage(void *object TSRMLS_DC) { php_zmq_poll_object *intern = (php_zmq_poll_object *)object; if (!intern) { return; } php_zmq_pollset_deinit(&(intern->set) TSRMLS_CC); zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); } static void php_zmq_device_object_free_storage(void *object TSRMLS_DC) { php_zmq_device_object *intern = (php_zmq_device_object *)object; if (!intern) { return; } s_clear_device_callback (&intern->idle_cb); s_clear_device_callback (&intern->timer_cb); if (intern->front) { zend_objects_store_del_ref(intern->front TSRMLS_CC); zval_ptr_dtor (&intern->front); } if (intern->back) { zend_objects_store_del_ref(intern->back TSRMLS_CC); zval_ptr_dtor (&intern->back); } if (intern->capture) { zend_objects_store_del_ref(intern->capture TSRMLS_CC); zval_ptr_dtor (&intern->capture); } zend_object_std_dtor(&intern->zo TSRMLS_CC); efree(intern); } static zend_object_value php_zmq_context_object_new_ex(zend_class_entry *class_type, php_zmq_context_object **ptr TSRMLS_DC) { zend_object_value retval; php_zmq_context_object *intern; /* Allocate memory for it */ intern = (php_zmq_context_object *) emalloc(sizeof(php_zmq_context_object)); memset(&intern->zo, 0, sizeof(zend_object)); /* Context is initialized in the constructor */ intern->context = NULL; if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_zmq_context_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) &zmq_context_object_handlers; return retval; } static zend_object_value php_zmq_socket_object_new_ex(zend_class_entry *class_type, php_zmq_socket_object **ptr TSRMLS_DC) { zend_object_value retval; php_zmq_socket_object *intern; /* Allocate memory for it */ intern = (php_zmq_socket_object *) emalloc(sizeof(php_zmq_socket_object)); memset(&intern->zo, 0, sizeof(zend_object)); intern->socket = NULL; intern->persistent_id = NULL; intern->context_obj = NULL; if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_zmq_socket_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) &zmq_socket_object_handlers; return retval; } static zend_object_value php_zmq_poll_object_new_ex(zend_class_entry *class_type, php_zmq_poll_object **ptr TSRMLS_DC) { zend_object_value retval; php_zmq_poll_object *intern; /* Allocate memory for it */ intern = (php_zmq_poll_object *) emalloc(sizeof(php_zmq_poll_object)); memset(&intern->zo, 0, sizeof(zend_object)); php_zmq_pollset_init(&(intern->set)); if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_zmq_poll_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) &zmq_poll_object_handlers; return retval; } static zend_object_value php_zmq_device_object_new_ex(zend_class_entry *class_type, php_zmq_device_object **ptr TSRMLS_DC) { zend_object_value retval; php_zmq_device_object *intern; /* Allocate memory for it */ intern = (php_zmq_device_object *) emalloc(sizeof(php_zmq_device_object)); memset(&intern->zo, 0, sizeof(zend_object)); memset (&intern->idle_cb, 0, sizeof (php_zmq_device_cb_t)); memset (&intern->timer_cb, 0, sizeof (php_zmq_device_cb_t)); intern->front = NULL; intern->back = NULL; intern->capture = NULL; if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_zmq_device_object_free_storage, NULL TSRMLS_CC); retval.handlers = (zend_object_handlers *) &zmq_device_object_handlers; return retval; } static zend_object_value php_zmq_context_object_new(zend_class_entry *class_type TSRMLS_DC) { return php_zmq_context_object_new_ex(class_type, NULL TSRMLS_CC); } static zend_object_value php_zmq_socket_object_new(zend_class_entry *class_type TSRMLS_DC) { return php_zmq_socket_object_new_ex(class_type, NULL TSRMLS_CC); } static zend_object_value php_zmq_poll_object_new(zend_class_entry *class_type TSRMLS_DC) { return php_zmq_poll_object_new_ex(class_type, NULL TSRMLS_CC); } static zend_object_value php_zmq_device_object_new(zend_class_entry *class_type TSRMLS_DC) { return php_zmq_device_object_new_ex(class_type, NULL TSRMLS_CC); } ZEND_RSRC_DTOR_FUNC(php_zmq_context_dtor) { if (rsrc->ptr) { php_zmq_context *ctx = (php_zmq_context *)rsrc->ptr; php_zmq_context_destroy(ctx); rsrc->ptr = NULL; } } ZEND_RSRC_DTOR_FUNC(php_zmq_socket_dtor) { if (rsrc->ptr) { php_zmq_socket *zms = (php_zmq_socket *)rsrc->ptr; php_zmq_socket_destroy(zms); rsrc->ptr = NULL; } } static void php_zmq_init_globals (zend_php_zmq_globals *zmq_globals) { zmq_globals->clock_ctx = NULL; } PHP_MINIT_FUNCTION(zmq) { char version[PHP_ZMQ_VERSION_LEN]; zend_class_entry ce, ce_context, ce_socket, ce_poll, ce_device; zend_class_entry ce_exception, ce_context_exception, ce_socket_exception, ce_poll_exception, ce_device_exception; #ifdef HAVE_CZMQ_2 zend_class_entry ce_cert, ce_cert_exception, ce_auth, ce_auth_exception; #endif le_zmq_context = zend_register_list_destructors_ex(NULL, php_zmq_context_dtor, "ZMQ persistent context", module_number); le_zmq_socket = zend_register_list_destructors_ex(NULL, php_zmq_socket_dtor, "ZMQ persistent socket", module_number); memcpy(&zmq_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_context_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_socket_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_poll_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_device_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); #ifdef HAVE_CZMQ_2 memcpy(&zmq_cert_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_auth_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); #endif INIT_CLASS_ENTRY(ce, "ZMQ", php_zmq_class_methods); ce.create_object = NULL; zmq_object_handlers.clone_obj = NULL; php_zmq_sc_entry = zend_register_internal_class(&ce TSRMLS_CC); INIT_CLASS_ENTRY(ce_context, "ZMQContext", php_zmq_context_class_methods); ce_context.create_object = php_zmq_context_object_new; zmq_context_object_handlers.clone_obj = NULL; php_zmq_context_sc_entry = zend_register_internal_class(&ce_context TSRMLS_CC); INIT_CLASS_ENTRY(ce_socket, "ZMQSocket", php_zmq_socket_class_methods); ce_socket.create_object = php_zmq_socket_object_new; zmq_socket_object_handlers.clone_obj = NULL; php_zmq_socket_sc_entry = zend_register_internal_class(&ce_socket TSRMLS_CC); INIT_CLASS_ENTRY(ce_poll, "ZMQPoll", php_zmq_poll_class_methods); ce_poll.create_object = php_zmq_poll_object_new; zmq_poll_object_handlers.clone_obj = NULL; php_zmq_poll_sc_entry = zend_register_internal_class(&ce_poll TSRMLS_CC); INIT_CLASS_ENTRY(ce_device, "ZMQDevice", php_zmq_device_class_methods); ce_device.create_object = php_zmq_device_object_new; zmq_device_object_handlers.clone_obj = NULL; php_zmq_device_sc_entry = zend_register_internal_class(&ce_device TSRMLS_CC); #ifdef HAVE_CZMQ_2 INIT_CLASS_ENTRY(ce_cert, "ZMQCert", php_zmq_cert_class_methods); ce_cert.create_object = php_zmq_cert_new; zmq_cert_object_handlers.clone_obj = php_zmq_cert_clone; php_zmq_cert_sc_entry = zend_register_internal_class(&ce_cert TSRMLS_CC); INIT_CLASS_ENTRY(ce_auth, "ZMQAuth", php_zmq_auth_class_methods); ce_auth.create_object = php_zmq_auth_new; zmq_auth_object_handlers.clone_obj = NULL; php_zmq_auth_sc_entry = zend_register_internal_class(&ce_auth TSRMLS_CC); #endif INIT_CLASS_ENTRY(ce_exception, "ZMQException", NULL); php_zmq_exception_sc_entry = zend_register_internal_class_ex(&ce_exception, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); php_zmq_exception_sc_entry->ce_flags &= ~ZEND_ACC_FINAL_CLASS; INIT_CLASS_ENTRY(ce_context_exception, "ZMQContextException", NULL); php_zmq_context_exception_sc_entry = zend_register_internal_class_ex(&ce_context_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_context_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; INIT_CLASS_ENTRY(ce_socket_exception, "ZMQSocketException", NULL); php_zmq_socket_exception_sc_entry = zend_register_internal_class_ex(&ce_socket_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_socket_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; INIT_CLASS_ENTRY(ce_poll_exception, "ZMQPollException", NULL); php_zmq_poll_exception_sc_entry = zend_register_internal_class_ex(&ce_poll_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_poll_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; INIT_CLASS_ENTRY(ce_device_exception, "ZMQDeviceException", NULL); php_zmq_device_exception_sc_entry = zend_register_internal_class_ex(&ce_device_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_device_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; #ifdef HAVE_CZMQ_2 INIT_CLASS_ENTRY(ce_cert_exception, "ZMQCertException", NULL); php_zmq_cert_exception_sc_entry = zend_register_internal_class_ex(&ce_cert_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_cert_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; INIT_CLASS_ENTRY(ce_auth_exception, "ZMQAuthException", NULL); php_zmq_auth_exception_sc_entry = zend_register_internal_class_ex(&ce_auth_exception, php_zmq_exception_sc_entry, "ZMQException" TSRMLS_CC); php_zmq_auth_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL_CLASS; #endif ZEND_INIT_MODULE_GLOBALS(php_zmq, php_zmq_init_globals, NULL); ZMQ_G(clock_ctx) = php_zmq_clock_init (); if (!ZMQ_G(clock_ctx)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialise clock"); return FAILURE; } #define PHP_ZMQ_REGISTER_CONST_LONG(const_name, value) \ zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); #define PHP_ZMQ_REGISTER_CONST_STRING(const_name, value) \ zend_declare_class_constant_string (php_zmq_sc_entry, const_name, sizeof(const_name)-1, value TSRMLS_CC); /* Socket constants */ PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PAIR", ZMQ_PAIR); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PUB", ZMQ_PUB); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_SUB", ZMQ_SUB); #if ZMQ_VERSION_MAJOR >= 3 PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XSUB", ZMQ_XSUB); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XPUB", ZMQ_XPUB); #endif PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_REQ", ZMQ_REQ); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_REP", ZMQ_REP); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XREQ", ZMQ_XREQ); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XREP", ZMQ_XREP); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PUSH", ZMQ_PUSH); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PULL", ZMQ_PULL); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_DEALER", ZMQ_DEALER); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_ROUTER", ZMQ_ROUTER); #if ZMQ_VERSION_MAJOR >= 4 PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_STREAM", ZMQ_STREAM); #endif /* 2.0? */ PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_UPSTREAM", ZMQ_PULL); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_DOWNSTREAM", ZMQ_PUSH); #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 PHP_ZMQ_REGISTER_CONST_LONG("MODE_SNDLABEL", ZMQ_SNDLABEL); #endif PHP_ZMQ_REGISTER_CONST_LONG("POLL_IN", ZMQ_POLLIN); PHP_ZMQ_REGISTER_CONST_LONG("POLL_OUT", ZMQ_POLLOUT); PHP_ZMQ_REGISTER_CONST_LONG("MODE_SNDMORE", ZMQ_SNDMORE); PHP_ZMQ_REGISTER_CONST_LONG("MODE_NOBLOCK", ZMQ_DONTWAIT); PHP_ZMQ_REGISTER_CONST_LONG("MODE_DONTWAIT", ZMQ_DONTWAIT); PHP_ZMQ_REGISTER_CONST_LONG("DEVICE_FORWARDER", ZMQ_FORWARDER); PHP_ZMQ_REGISTER_CONST_LONG("DEVICE_QUEUE", ZMQ_QUEUE); PHP_ZMQ_REGISTER_CONST_LONG("DEVICE_STREAMER", ZMQ_STREAMER); PHP_ZMQ_REGISTER_CONST_LONG("ERR_INTERNAL", PHP_ZMQ_INTERNAL_ERROR); PHP_ZMQ_REGISTER_CONST_LONG("ERR_EAGAIN", EAGAIN); PHP_ZMQ_REGISTER_CONST_LONG("ERR_ENOTSUP", ENOTSUP); PHP_ZMQ_REGISTER_CONST_LONG("ERR_EFSM", EFSM); PHP_ZMQ_REGISTER_CONST_LONG("ERR_ETERM", ETERM); php_zmq_get_lib_version(version); PHP_ZMQ_REGISTER_CONST_STRING("LIBZMQ_VER", version); php_zmq_register_sockopt_constants (php_zmq_sc_entry TSRMLS_CC); #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3 PHP_ZMQ_REGISTER_CONST_LONG("CTXOPT_MAX_SOCKETS", ZMQ_MAX_SOCKETS); PHP_ZMQ_REGISTER_CONST_LONG("CTXOPT_MAX_SOCKETS_DEFAULT", ZMQ_MAX_SOCKETS_DFLT); #endif #ifdef HAVE_CZMQ_2 PHP_ZMQ_REGISTER_CONST_STRING("CURVE_ALLOW_ANY", CURVE_ALLOW_ANY); zend_declare_class_constant_long(php_zmq_auth_sc_entry, "AUTH_TYPE_PLAIN", 15, (long)PHP_ZMQ_AUTH_TYPE_PLAIN TSRMLS_CC); zend_declare_class_constant_long(php_zmq_auth_sc_entry, "AUTH_TYPE_CURVE", 15, (long)PHP_ZMQ_AUTH_TYPE_CURVE TSRMLS_CC); #endif #undef PHP_ZMQ_REGISTER_CONST_LONG #undef PHP_ZMQ_REGISTER_CONST_STRING return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(zmq) { #ifdef PHP_ZMQ_PTHREADS if (php_zmq_global_context) { zmq_term (php_zmq_global_context); php_zmq_global_context = NULL; } #endif php_zmq_clock_destroy (&ZMQ_G (clock_ctx)); return SUCCESS; } PHP_MINFO_FUNCTION(zmq) { char version[PHP_ZMQ_VERSION_LEN]; php_zmq_get_lib_version(version); php_info_print_table_start(); php_info_print_table_header(2, "ZMQ extension", "enabled"); php_info_print_table_row(2, "ZMQ extension version", PHP_ZMQ_VERSION); php_info_print_table_row(2, "libzmq version", version); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } zend_module_entry zmq_module_entry = { STANDARD_MODULE_HEADER, PHP_ZMQ_EXTNAME, zmq_functions, /* Functions */ PHP_MINIT(zmq), /* MINIT */ PHP_MSHUTDOWN(zmq), /* MSHUTDOWN */ NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(zmq), /* MINFO */ PHP_ZMQ_VERSION, /* version */ STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_ZMQ ZEND_GET_MODULE(zmq) #endif /* COMPILE_DL_ZMQ */ zmq-1.1.3/php5/zmq_device.c0000644000076500000240000002277512653534763012442 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ /* Based on zeromq 2.1.x devices, which is: Copyright (c) 2007-2011 iMatix Corporation Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file */ #include "php_zmq.h" #include "php_zmq_private.h" ZEND_EXTERN_MODULE_GLOBALS(php_zmq) static zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRMLS_DC) { zend_bool retval = 0; zval **params[1]; zval *retval_ptr = NULL; params [0] = &cb->user_data; cb->fci.params = params; cb->fci.param_count = 1; /* Call the cb */ cb->fci.no_separation = 1; cb->fci.retval_ptr_ptr = &retval_ptr; if (zend_call_function(&(cb->fci), &(cb->fci_cache) TSRMLS_CC) == FAILURE) { if (!EG(exception)) { char *buf = php_zmq_printable_func (&(cb->fci), &(cb->fci_cache) TSRMLS_CC); zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0 TSRMLS_CC, "Failed to invoke callback %s()", buf); efree (buf); } } if (retval_ptr) { convert_to_boolean(retval_ptr); if (Z_BVAL_P(retval_ptr)) { retval = 1; } zval_ptr_dtor(&retval_ptr); } cb->scheduled_at = current_ts + cb->timeout; return retval; } static int s_capture_message (void *socket, zmq_msg_t *msg, int more) { int rc; zmq_msg_t msg_cp; rc = zmq_msg_init (&msg_cp); if (rc == -1) return -1; rc = zmq_msg_copy (&msg_cp, msg); if (rc == -1) { zmq_msg_close (&msg_cp); return -1; } return zmq_sendmsg (socket, &msg_cp, more ? ZMQ_SNDMORE : 0); } static int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC) { int timeout = -1; uint64_t current = php_zmq_clock (ZMQ_G (clock_ctx)); /* Do we have timer? */ if (intern->timer_cb.initialized && intern->timer_cb.timeout) { /* This is when we need to launch timer */ timeout = (int) (intern->timer_cb.scheduled_at - current); /* If we are tiny bit late, make sure it's asap */ if (timeout <= 0) { return 1 * PHP_ZMQ_TIMEOUT; } } /* Do we have idle callback? */ if (intern->idle_cb.initialized && intern->idle_cb.timeout) { /* Do we need to reduce next timing? */ int idle_timeout = (int) (intern->idle_cb.scheduled_at - current); /* Might happen if we get scheduled tiny bit late */ if (idle_timeout <= 0) { return 1 * PHP_ZMQ_TIMEOUT; } if (timeout == -1 || idle_timeout < timeout) timeout = idle_timeout; } if (timeout > 0) timeout *= PHP_ZMQ_TIMEOUT; return timeout; } zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) { int errno_; uint64_t last_message_received; void *capture_sock; php_zmq_socket_object *front, *back; zmq_msg_t msg; #if ZMQ_VERSION_MAJOR >= 3 int more; #else int64_t more; #endif #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 int label; size_t labelsz = sizeof(label); #endif size_t moresz; zmq_pollitem_t items [2]; int rc = zmq_msg_init (&msg); if (rc != 0) { return 0; } front = (php_zmq_socket_object *)zend_object_store_get_object(intern->front TSRMLS_CC); back = (php_zmq_socket_object *)zend_object_store_get_object(intern->back TSRMLS_CC); items [0].socket = front->socket->z_socket; items [0].fd = 0; items [0].events = ZMQ_POLLIN; items [0].revents = 0; items [1].socket = back->socket->z_socket; items [1].fd = 0; items [1].events = ZMQ_POLLIN; items [1].revents = 0; capture_sock = NULL; if (intern->capture) { php_zmq_socket_object *capture = (php_zmq_socket_object *)zend_object_store_get_object(intern->capture TSRMLS_CC); capture_sock = capture->socket->z_socket; } last_message_received = php_zmq_clock (ZMQ_G (clock_ctx)); intern->timer_cb.scheduled_at = last_message_received + intern->timer_cb.timeout; intern->idle_cb.scheduled_at = last_message_received + intern->idle_cb.timeout; while (1) { uint64_t current_ts = 0; /* Calculate poll_timeout based on idle / timer cb */ int timeout = s_calculate_timeout (intern TSRMLS_CC); rc = zmq_poll(&items [0], 2, timeout); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } current_ts = php_zmq_clock (ZMQ_G (clock_ctx)); if (rc > 0) last_message_received = current_ts; /* Do we have a timer callback? */ if (intern->timer_cb.initialized && intern->timer_cb.timeout > 0) { /* Is it timer to call the timer ? */ if (intern->timer_cb.scheduled_at <= current_ts) { if (!s_invoke_device_cb (&intern->timer_cb, current_ts TSRMLS_CC)) { zmq_msg_close (&msg); return 1; } } } /* Do we have a idle callback? */ if (rc == 0 && intern->idle_cb.initialized && intern->idle_cb.timeout > 0) { /* Is it timer to call the idle callback ? */ if ((current_ts - last_message_received) >= intern->idle_cb.timeout && intern->idle_cb.scheduled_at <= current_ts) { if (!s_invoke_device_cb (&intern->idle_cb, current_ts TSRMLS_CC)) { zmq_msg_close (&msg); return 1; } } continue; } if (items [0].revents & ZMQ_POLLIN) { while (1) { rc = zmq_recvmsg(items [0].socket, &msg, 0); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } moresz = sizeof(more); rc = zmq_getsockopt(items [0].socket, ZMQ_RCVMORE, &more, &moresz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 labelsz = sizeof(label); rc = zmq_getsockopt(items [0].socket, ZMQ_RCVLABEL, &label, &labelsz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } rc = zmq_sendmsg (items [1].socket, &msg, label ? ZMQ_SNDLABEL : (more ? ZMQ_SNDMORE : 0)); more = more | label; #else if (capture_sock) { rc = s_capture_message (capture_sock, &msg, more); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } } rc = zmq_sendmsg (items [1].socket, &msg, more ? ZMQ_SNDMORE : 0); #endif if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } if (!more) break; } } if (items [1].revents & ZMQ_POLLIN) { while (1) { rc = zmq_recvmsg(items [1].socket, &msg, 0); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } moresz = sizeof (more); rc = zmq_getsockopt(items [1].socket, ZMQ_RCVMORE, &more, &moresz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); return errno_; } #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 labelsz = sizeof(label); rc = zmq_getsockopt(items [1].socket, ZMQ_RCVLABEL, &label, &labelsz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } rc = zmq_sendmsg (items [0].socket, &msg, label ? ZMQ_SNDLABEL : (more ? ZMQ_SNDMORE : 0)); more = more | label; #else if (capture_sock) { rc = s_capture_message (capture_sock, &msg, more); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } } rc = zmq_sendmsg (items [0].socket, &msg, more ? ZMQ_SNDMORE : 0); #endif if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } if (!more) break; } } } zmq_msg_close (&msg); return 0; } zmq-1.1.3/php5/zmq_fd_stream.c0000644000076500000240000000752312653534763013141 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" static size_t php_zmq_fd_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { return 0; } static size_t php_zmq_fd_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) { return 0; } static int php_zmq_fd_close(php_stream *stream, int close_handle TSRMLS_DC) { zval *obj = (zval *) stream->abstract; zend_objects_store_del_ref(obj TSRMLS_CC); Z_DELREF_P(obj); return EOF; } static int php_zmq_fd_flush(php_stream *stream TSRMLS_DC) { return FAILURE; } static int php_zmq_fd_cast(php_stream *stream, int cast_as, void **ret TSRMLS_DC) { zval *obj = (zval *) stream->abstract; php_zmq_socket_object *intern = (php_zmq_socket_object *) zend_object_store_get_object(obj TSRMLS_CC); switch (cast_as) { case PHP_STREAM_AS_FD_FOR_SELECT: case PHP_STREAM_AS_FD: case PHP_STREAM_AS_SOCKETD: if (ret) { size_t optsiz = sizeof (int); if (zmq_getsockopt(intern->socket->z_socket, ZMQ_FD, (int*) ret, &optsiz) != 0) { return FAILURE; } } return SUCCESS; default: return FAILURE; } } static php_stream_ops php_stream_zmq_fd_ops = { php_zmq_fd_write, php_zmq_fd_read, php_zmq_fd_close, php_zmq_fd_flush, "ZMQ_FD", NULL, /* seek */ php_zmq_fd_cast, /* cast */ NULL, /* stat */ NULL /* set_option */ }; php_stream *php_zmq_create_zmq_fd(zval *obj TSRMLS_DC) { php_stream *stream; stream = php_stream_alloc(&php_stream_zmq_fd_ops, obj, NULL, "r"); if (stream) { zend_objects_store_add_ref(obj TSRMLS_CC); Z_ADDREF_P(obj); return stream; } return NULL; } /* }}} */ zmq-1.1.3/php5/zmq_pollset.c0000644000076500000240000002633412653534763012660 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #include "php_zmq_pollset.h" #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) # include "ext/standard/md5.h" #else # include "ext/spl/php_spl.h" #endif #define PHP_ZMQ_ALLOC_SIZE 5 void php_zmq_pollset_init(php_zmq_pollset *set) { set->num_items = 0; set->num_php_items = 0; set->alloc_size = PHP_ZMQ_ALLOC_SIZE; set->items = ecalloc(PHP_ZMQ_ALLOC_SIZE, sizeof(zmq_pollitem_t)); set->php_items = ecalloc(PHP_ZMQ_ALLOC_SIZE, sizeof(php_zmq_pollitem)); MAKE_STD_ZVAL(set->errors); array_init(set->errors); } void php_zmq_pollset_clear(php_zmq_pollset *set, zend_bool reinit TSRMLS_DC) { if (set->alloc_size > 0) { efree(set->php_items); efree(set->items); } set->items = NULL; set->php_items = NULL; set->alloc_size = 0; if (reinit) { zval_dtor(set->errors); FREE_ZVAL(set->errors); php_zmq_pollset_init(set); } } void php_zmq_pollset_deinit(php_zmq_pollset *set TSRMLS_DC) { int i; for (i = 0; i < set->num_php_items; i++) { if (Z_TYPE_P(set->php_items[i].entry) == IS_OBJECT) { zend_objects_store_del_ref(set->php_items[i].entry TSRMLS_CC); } zval_ptr_dtor(&(set->php_items[i].entry)); } php_zmq_pollset_clear(set, 0 TSRMLS_CC); zval_dtor(set->errors); FREE_ZVAL(set->errors); } void php_zmq_pollset_delete_all(php_zmq_pollset *set TSRMLS_DC) { int i; for (i = 0; i < set->num_php_items; i++) { if (Z_TYPE_P(set->php_items[i].entry) == IS_OBJECT) { zend_objects_store_del_ref(set->php_items[i].entry TSRMLS_CC); } zval_ptr_dtor(&(set->php_items[i].entry)); } php_zmq_pollset_clear(set, 1 TSRMLS_CC); } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) static void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/ { PHP_MD5_CTX context; unsigned char digest[16]; char *hash; int len; len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj)); result[0] = '\0'; PHP_MD5Init(&context); PHP_MD5Update(&context, (unsigned char*) hash, len); PHP_MD5Final(digest, &context); make_digest(result, digest); efree(hash); } /* }}} */ #endif static void php_zmq_create_key(zval *entry, char key[35], int *key_len TSRMLS_DC) { if (Z_TYPE_P(entry) == IS_RESOURCE) { *key_len = snprintf(key, 35, "r:%d", Z_LVAL_P(entry)); } else { char hash[33]; php_spl_object_hash(entry, hash TSRMLS_CC); *key_len = snprintf(key, 35, "o:%s", hash); } } zend_bool php_zmq_pollset_get_key(php_zmq_pollset *set, int pos, char key[35], int *key_len TSRMLS_DC) { if (pos >= set->num_php_items || pos < 0) { return 0; } if (*key_len < set->php_items[pos].key_len + 1) { return 0; } memcpy(key, set->php_items[pos].key, set->php_items[pos].key_len + 1); *key_len = set->php_items[pos].key_len; return 1; } int php_zmq_pollset_add(php_zmq_pollset *pollset, zval *entry, int events TSRMLS_DC) { int i; char key[35]; int key_len; zend_bool resize; assert(pollset->num_php_items == pollset->num_items); if (Z_TYPE_P(entry) != IS_OBJECT && Z_TYPE_P(entry) != IS_RESOURCE) { return PHP_ZMQ_POLLSET_ERR_INVALID_TYPE; } php_zmq_create_key(entry, key, &key_len TSRMLS_CC); if (!key_len || key_len > 34) { return PHP_ZMQ_POLLSET_ERR_KEY_FAIL; } for (i = 0; i < pollset->num_php_items; i++) { if (key_len == pollset->php_items[i].key_len && !memcmp(pollset->php_items[i].key, key, key_len)) { pollset->items[i].events = events; pollset->php_items[i].events = events; return i; } } resize = (pollset->num_items >= pollset->alloc_size); if (Z_TYPE_P(entry) == IS_RESOURCE) { int fd; php_stream *stream; php_stream_from_zval_no_verify(stream, &entry); if (!stream) { return PHP_ZMQ_POLLSET_ERR_NO_STREAM; } if (php_stream_can_cast(stream, (PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL | PHP_STREAM_AS_SOCKETD) & ~REPORT_ERRORS) == FAILURE) { return PHP_ZMQ_POLLSET_ERR_CANNOT_CAST; } if (php_stream_cast(stream, (PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL | PHP_STREAM_AS_SOCKETD) & ~REPORT_ERRORS, (void*)&fd, 0) == FAILURE) { return PHP_ZMQ_POLLSET_ERR_CAST_FAILED; } if (resize) { pollset->items = erealloc(pollset->items, (pollset->alloc_size + PHP_ZMQ_ALLOC_SIZE) * sizeof(zmq_pollitem_t)); } memset(&(pollset->items[pollset->num_items]), 0, sizeof(zmq_pollitem_t)); pollset->items[pollset->num_items].fd = fd; pollset->items[pollset->num_items].events = events; } else { php_zmq_socket_object *item = (php_zmq_socket_object *)zend_object_store_get_object(entry TSRMLS_CC); if (resize) { pollset->items = erealloc(pollset->items, (pollset->alloc_size + PHP_ZMQ_ALLOC_SIZE) * sizeof(zmq_pollitem_t)); } memset(&(pollset->items[pollset->num_items]), 0, sizeof(zmq_pollitem_t)); pollset->items[pollset->num_items].socket = item->socket->z_socket; pollset->items[pollset->num_items].events = events; zend_objects_store_add_ref(entry TSRMLS_CC); } Z_ADDREF_P(entry); if (resize) { pollset->php_items = erealloc(pollset->php_items, (pollset->alloc_size + PHP_ZMQ_ALLOC_SIZE) * sizeof(php_zmq_pollitem)); pollset->alloc_size += PHP_ZMQ_ALLOC_SIZE; } pollset->php_items[pollset->num_php_items].events = events; pollset->php_items[pollset->num_php_items].entry = entry; pollset->php_items[pollset->num_php_items].key_len = key_len; if (Z_TYPE_P(entry) == IS_RESOURCE) { pollset->php_items[pollset->num_php_items].fd = pollset->items[pollset->num_items].fd; } else { pollset->php_items[pollset->num_php_items].socket = pollset->items[pollset->num_items].socket; } memcpy(pollset->php_items[pollset->num_php_items].key, key, key_len + 1); pollset->num_php_items++; pollset->num_items++; return (pollset->num_php_items - 1); } void php_zmq_pollset_rebuild(php_zmq_pollset *set) { int i; if (set->num_php_items == 0 && set->items) { efree(set->items); set->items = NULL; return; } /* Clear items */ if (set->items) { efree(set->items); } set->items = ecalloc(set->alloc_size, sizeof(zmq_pollitem_t)); for (i = 0; i < set->num_php_items; i++) { if (Z_TYPE_P(set->php_items[i].entry) == IS_RESOURCE) { set->items[i].fd = set->php_items[i].fd; } else { set->items[i].socket = set->php_items[i].socket; } set->items[i].events = set->php_items[i].events; } set->num_items = set->num_php_items; } static void php_zmq_pollitem_copy(php_zmq_pollitem *target, php_zmq_pollitem *source) { target->events = source->events; target->entry = source->entry; target->key_len = source->key_len; target->socket = source->socket; target->fd = source->fd; memcpy(target->key, source->key, source->key_len + 1); } zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, char key[35], int key_len TSRMLS_DC) { php_zmq_pollitem *php_items = NULL; int i, num_php_items = 0, alloc_size; zend_bool match = 0; alloc_size = (set->alloc_size - set->num_items > PHP_ZMQ_ALLOC_SIZE) ? (set->alloc_size - PHP_ZMQ_ALLOC_SIZE) : set->alloc_size; php_items = ecalloc(alloc_size, sizeof(php_zmq_pollitem)); for (i = 0; i < set->num_php_items; i++) { if (!match && key_len == set->php_items[i].key_len && !memcmp(set->php_items[i].key, key, key_len)) { if (Z_TYPE_P(set->php_items[i].entry) == IS_OBJECT) { zend_objects_store_del_ref(set->php_items[i].entry TSRMLS_CC); } zval_ptr_dtor(&(set->php_items[i].entry)); match = 1; continue; } php_zmq_pollitem_copy(&(php_items[num_php_items]), &(set->php_items[i])); num_php_items++; } php_zmq_pollset_clear(set, 0 TSRMLS_CC); set->php_items = php_items; set->num_php_items = num_php_items; set->alloc_size = alloc_size; php_zmq_pollset_rebuild(set); return match; } zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry TSRMLS_DC) { char key[35]; int key_len; php_zmq_create_key(entry, key, &key_len TSRMLS_CC); return php_zmq_pollset_delete_by_key(set, key, key_len TSRMLS_CC); } int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array, zval *e_array) { int rc, i; zend_bool readable = 0, writable = 0; zend_hash_clean(Z_ARRVAL_P(e_array)); if (r_array && Z_TYPE_P(r_array) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(r_array)) > 0) { zend_hash_clean(Z_ARRVAL_P(r_array)); } readable = 1; } if (w_array && Z_TYPE_P(w_array) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(w_array)) > 0) { zend_hash_clean(Z_ARRVAL_P(w_array)); } writable = 1; } assert(set->num_items == set->num_php_items); rc = zmq_poll(set->items, set->num_items, timeout); if (rc == -1) { return -1; } if (rc > 0) { for (i = 0; i < set->num_items; i++) { if (readable && set->items[i].revents & ZMQ_POLLIN) { Z_ADDREF_P(set->php_items[i].entry); add_next_index_zval(r_array, set->php_items[i].entry); } if (writable && set->items[i].revents & ZMQ_POLLOUT) { Z_ADDREF_P(set->php_items[i].entry); add_next_index_zval(w_array, set->php_items[i].entry); } if (set->items[i].revents & ZMQ_POLLERR) { add_next_index_string(e_array, set->php_items[i].key, set->php_items[i].key_len); } } } return rc; } zmq-1.1.3/php5/zmq_sockopt.c0000644000076500000240000051303712653534763012661 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } 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_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; 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); #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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } 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; 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 #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 /* {{{ 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_SNDHWM: { 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_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVHWM: { 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_RCVHWM 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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } break; case ZMQ_RATE: { 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_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RECOVERY_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_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_SNDBUF: { 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_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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: { 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_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_EVENTS: { 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_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_RCVLABEL: { 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_RCVLABEL 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; 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_SNDHWM: { 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_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVHWM: { 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_RCVHWM 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: { 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_RATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RECOVERY_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_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_SNDBUF: { 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_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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; case ZMQ_RCVLABEL: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVLABEL is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } break; case ZMQ_HWM: { int value; convert_to_long(pz_value); if (Z_LVAL_P(pz_value) < 0) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The option value must be zero or larger", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } value = (int) Z_LVAL_P(pz_value); status = zmq_setsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof(int)); if (status == 0) { status = zmq_setsockopt(intern->socket->z_socket, ZMQ_RCVHWM, &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_HWM 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_SNDHWM", ZMQ_SNDHWM); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); 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_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_MAXMSGSIZE", ZMQ_MAXMSGSIZE); 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); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVLABEL", ZMQ_RCVLABEL); #undef PHP_ZMQ_REGISTER_SOCKOPT } #endif #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 1 /* {{{ 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_SNDHWM: { 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_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVHWM: { 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_RCVHWM 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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } break; case ZMQ_RATE: { 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_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RECOVERY_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_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_SNDBUF: { 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_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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: { 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_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_EVENTS: { 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_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; 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_SNDHWM: { 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_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVHWM: { 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_RCVHWM 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: { 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_RATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RECOVERY_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_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_SNDBUF: { 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_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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; case ZMQ_HWM: { int value; convert_to_long(pz_value); if (Z_LVAL_P(pz_value) < 0) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The option value must be zero or larger", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } value = (int) Z_LVAL_P(pz_value); status = zmq_setsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof(int)); if (status == 0) { status = zmq_setsockopt(intern->socket->z_socket, ZMQ_RCVHWM, &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_HWM 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_SNDHWM", ZMQ_SNDHWM); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); 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_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_MAXMSGSIZE", ZMQ_MAXMSGSIZE); 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 == 2 && ZMQ_VERSION_PATCH == 0) /* {{{ 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_SNDHWM: { 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_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVHWM: { 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_RCVHWM 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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } break; case ZMQ_RATE: { 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_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RECOVERY_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_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_SNDBUF: { 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_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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: { 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_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_EVENTS: { 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_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_IPV4ONLY: { 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_IPV4ONLY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_LAST_ENDPOINT: { char value[255]; value_len = 255; 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_LAST_ENDPOINT value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1, 1); } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_ACCEPT_FILTER: { char value[255]; value_len = 255; 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_TCP_ACCEPT_FILTER value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } 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; 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_SNDHWM: { 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_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVHWM: { 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_RCVHWM 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: { 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_RATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RECOVERY_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_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_SNDBUF: { 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_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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; case ZMQ_IPV4ONLY: { 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_IPV4ONLY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_LAST_ENDPOINT: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_LAST_ENDPOINT is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_ACCEPT_FILTER: { 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_TCP_ACCEPT_FILTER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_HWM: { int value; convert_to_long(pz_value); if (Z_LVAL_P(pz_value) < 0) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The option value must be zero or larger", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } value = (int) Z_LVAL_P(pz_value); status = zmq_setsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof(int)); if (status == 0) { status = zmq_setsockopt(intern->socket->z_socket, ZMQ_RCVHWM, &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_HWM 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_SNDHWM", ZMQ_SNDHWM); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); 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_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_MAXMSGSIZE", ZMQ_MAXMSGSIZE); 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); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV4ONLY", ZMQ_IPV4ONLY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LAST_ENDPOINT", ZMQ_LAST_ENDPOINT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE", ZMQ_TCP_KEEPALIVE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_IDLE", ZMQ_TCP_KEEPALIVE_IDLE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_CNT", ZMQ_TCP_KEEPALIVE_CNT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_INTVL", ZMQ_TCP_KEEPALIVE_INTVL); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_ACCEPT_FILTER", ZMQ_TCP_ACCEPT_FILTER); #undef PHP_ZMQ_REGISTER_SOCKOPT } #endif #if (ZMQ_VERSION_MAJOR == 3 && ((ZMQ_VERSION_MINOR == 2 && ZMQ_VERSION_PATCH > 0) || (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_SNDHWM: { 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_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVHWM: { 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_RCVHWM 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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } break; case ZMQ_RATE: { 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_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RECOVERY_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_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_SNDBUF: { 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_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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: { 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_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_EVENTS: { 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_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_IPV4ONLY: { 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_IPV4ONLY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_LAST_ENDPOINT: { char value[255]; value_len = 255; 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_LAST_ENDPOINT value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1, 1); } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_ACCEPT_FILTER: { char value[255]; value_len = 255; 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_TCP_ACCEPT_FILTER value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_DELAY_ATTACH_ON_CONNECT: { 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_DELAY_ATTACH_ON_CONNECT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_XPUB_VERBOSE: { 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_XPUB_VERBOSE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_ROUTER_MANDATORY: { 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_ROUTER_MANDATORY 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; 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_SNDHWM: { 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_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVHWM: { 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_RCVHWM 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: { 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_RATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RECOVERY_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_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_SNDBUF: { 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_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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; case ZMQ_IPV4ONLY: { 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_IPV4ONLY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_LAST_ENDPOINT: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_LAST_ENDPOINT is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_ACCEPT_FILTER: { 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_TCP_ACCEPT_FILTER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_DELAY_ATTACH_ON_CONNECT: { 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_DELAY_ATTACH_ON_CONNECT option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_XPUB_VERBOSE: { 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_XPUB_VERBOSE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_ROUTER_MANDATORY: { 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_ROUTER_MANDATORY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_HWM: { int value; convert_to_long(pz_value); if (Z_LVAL_P(pz_value) < 0) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The option value must be zero or larger", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } value = (int) Z_LVAL_P(pz_value); status = zmq_setsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof(int)); if (status == 0) { status = zmq_setsockopt(intern->socket->z_socket, ZMQ_RCVHWM, &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_HWM 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_SNDHWM", ZMQ_SNDHWM); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); 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_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_MAXMSGSIZE", ZMQ_MAXMSGSIZE); 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); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV4ONLY", ZMQ_IPV4ONLY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LAST_ENDPOINT", ZMQ_LAST_ENDPOINT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE", ZMQ_TCP_KEEPALIVE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_IDLE", ZMQ_TCP_KEEPALIVE_IDLE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_CNT", ZMQ_TCP_KEEPALIVE_CNT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_INTVL", ZMQ_TCP_KEEPALIVE_INTVL); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_ACCEPT_FILTER", ZMQ_TCP_ACCEPT_FILTER); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_DELAY_ATTACH_ON_CONNECT", ZMQ_DELAY_ATTACH_ON_CONNECT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_XPUB_VERBOSE", ZMQ_XPUB_VERBOSE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_MANDATORY", ZMQ_ROUTER_MANDATORY); #undef PHP_ZMQ_REGISTER_SOCKOPT } #endif #if ZMQ_VERSION_MAJOR >= 4 /* {{{ 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_SNDHWM: { 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_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVHWM: { 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_RCVHWM 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_IDENTITY: { char value[255]; value_len = 255; 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(value, value_len, 1); } break; case ZMQ_RATE: { 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_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RECOVERY_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_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_SNDBUF: { 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_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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: { 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_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_EVENTS: { 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_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_IPV4ONLY: { 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_IPV4ONLY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_LAST_ENDPOINT: { char value[255]; value_len = 255; 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_LAST_ENDPOINT value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1, 1); } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_TCP_ACCEPT_FILTER: { char value[255]; value_len = 255; 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_TCP_ACCEPT_FILTER value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_DELAY_ATTACH_ON_CONNECT: { 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_DELAY_ATTACH_ON_CONNECT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_XPUB_VERBOSE: { 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_XPUB_VERBOSE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_ROUTER_MANDATORY: { 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_ROUTER_MANDATORY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_ROUTER_RAW: { 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_ROUTER_RAW value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_IPV6: { 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_IPV6 value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_PLAIN_SERVER: { 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_PLAIN_SERVER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_PLAIN_USERNAME: { char value[255]; value_len = 255; 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_PLAIN_USERNAME value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_PLAIN_PASSWORD: { char value[255]; value_len = 255; 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_PLAIN_PASSWORD value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_CURVE_SERVER: { 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_CURVE_SERVER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_CURVE_PUBLICKEY: { char value[255]; value_len = 255; 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_CURVE_PUBLICKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_CURVE_SECRETKEY: { char value[255]; value_len = 255; 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_CURVE_SECRETKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_CURVE_SERVERKEY: { char value[255]; value_len = 255; 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_CURVE_SERVERKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } break; case ZMQ_PROBE_ROUTER: { 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_PROBE_ROUTER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_REQ_CORRELATE: { 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_REQ_CORRELATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_REQ_RELAXED: { 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_REQ_RELAXED value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_CONFLATE: { 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_CONFLATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; case ZMQ_ZAP_DOMAIN: { char value[255]; value_len = 255; 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_ZAP_DOMAIN value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len, 1); } 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; 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_SNDHWM: { 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_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVHWM: { 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_RCVHWM 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: { 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_RATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RECOVERY_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_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_SNDBUF: { 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_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_RCVBUF: { 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_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_MAXMSGSIZE: { 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_MAXMSGSIZE 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; case ZMQ_IPV4ONLY: { 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_IPV4ONLY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_LAST_ENDPOINT: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_LAST_ENDPOINT is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } break; case ZMQ_TCP_KEEPALIVE: { 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_TCP_KEEPALIVE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_IDLE: { 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_TCP_KEEPALIVE_IDLE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_CNT: { 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_TCP_KEEPALIVE_CNT option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_KEEPALIVE_INTVL: { 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_TCP_KEEPALIVE_INTVL option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_TCP_ACCEPT_FILTER: { 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_TCP_ACCEPT_FILTER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_DELAY_ATTACH_ON_CONNECT: { 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_DELAY_ATTACH_ON_CONNECT option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_XPUB_VERBOSE: { 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_XPUB_VERBOSE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_ROUTER_MANDATORY: { 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_ROUTER_MANDATORY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_ROUTER_RAW: { 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_ROUTER_RAW option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_IPV6: { 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_IPV6 option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_PLAIN_SERVER: { 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_PLAIN_SERVER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_PLAIN_USERNAME: { 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_PLAIN_USERNAME option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_PLAIN_PASSWORD: { 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_PLAIN_PASSWORD option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_CURVE_SERVER: { 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_CURVE_SERVER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_CURVE_PUBLICKEY: { 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_CURVE_PUBLICKEY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_CURVE_SECRETKEY: { 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_CURVE_SECRETKEY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_CURVE_SERVERKEY: { 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_CURVE_SERVERKEY option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_PROBE_ROUTER: { 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_PROBE_ROUTER option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_REQ_CORRELATE: { 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_REQ_CORRELATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_REQ_RELAXED: { 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_REQ_RELAXED option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_CONFLATE: { 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_CONFLATE option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_ZAP_DOMAIN: { 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_ZAP_DOMAIN option: %s", zmq_strerror(errno)); return; } } break; case ZMQ_HWM: { int value; convert_to_long(pz_value); if (Z_LVAL_P(pz_value) < 0) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The option value must be zero or larger", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC); return; } value = (int) Z_LVAL_P(pz_value); status = zmq_setsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof(int)); if (status == 0) { status = zmq_setsockopt(intern->socket->z_socket, ZMQ_RCVHWM, &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_HWM 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_SNDHWM", ZMQ_SNDHWM); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); 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_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_MAXMSGSIZE", ZMQ_MAXMSGSIZE); 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); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV4ONLY", ZMQ_IPV4ONLY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LAST_ENDPOINT", ZMQ_LAST_ENDPOINT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE", ZMQ_TCP_KEEPALIVE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_IDLE", ZMQ_TCP_KEEPALIVE_IDLE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_CNT", ZMQ_TCP_KEEPALIVE_CNT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_INTVL", ZMQ_TCP_KEEPALIVE_INTVL); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_ACCEPT_FILTER", ZMQ_TCP_ACCEPT_FILTER); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_DELAY_ATTACH_ON_CONNECT", ZMQ_DELAY_ATTACH_ON_CONNECT); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_XPUB_VERBOSE", ZMQ_XPUB_VERBOSE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_MANDATORY", ZMQ_ROUTER_MANDATORY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_RAW", ZMQ_ROUTER_RAW); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV6", ZMQ_IPV6); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_SERVER", ZMQ_PLAIN_SERVER); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_USERNAME", ZMQ_PLAIN_USERNAME); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_PASSWORD", ZMQ_PLAIN_PASSWORD); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SERVER", ZMQ_CURVE_SERVER); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_PUBLICKEY", ZMQ_CURVE_PUBLICKEY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SECRETKEY", ZMQ_CURVE_SECRETKEY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SERVERKEY", ZMQ_CURVE_SERVERKEY); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PROBE_ROUTER", ZMQ_PROBE_ROUTER); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_REQ_CORRELATE", ZMQ_REQ_CORRELATE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_REQ_RELAXED", ZMQ_REQ_RELAXED); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CONFLATE", ZMQ_CONFLATE); PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ZAP_DOMAIN", ZMQ_ZAP_DOMAIN); #undef PHP_ZMQ_REGISTER_SOCKOPT } #endif zmq-1.1.3/php5/zmq_clock.c0000644000076500000240000001270012653534763012261 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef HAVE_TIME_H # include #endif #ifdef HAVE_SYS_TIME_H # include #endif #ifdef HAVE_MACH_MACH_TIME_H # include #endif #if defined(PHP_WIN32) # include "win32/time.h" #endif static uint64_t s_backup_clock () { #if defined(HAVE_GETTIMEOFDAY) struct timeval tv; gettimeofday(&tv, NULL); return (uint64_t) (((uint64_t) tv.tv_sec * 1000) + ((uint64_t) tv.tv_usec / 1000)); #endif php_error (E_ERROR, "Failed to get current time"); return 0; } /* Systems supporting clock_gettime(CLOCK_MONOTONIC) */ #if defined(HAVE_CLOCK_GETTIME) && (defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC)) struct _php_zmq_clock_ctx_t {}; php_zmq_clock_ctx_t *php_zmq_clock_init () { return malloc (sizeof (php_zmq_clock_ctx_t)); } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { struct timespec ts; #if defined(CLOCK_MONOTONIC_RAW) if (clock_gettime (CLOCK_MONOTONIC_RAW, &ts) == 0) { #else if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) { #endif return (uint64_t) (((uint64_t) ts.tv_sec * 1000) + ((uint64_t) ts.tv_nsec / 1000000)); } return s_backup_clock (); } /* Mac OS X */ #elif defined(HAVE_MACH_ABSOLUTE_TIME) struct _php_zmq_clock_ctx_t { uint64_t scaling_factor; }; php_zmq_clock_ctx_t *php_zmq_clock_init () { php_zmq_clock_ctx_t *ctx; mach_timebase_info_data_t info; if (mach_timebase_info (&info) != 0) { return NULL; } ctx = malloc (sizeof (php_zmq_clock_ctx_t)); ctx->scaling_factor = (info.numer / info.denom); return ctx; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *ctx) { return (mach_absolute_time () * ctx->scaling_factor) / 1000000; } /* Windows systems. Not using QueryPerformanceCounter because of: https://www.virtualbox.org/ticket/11951 */ #elif defined(PHP_WIN32) struct _php_zmq_clock_ctx_t { int wrap_count; uint64_t last_ticks; }; php_zmq_clock_ctx_t *php_zmq_clock_init () { return calloc (1, sizeof (php_zmq_clock_ctx_t)); } static uint64_t s_get_tick_count (php_zmq_clock_ctx_t *clock_ctx) { uint64_t ticks = (uint64_t) GetTickCount (); /* Has the clock wrapped? */ if (ticks < clock_ctx->last_ticks) ++clock_ctx->wrap_count; clock_ctx->last_ticks = ticks; ticks += (uint64_t) clock_ctx->wrap_count * (uint64_t) MAXDWORD; return ticks; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { return s_get_tick_count (clock_ctx); } #elif defined(HAVE_GETTIMEOFDAY) struct _php_zmq_clock_ctx_t {}; php_zmq_clock_ctx_t *php_zmq_clock_init () { return malloc (sizeof (php_zmq_clock_ctx_t)); } static uint64_t s_get_tick_count (php_zmq_clock_ctx_t *clock_ctx) { uint64_t ticks = (uint64_t) GetTickCount (); /* Has the clock wrapped? */ if (ticks < clock_ctx->last_ticks) ++clock_ctx->wrap_count; clock_ctx->last_ticks = ticks; ticks += (uint64_t) clock_ctx->wrap_count * MAX_DWORD; return ticks; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { return s_backup_clock (); } #else # error "Cannot find a clock that would work on this platform. Please report a bug" #endif void php_zmq_clock_destroy (php_zmq_clock_ctx_t **clock_ctx) { free (*clock_ctx); } zmq-1.1.3/php5/php_zmq.h0000644000076500000240000000513212653534763011763 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_H_ # define _PHP_ZMQ_H_ #define PHP_ZMQ_EXTNAME "zmq" #define PHP_ZMQ_VERSION "1.1.3" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef ZTS # include "TSRM.h" #endif #include "php.h" extern zend_module_entry zmq_module_entry; #define phpext_zmq_ptr &zmq_module_entry #endif /* _PHP_ZMQ_H_ */ zmq-1.1.3/php5/php_zmq_private.h0000644000076500000240000001763012653534763013523 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_PRIVATE_H_ # define _PHP_ZMQ_PRIVATE_H_ #include "ext/standard/info.h" #include "Zend/zend_exceptions.h" #include "main/php_ini.h" #include #ifdef HAVE_CZMQ # include # if CZMQ_VERSION_MAJOR >= 2 # define HAVE_CZMQ_2 # endif #endif #ifdef PHP_WIN32 # include "win32/php_stdint.h" #else # include #endif /* {{{ typedef struct _php_zmq_pollitem */ typedef struct _php_zmq_pollitem { int events; zval *entry; char key[35]; int key_len; /* convenience pointer containing fd or socket */ void *socket; int fd; } php_zmq_pollitem; /* }}} */ /* {{{ typedef struct _php_zmq_pollset */ typedef struct _php_zmq_pollset { php_zmq_pollitem *php_items; int num_php_items; /* items and a count */ zmq_pollitem_t *items; int num_items; /* How many allocated */ int alloc_size; /* Errors in the last poll */ zval *errors; } php_zmq_pollset; /* }}} */ /* {{{ typedef struct _php_zmq_context */ typedef struct _php_zmq_context { /* zmq context */ void *z_ctx; /* Amount of io-threads */ int io_threads; /* Is this a persistent context */ zend_bool is_persistent; /* Should this context live to end of request */ zend_bool is_global; /* Who created me */ int pid; } php_zmq_context; /* }}} */ /* {{{ typedef struct _php_zmq_socket */ typedef struct _php_zmq_socket { void *z_socket; php_zmq_context *ctx; HashTable connect; HashTable bind; zend_bool is_persistent; /* Who created me */ int pid; } php_zmq_socket; /* }}} */ /* {{{ typedef struct _php_zmq_context_object */ typedef struct _php_zmq_context_object { zend_object zo; php_zmq_context *context; } php_zmq_context_object; /* }}} */ /* {{{ typedef struct _php_zmq_socket_object */ typedef struct _php_zmq_socket_object { zend_object zo; php_zmq_socket *socket; /* options for the context */ char *persistent_id; /* zval of the context */ zval *context_obj; } php_zmq_socket_object; /* }}} */ /* {{{ typedef struct _php_zmq_poll_object */ typedef struct _php_zmq_poll_object { zend_object zo; php_zmq_pollset set; } php_zmq_poll_object; /* }}} */ typedef struct _php_zmq_device_cb_t { zend_bool initialized; long timeout; zend_fcall_info fci; zend_fcall_info_cache fci_cache; zval *user_data; uint64_t scheduled_at; } php_zmq_device_cb_t; /* {{{ typedef struct _php_zmq_device_object */ typedef struct _php_zmq_device_object { zend_object zo; php_zmq_device_cb_t idle_cb; php_zmq_device_cb_t timer_cb; zval *front; zval *back; zval *capture; } php_zmq_device_object; /* }}} */ #ifdef ZTS # define ZMQ_G(v) TSRMG(php_zmq_globals_id, zend_php_zmq_globals *, v) #else # define ZMQ_G(v) (php_zmq_globals.v) #endif #define PHP_ZMQ_CONTEXT_OBJECT (php_zmq_context_object *)zend_object_store_get_object(getThis() TSRMLS_CC); #define PHP_ZMQ_SOCKET_OBJECT (php_zmq_socket_object *)zend_object_store_get_object(getThis() TSRMLS_CC); #define PHP_ZMQ_POLL_OBJECT (php_zmq_poll_object *)zend_object_store_get_object(getThis() TSRMLS_CC); #define PHP_ZMQ_DEVICE_OBJECT (php_zmq_device_object *)zend_object_store_get_object(getThis() TSRMLS_CC); #define ZMQ_RETURN_THIS RETURN_ZVAL(getThis(), 1, 0); #ifndef Z_ADDREF_P # define Z_ADDREF_P(pz) (pz)->refcount++ #endif #ifndef Z_DELREF_P # define Z_DELREF_P(pz) (pz)->refcount-- #endif #ifndef Z_REFCOUNT_P # define Z_REFCOUNT_P(pz) (pz)->refcount #endif #if ZEND_MODULE_API_NO > 20060613 #define PHP_ZMQ_ERROR_HANDLING_INIT() zend_error_handling error_handling; #define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling TSRMLS_CC); #define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC); #else #define PHP_ZMQ_ERROR_HANDLING_INIT() #define PHP_ZMQ_ERROR_HANDLING_THROW() php_set_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry TSRMLS_CC); #define PHP_ZMQ_ERROR_HANDLING_RESTORE() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); #endif /* Compatibility macros between zeromq 2.x and 3.x */ #ifndef ZMQ_DONTWAIT # define ZMQ_DONTWAIT ZMQ_NOBLOCK #endif #ifndef ZMQ_HWM # define ZMQ_HWM (ZMQ_DONTWAIT + 200) #endif #ifndef ZMQ_FORWARDER # define ZMQ_FORWARDER 0 #endif #ifndef ZMQ_QUEUE # define ZMQ_QUEUE 0 #endif #ifndef ZMQ_STREAMER # define ZMQ_STREAMER 0 #endif #if ZMQ_VERSION_MAJOR == 2 # define zmq_sendmsg zmq_send # define zmq_recvmsg zmq_recv # define PHP_ZMQ_TIMEOUT 1000 #else # define PHP_ZMQ_TIMEOUT 1 #endif #define PHP_ZMQ_INTERNAL_ERROR -99 #define PHP_ZMQ_VERSION_LEN 24 #ifdef HAVE_CZMQ_2 # define PHP_ZMQ_AUTH_TYPE_PLAIN 0 # define PHP_ZMQ_AUTH_TYPE_CURVE 1 #endif PHP_METHOD(zmqsocket, getsockopt); PHP_METHOD(zmqsocket, setsockopt); zend_bool php_zmq_device(php_zmq_device_object *intern TSRMLS_DC); zend_class_entry *php_zmq_socket_exception_sc_entry_get (); zend_class_entry *php_zmq_device_exception_sc_entry_get (); php_stream *php_zmq_create_zmq_fd(zval *obj TSRMLS_DC); void php_zmq_register_sockopt_constants (zend_class_entry *ce TSRMLS_DC); typedef struct _php_zmq_clock_ctx_t php_zmq_clock_ctx_t; php_zmq_clock_ctx_t *php_zmq_clock_init (); uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx); void php_zmq_clock_destroy (php_zmq_clock_ctx_t **clock_ctx); char *php_zmq_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC); ZEND_BEGIN_MODULE_GLOBALS(php_zmq) php_zmq_clock_ctx_t *clock_ctx; ZEND_END_MODULE_GLOBALS(php_zmq) #ifdef HAVE_CZMQ_2 typedef struct _php_zmq_cert { zend_object zend_object; zcert_t *zcert; } php_zmq_cert_object; typedef struct _php_zmq_auth { zend_object zend_object; zctx_t *shadow_context; zauth_t *zauth; } php_zmq_auth_object; #endif #endif /* _PHP_ZMQ_PRIVATE_H_ */ zmq-1.1.3/php5/php_zmq_pollset.h0000644000076500000240000001061312653534763013525 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_POLLSET_H_ # define _PHP_ZMQ_POLLSET_H_ #define PHP_ZMQ_POLLSET_ERR_NO_STREAM -1 #define PHP_ZMQ_POLLSET_ERR_CANNOT_CAST -2 #define PHP_ZMQ_POLLSET_ERR_CAST_FAILED -3 #define PHP_ZMQ_POLLSET_ERR_NO_INIT -4 #define PHP_ZMQ_POLLSET_ERR_NO_POLL -5 #define PHP_ZMQ_POLLSET_ERR_KEY_FAIL -6 #define PHP_ZMQ_POLLSET_ERR_INVALID_TYPE -7 /** {{{ void php_zmq_pollset_init(php_zmq_pollset *set); */ void php_zmq_pollset_init(php_zmq_pollset *set); /* }}} */ /** {{{ void php_zmq_pollset_deinit(php_zmq_pollset *set TSRMLS_DC); */ void php_zmq_pollset_deinit(php_zmq_pollset *set TSRMLS_DC); /* }}} */ /** {{{ void php_zmq_pollset_clear(php_zmq_pollset *set, zend_bool reinit); */ void php_zmq_pollset_clear(php_zmq_pollset *set, zend_bool reinit TSRMLS_DC); /* }}} */ /** {{{ int php_zmq_pollset_add(php_zmq_pollset *set, zval *entry, int events TSRMLS_DC); */ int php_zmq_pollset_add(php_zmq_pollset *set, zval *entry, int events TSRMLS_DC); /* }}} */ /** {{{ void php_zmq_pollset_rebuild(php_zmq_pollset *set); */ void php_zmq_pollset_rebuild(php_zmq_pollset *set); /* }}} */ /** {{{ zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry TSRMLS_DC); */ zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry TSRMLS_DC); /* }}} */ /** {{{ int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array, zval *e_array); */ int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array, zval *e_array); /* }}} */ /** {{{ zend_bool php_zmq_pollset_get_key(php_zmq_pollset *set, int pos, char key[35], int *key_len TSRMLS_DC); */ zend_bool php_zmq_pollset_get_key(php_zmq_pollset *set, int pos, char key[35], int *key_len TSRMLS_DC); /* }}} */ /** {{{ zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, char key[35], int key_len TSRMLS_DC); */ zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, char key[35], int key_len TSRMLS_DC); /* }}} */ /** {{{ void php_zmq_pollset_delete_all(php_zmq_pollset *set TSRMLS_DC); */ void php_zmq_pollset_delete_all(php_zmq_pollset *set TSRMLS_DC); /* }}} */ #endif /* _PHP_ZMQ_POLLSET_H_ */ zmq-1.1.3/tests/001-send.phpt0000644000076500000240000000070312653534763012545 0ustar --TEST-- Test send / recv --SKIPIF-- --FILE-- sendmsg("Hello world!"); $message = $server->recvmsg(); var_dump($message); $server->sendmsg($message); $message = $client->recvmsg(); var_dump($message); --EXPECT-- string(12) "Hello world!" string(12) "Hello world!"zmq-1.1.3/tests/002-test-binary.phpt0000644000076500000240000000103212653534763014052 0ustar --TEST-- Test send / recv binary --SKIPIF-- --FILE-- sendmsg($rose); $message = $server->recvmsg(); var_dump(strlen($message)); $server->sendmsg($message); $message = $client->recvmsg(); var_dump(strlen($message)); var_dump($message === $rose); --EXPECTF-- int(1580) int(1580) bool(true)zmq-1.1.3/tests/003-getpersistentid.phpt0000644000076500000240000000042612653534763015035 0ustar --TEST-- Test getting persistent id --SKIPIF-- --FILE-- getPersistentId()); --EXPECT-- string(5) "hello"zmq-1.1.3/tests/004-getendpoints.phpt0000644000076500000240000000132412653534763014322 0ustar --TEST-- Test getting endpoints --SKIPIF-- --FILE-- getEndpoints()); var_dump($server->getEndpoints()); $socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ); var_dump($socket->getEndpoints()); --EXPECTF-- array(2) { ["connect"]=> array(1) { [0]=> string(%d) "inproc://php-test" } ["bind"]=> array(0) { } } array(2) { ["connect"]=> array(0) { } ["bind"]=> array(1) { [0]=> string(%d) "inproc://php-test" } } array(2) { ["connect"]=> array(0) { } ["bind"]=> array(0) { } }zmq-1.1.3/tests/005-forceconnectarg.phpt0000644000076500000240000000116712653534763014767 0ustar --TEST-- Test forcing connect --SKIPIF-- --FILE-- connect("tcp://127.0.0.1:5566"); $socket->connect("tcp://127.0.0.1:5566", true); $socket->connect("tcp://127.0.0.1:5566", true); $socket->connect("tcp://127.0.0.1:5566", true); $socket->connect("tcp://127.0.0.1:5566"); var_dump($socket->getEndpoints()); --EXPECTF-- array(2) { ["connect"]=> array(1) { [0]=> string(20) "tcp://127.0.0.1:5566" } ["bind"]=> array(0) { } }zmq-1.1.3/tests/006-sockopt.phpt0000644000076500000240000000136212653534763013305 0ustar --TEST-- Test getsockopt / setsockopt --SKIPIF-- --FILE-- setSockOpt(ZMQ::SOCKOPT_IDENTITY, "hello"); var_dump($test->getSockOpt(ZMQ::SOCKOPT_IDENTITY)); $test->setSockOpt(ZMQ::SOCKOPT_IDENTITY, str_repeat("a", 255)); var_dump(strlen($test->getSockOpt(ZMQ::SOCKOPT_IDENTITY))); try { $test->setSockOpt(ZMQ::SOCKOPT_IDENTITY, str_repeat("a", 300)); var_dump(strlen($test->getSockOpt(ZMQ::SOCKOPT_IDENTITY))); } catch (ZMQSocketException $e) { echo "too long"; } --EXPECT-- string(5) "hello" int(255) too long zmq-1.1.3/tests/007-addremovepoll.phpt0000644000076500000240000000307012653534763014457 0ustar --TEST-- Test adding / removing items --SKIPIF-- --FILE-- add($z, ZMQ::POLL_IN); $fp_id = $poll->add($stream, ZMQ::POLL_IN | ZMQ::POLL_OUT); var_dump($obj_id, $fp_id, $poll->count()); $readable = array(); $writable = array(); $poll->poll($readable, $writable, 1000); var_dump($readable, $writable); fclose ($stream); fclose ($socket_client); fclose ($socket_server); var_dump($poll->poll($readable, $writable, 1000)); var_dump($poll->getLastErrors()); $poll->remove($fp_id); $poll->clear(); var_dump($poll->count()); --EXPECTF-- string(34) "o:%s" string(3) "r:%d" int(2) array(1) { [0]=> resource(%d) of type (stream) } array(1) { [0]=> resource(%d) of type (stream) } int(1) array(1) { [0]=> string(3) "r:%d" } int(0)zmq-1.1.3/tests/008-twowaystoconstruct.phpt0000644000076500000240000000060412653534763015650 0ustar --TEST-- Test constructing a socket --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REQ); var_dump($socket2); --EXPECTF-- object(ZMQSocket)#%d (%d) { } object(ZMQSocket)#%d (%d) { }zmq-1.1.3/tests/009-ispersistent.phpt0000644000076500000240000000172712653534763014367 0ustar --TEST-- Test ispersistent on context and socket --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REQ, 'persistentId'); $socket2 = $context->getSocket(ZMQ::SOCKET_REQ, null); var_dump($context->isPersistent(), $socket->isPersistent(), $socket->getPersistentId(), $socket2->isPersistent(), $socket2->getPersistentId()); /* Non-persistent context */ $context = new ZMQContext(1, false); $socket = $context->getSocket(ZMQ::SOCKET_REQ, 'persistentId'); $socket2 = $context->getSocket(ZMQ::SOCKET_REQ, null); var_dump($context->isPersistent(), $socket->isPersistent(), $socket->getPersistentId(), $socket2->isPersistent(), $socket2->getPersistentId()); --EXPECTF-- bool(true) bool(true) string(12) "persistentId" bool(false) NULL bool(false) bool(false) NULL bool(false) NULLzmq-1.1.3/tests/010-pollsetinvalidargs.phpt0000644000076500000240000000064312653534763015525 0ustar --TEST-- Test invalid args for ZMQPoll --SKIPIF-- --FILE-- add('string here', 0); } catch (ZMQPollException $e) { echo "Got exception\n"; } try { $poll = new ZMQPoll(); $poll->add(new stdClass(), 0); } catch (ZMQPollException $e) { echo "Got second exception\n"; } --EXPECT-- Got exception Got second exceptionzmq-1.1.3/tests/011-exceptions.phpt0000644000076500000240000000064612653534763014004 0ustar --TEST-- Test exceptions --SKIPIF-- --FILE-- --FILE-- add(fopen(__FILE__, 'r'), ZMQ::POLL_IN); $id2 = $poll->add($sock, ZMQ::POLL_IN); $poll->remove($id1); $poll->remove("adsads"); echo "OK"; --EXPECT-- OKzmq-1.1.3/tests/013-pollclearandreuse.phpt0000644000076500000240000000124112653534763015321 0ustar --TEST-- Test clearing and reusing ZMQPoll --SKIPIF-- --FILE-- add(new ZMQSocket($ctx, ZMQ::SOCKET_REP), ZMQ::POLL_IN); } var_dump($poll->count()); $poll->clear(); var_dump($poll->count()); for ($i = 0; $i < 10; $i++) { $ids[] = $poll->add(new ZMQSocket($ctx, ZMQ::SOCKET_REP, 'dfd'), ZMQ::POLL_IN); } var_dump($poll->count()); for ($i = 0; $i < 10; $i++) { if ($poll->remove($ids[$i]) !== true) { echo 'err'; } } var_dump($poll->count()); --EXPECT-- int(10) int(0) int(10) int(0)zmq-1.1.3/tests/014-setsockoptparam.phpt0000644000076500000240000000052712653534763015043 0ustar --TEST-- Test setSockOpt param type --SKIPIF-- --FILE-- setSockOpt(ZMQ::SOCKOPT_HWM, $test); echo gettype($test) . "\n"; echo "done\n"; --EXPECT-- string donezmq-1.1.3/tests/015-callback.phpt0000644000076500000240000000131012653534763013350 0ustar --TEST-- Test basic callback usage --SKIPIF-- --FILE-- getEndpoints()); $ctx = new ZMQContext(); $socket = $ctx->getSocket(ZMQ::SOCKET_REQ, 'my persistent 2', 'bind_callback'); var_dump($socket->getEndpoints()); --EXPECT-- array(2) { ["connect"]=> array(0) { } ["bind"]=> array(1) { [0]=> string(22) "inproc://php-test-5566" } } array(2) { ["connect"]=> array(0) { } ["bind"]=> array(1) { [0]=> string(22) "inproc://php-test-5567" } }zmq-1.1.3/tests/016-callbackinvalidargs.phpt0000644000076500000240000000101112653534763015573 0ustar --TEST-- Test invalid args for callback --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REQ, 'my persistent 2', 'this_function_does_not_exist'); echo "Fail\n"; } catch (ZMQSocketException $e) { echo "OK\n"; } --EXPECT-- OK OKzmq-1.1.3/tests/017-callbackonlyonnewsocket.phpt0000644000076500000240000000142212653534763016540 0ustar --TEST-- Test that callback is only called on new socket --SKIPIF-- --FILE-- getEndpoints(); echo count($array['bind']) . "\n"; echo "OK"; --EXPECT-- 1 OKzmq-1.1.3/tests/018-callbackpersistent.phpt0000644000076500000240000000101112653534763015472 0ustar --TEST-- Test callback arguments on persistent and non-persistent socket --SKIPIF-- --FILE-- --FILE-- --FILE-- getMessage() . "\n"; } --EXPECTF-- Hello there zmq-1.1.3/tests/021-callbackwarning.phpt0000644000076500000240000000056712653534763014750 0ustar --TEST-- Test warning in callback --SKIPIF-- --FILE-- if (!defined('ZMQ::SOCKOPT_LINGER')) die ("Skip Not compiled against new enough version"); --FILE-- setSockOpt(ZMQ::SOCKOPT_HWM, 1); $req->setSockOpt(ZMQ::SOCKOPT_LINGER, 1); $req->bind("tcp://127.0.0.1:44331"); $rep = new ZMQSocket($ctx, ZMQ::SOCKET_REP); $rep->connect("tcp://127.0.0.1:44331"); $poll->add($req, ZMQ::POLL_OUT); $poll->poll($readable, $writable, 1000); var_dump($writable); $req->sendmsg('x'); $poll->poll($readable, $writable, 1000); var_dump($writable); $rep->recvmsg (); $rep->sendmsg('x'); $req->recvmsg(); $poll->poll($readable, $writable, 1000); var_dump($writable); echo "OK\n"; ?> --EXPECTF-- array(1) { [0]=> object(ZMQSocket)#3 (0) { } } array(0) { } array(1) { [0]=> object(ZMQSocket)#3 (0) { } } OKzmq-1.1.3/tests/023-failedcallback.phpt0000644000076500000240000000253112653534763014522 0ustar --TEST-- Test that failing callback does not add socket to plist --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_PUSH, 'test id', 'throw_stuff'); echo "fail\n"; } catch (Exception $e) { echo "success\n"; } try { $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'test id', 'throw_stuff'); echo "fail\n"; } catch (Exception $e) { echo "success\n"; } try { $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'test id', 'just_echo'); echo "success\n"; } catch (Exception $e) { echo "fail\n"; } echo "OK\n"; /**/ try { $socket = new ZMQSocket($context, ZMQ::SOCKET_PUSH, 'xx id', 'throw_stuff'); echo "fail\n"; } catch (Exception $e) { echo "success\n"; } try { $socket = new ZMQSocket($context, ZMQ::SOCKET_PUSH, 'xx id', 'throw_stuff'); echo "fail\n"; } catch (Exception $e) { echo "success\n"; } try { $socket = new ZMQSocket($context, ZMQ::SOCKET_PUSH, 'xx id', 'just_echo'); echo "success\n"; } catch (Exception $e) { echo "fail\n"; } echo "OK\n"; --EXPECTF-- success success called just_echo success OK success success called just_echo success OK zmq-1.1.3/tests/024-versionconstant.phpt0000644000076500000240000000033612653534763015062 0ustar --TEST-- Test retrieving version --SKIPIF-- --FILE-- 0 && strpos(ZMQ::LIBZMQ_VER, ".") !== false ? "OK" : FAIL; --EXPECT-- OKzmq-1.1.3/tests/025-sendrecvmulti.phpt0000644000076500000240000000123212653534763014504 0ustar --TEST-- Test send / recv for multipart messages --SKIPIF-- --FILE-- sendmulti($message); var_dump($message); $messages = $server->recvmulti(); var_dump($messages); $e = $server->sendMulti($message); var_dump($e == $server); --EXPECT-- array(3) { [0]=> string(5) "Hello" [1]=> string(5) "World" [2]=> int(12314) } array(3) { [0]=> string(5) "Hello" [1]=> string(5) "World" [2]=> string(5) "12314" } bool(true)zmq-1.1.3/tests/026-sockettype.phpt0000644000076500000240000000101212653534763014007 0ustar --TEST-- Test returning socket type --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_PUSH)->getSocketType() === ZMQ::SOCKET_PUSH); var_dump ($context->getSocket(ZMQ::SOCKET_PUB)->getSocketType() === ZMQ::SOCKET_PUB); $socket = $context->getSocket(ZMQ::SOCKET_ROUTER); var_dump ($socket->getSocketType() === $socket->getSockOpt(ZMQ::SOCKOPT_TYPE)); echo "OK\n"; --EXPECTF-- bool(true) bool(true) bool(true) OK zmq-1.1.3/tests/027-getset.phpt0000644000076500000240000000111512653534763013115 0ustar --TEST-- Test setting and getting values --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_DEALER); $socket->setSockOpt (ZMQ::SOCKOPT_IDENTITY, "Hello"); var_dump ($socket->getSockOpt (ZMQ::SOCKOPT_IDENTITY)); $socket->setSockOpt (ZMQ::SOCKOPT_BACKLOG, 100); var_dump ($socket->getSockOpt (ZMQ::SOCKOPT_BACKLOG)); $socket->setSockOpt (ZMQ::SOCKOPT_LINGER, 50); var_dump ($socket->getSockOpt (ZMQ::SOCKOPT_LINGER)); echo "OK\n"; --EXPECTF-- string(5) "Hello" int(100) int(50) OK zmq-1.1.3/tests/028-xpub.phpt0000644000076500000240000000132012653534763012577 0ustar --TEST-- Test send / recv with XPUB and XSUB sockets --SKIPIF-- --FILE-- bind(ZEROMQ_TEST_DSN); $client = new ZMQSocket($context, ZMQ::SOCKET_SUB); $client->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "Hel"); $client->connect(ZEROMQ_TEST_DSN); var_dump(substr($server->recvmsg(), 1)); $server->sendmsg("Goodbye world!"); $server->sendmsg("Hello world!"); $message = $client->recvmsg(); var_dump($message); --EXPECT-- string(3) "Hel" string(12) "Hello world!"zmq-1.1.3/tests/029-xrepxreqdevice.phpt0000644000076500000240000000171312653534763014666 0ustar --TEST-- Test send / recv with an XREQ and XREP device --SKIPIF-- --FILE-- bind(ZEROMQ_TEST_DSN); $downstream = new ZMQSocket($context, ZMQ::SOCKET_XREP); $downstream->bind(ZEROMQ_TEST_DSN2); $device = new ZMQDevice($upstream, $downstream); $device->setIdleCallback('idle_func', 100, 'test'); $server = new ZMQSocket($context, ZMQ::SOCKET_REP); $server->connect(ZEROMQ_TEST_DSN); $client = new ZMQSocket($context, ZMQ::SOCKET_REQ); $client->connect(ZEROMQ_TEST_DSN2); $client->sendmsg("Hello server!"); $device->run(); var_dump($server->recvmsg()); $server->sendmsg("Hello client!"); $device->run(); var_dump($client->recvmsg()); --EXPECT-- string(13) "Hello server!" string(13) "Hello client!" zmq-1.1.3/tests/030-xrepmanualqueue.phpt0000644000076500000240000000252712653534763015045 0ustar --TEST-- Test send / recv with a manually created XREQ and XREP device --SKIPIF-- --FILE-- bind('inproc://xrep'); $xreq->bind('inproc://xreq'); $req->connect('inproc://xrep'); $rep->connect('inproc://xreq'); $in = array('hi', 'there'); $req->sendMulti($in); do { $message = $xrep->recv(); $more = $xrep->getSockOpt(ZMQ::SOCKOPT_RCVMORE); if( $xrep->getSockOpt( ZMQ::SOCKOPT_RCVLABEL ) ) { $xreq->send( $message, ZMQ::MODE_SNDLABEL ); } else { $xreq->send( $message, $more ? ZMQ::MODE_SNDMORE : 0 ); } } while( $more ); $out = $rep->recvMulti(); assert($in == $out); $rep->sendMulti(array("oh", "hello!")); do { $message = $xreq->recv(); $more = $xreq->getSockOpt(ZMQ::SOCKOPT_RCVMORE); if( $xreq->getSockOpt( ZMQ::SOCKOPT_RCVLABEL ) ) { $xrep->send( $message, ZMQ::MODE_SNDLABEL ); } else { $xrep->send( $message, $more ? ZMQ::MODE_SNDMORE : 0 ); } } while( $more ); var_dump($req->recvMulti()); --EXPECT-- array(2) { [0]=> string(2) "oh" [1]=> string(6) "hello!" } zmq-1.1.3/tests/031-lastendpoint.phpt0000644000076500000240000000077212653534763014331 0ustar --TEST-- Test last endpoint --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REP) ->bind("inproc://hello-there"); $endpoint = $server->getSockopt(ZMQ::SOCKOPT_LAST_ENDPOINT); var_dump($endpoint); echo "OK"; --EXPECT-- string(20) "inproc://hello-there" OKzmq-1.1.3/tests/032-contextopt.phpt0000644000076500000240000000100312653534763014021 0ustar --TEST-- Test context options --SKIPIF-- --FILE-- getOpt(ZMQ::CTXOPT_MAX_SOCKETS) === ZMQ::CTXOPT_MAX_SOCKETS_DEFAULT); var_dump($context->setOpt(ZMQ::CTXOPT_MAX_SOCKETS, 512)); var_dump($context->getOpt(ZMQ::CTXOPT_MAX_SOCKETS)); echo "OK"; --EXPECT-- bool(true) NULL int(512) OKzmq-1.1.3/tests/033-disconnect.phpt0000644000076500000240000000131412653534763013751 0ustar --TEST-- Test disconnect --SKIPIF-- --FILE-- getendpoints(); var_dump($endpoints); foreach ($endpoints['connect'] as $dsn) { $c->disconnect($dsn); } var_dump ($c->getendpoints()); echo "OK"; --EXPECT-- array(2) { ["connect"]=> array(1) { [0]=> string(17) "inproc://php-test" } ["bind"]=> array(0) { } } array(2) { ["connect"]=> array(0) { } ["bind"]=> array(0) { } } OKzmq-1.1.3/tests/034-unbind.phpt0000644000076500000240000000124612653534763013104 0ustar --TEST-- Test unbind --SKIPIF-- --FILE-- getendpoints(); var_dump($endpoints); foreach ($endpoints['bind'] as $dsn) { $s->unbind($dsn); } var_dump ($s->getendpoints()); echo "OK"; --EXPECT-- array(2) { ["connect"]=> array(0) { } ["bind"]=> array(1) { [0]=> string(17) "inproc://php-test" } } array(2) { ["connect"]=> array(0) { } ["bind"]=> array(0) { } } OKzmq-1.1.3/tests/035-capture.phpt0000644000076500000240000000244512653534763013273 0ustar --TEST-- Test device capture --SKIPIF-- --FILE-- bind (ZEROMQ_TEST_DSN); $sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH); $sender->connect(ZEROMQ_TEST_DSN); $backend = new ZMQSocket($context, ZMQ::SOCKET_PUSH); $backend->bind (ZEROMQ_TEST_DSN2); $receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL); $receiver->connect(ZEROMQ_TEST_DSN2); $capture = new ZMQSocket($context, ZMQ::SOCKET_PUB); $capture->bind ('inproc://capture'); $capture_listener = new ZMQSocket($context, ZMQ::SOCKET_SUB); $capture_listener->connect ('inproc://capture'); $capture_listener->setSockOpt (ZMQ::SOCKOPT_SUBSCRIBE, ""); $device = new ZMQDevice($front, $backend, $capture); $device->setIdleCallback(function () { return false; }, 100, 'ddd'); $sender->sendmsg ("Hello backend"); $device->run (); $device->run (); echo "Receiving from receiver" . PHP_EOL; var_dump($receiver->recvmsg()); echo "Receiving from capture listener" . PHP_EOL; var_dump($capture_listener->recvmsg()); echo "OK"; ?> --EXPECT-- Receiving from receiver string(13) "Hello backend" Receiving from capture listener string(13) "Hello backend" OKzmq-1.1.3/tests/036-device.phpt0000644000076500000240000000437112653534763013070 0ustar --TEST-- Test device callbacks --SKIPIF-- --FILE-- name = $name; } public function getName () { return $this->name; } public function increment () { return ++$this->_counter; } public function getCount () { return $this->_counter; } public function reset () { $this->_counter = 0; } } class test { function foo ($user_data) { return false; } } $test = new test (); $ctx = new ZMQContext (); $device = new ZMQDevice($ctx->getSocket(ZMQ::SOCKET_SUB), $ctx->getSocket(ZMQ::SOCKET_PUB)); $last_called = proper_microtime (); $user_data = new CbStateData ('timer'); $orig_cb = function ($user_data) use (&$last_called, $device) { echo "Triggered for {$device->getTimerTimeout ()}ms timeout" . PHP_EOL; $time_elapsed = (proper_microtime () - $last_called) + 1; if ($time_elapsed < $device->getTimerTimeout ()) { echo "Called too early, only ${time_elapsed}ms elapsed, expected {$device->getTimerTimeout ()}" . PHP_EOL; } $device->setTimerTimeout ($device->getTimerTimeout () + 50); $last_called = proper_microtime (); echo "{$user_data->getName ()} function called {$user_data->increment ()} times\n"; return $user_data->getCount() < 3 ? true : false; }; // Setup callback and user data for callback $device->setTimerCallback ($orig_cb, 100, $user_data); // Run first time $device->run (); $device->setTimerCallback (array ($test, 'foo'), 100, $user_data); $device->setTimerCallback (array ($test, 'foo'), 100, $user_data); $device->setTimerCallback ($orig_cb, 100, $user_data); sleep (1); // Run second time $user_data->reset (); $device->setTimerTimeout (110); $device->run (); echo "OK"; ?> --EXPECT-- Triggered for 100ms timeout timer function called 1 times Triggered for 150ms timeout timer function called 2 times Triggered for 200ms timeout timer function called 3 times Triggered for 110ms timeout timer function called 1 times Triggered for 160ms timeout timer function called 2 times Triggered for 210ms timeout timer function called 3 times OKzmq-1.1.3/tests/037-device-deprecated.phpt0000644000076500000240000000123012653534763015156 0ustar --TEST-- Test device deprecated args --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_PUB)); // Setup callback and user data for callback $device->setIdleTimeout (100); $device->setIdleCallback (function ($user_data) { echo "Called: ${user_data}" . PHP_EOL; return false; }, "test"); // Run first time $device->run (); echo "OK"; ?> --EXPECTF-- Deprecated: ZMQDevice::setidlecallback(): The signature for setIdleCallback has changed, please update your code in %s on line %d Called: test OKzmq-1.1.3/tests/038-cert-construct.phpt0000644000076500000240000000075012653534763014607 0ustar --TEST-- Test a ZMQCert can be constructed. --SKIPIF-- getMessage()); } --EXPECT-- bool(true) string(69) "ZMQCert::__construct() expects parameter 1 to be string, object given" zmq-1.1.3/tests/039-cert-equals.phpt0000644000076500000240000000073312653534763014057 0ustar --TEST-- Test two ZMQCerts can be tested for equality. --SKIPIF-- getPublicTxt() === str_repeat("0", 40)) { // This means no curve die("skip No curve enabled in libczmq"); } --FILE-- equals($cert)); var_dump($newCert->equals($cert)); --EXPECT-- bool(true) bool(false) zmq-1.1.3/tests/040-cert-clone.phpt0000644000076500000240000000041412653534763013651 0ustar --TEST-- Test a ZMQCert can be cloned. --SKIPIF-- equals($clonedCert)); --EXPECT-- bool(true) zmq-1.1.3/tests/041-cert-meta.phpt0000644000076500000240000000132712653534763013504 0ustar --TEST-- Test a ZMQCert can get and set metadata. --SKIPIF-- getMeta('foo')); var_dump($cert->getMetaKeys()); $cert->setMeta('foo', 'bar'); var_dump($cert->getMeta('foo')); var_dump($cert->getMetaKeys()); $cert->setMeta('baz', 'qux'); var_dump($cert->getMetaKeys()); // This should generate an error var_dump($cert->getMetaKeys(123)); --EXPECTF-- NULL array(0) { } string(3) "bar" array(1) { [0]=> string(3) "foo" } array(2) { [0]=> string(3) "baz" [1]=> string(3) "foo" } Warning: ZMQCert::getMetaKeys() expects exactly 0 parameters, 1 given in %s on line %d NULL zmq-1.1.3/tests/042-cert-save.phpt0000644000076500000240000000146712653534763013522 0ustar --TEST-- Test a ZMQCert can be saved. --SKIPIF-- save($certPath); var_dump(is_file($certPath)); var_dump(is_file($certPath . '_secret')); unlink($certPath); unlink($certPath . '_secret'); // #savePublic $certPath = BASE_CERT_DIR . '/cert_public'; $cert = new ZMQCert(); $cert->savePublic($certPath); var_dump(is_file($certPath)); unlink($certPath); // #saveSecret $certPath = BASE_CERT_DIR . '/cert_secret'; $cert->saveSecret($certPath); var_dump(is_file($certPath)); unlink($certPath); rmdir(BASE_CERT_DIR); --EXPECT-- bool(true) bool(true) bool(true) bool(true) zmq-1.1.3/tests/043-cert-load.phpt0000644000076500000240000000123012653534763013470 0ustar --TEST-- Test a ZMQCert can be loaded. --SKIPIF-- save($certPath); $certCloneEquivalent = new ZMQCert($certPath); var_dump($certCloneEquivalent->equals($cert)); unlink($certPath); unlink($certPath . '_secret'); try { new ZMQCert('/path/to/cert'); } catch (ZMQCertException $e) { var_dump($e->getMessage()); } rmdir(BASE_CERT_DIR); --EXPECT-- bool(true) string(49) "Failed to load the certificate from /path/to/cert" zmq-1.1.3/tests/044-auth-construct.phpt0000644000076500000240000000041212653534763014603 0ustar --TEST-- Test a ZMQAuth can be constructed. --SKIPIF-- allow('127.0.0.1') === $auth); var_dump($auth->deny('192.168.0.1') === $auth); --EXPECT-- bool(true) bool(true) zmq-1.1.3/tests/046-cert-apply.phpt0000644000076500000240000000046312653534763013710 0ustar --TEST-- Test a ZMQCert can be applied to a ZMQSocket. --SKIPIF-- getSocket(ZMQ::SOCKET_REQ); $cert = new ZMQCert(); $cert->apply($socket); --EXPECT-- zmq-1.1.3/tests/047-auth-configure.phpt0000644000076500000240000000237712653534763014557 0ustar --TEST-- Test a ZMQAuth can be configured. --SKIPIF-- configure(ZMQAuth::AUTH_TYPE_PLAIN, '*', PASSWORDS_FILE) === $auth); unlink(PASSWORDS_FILE); // Test a ZMQAuth can be configured to use CURVE authentication. $cert = new ZMQCert(); $cert->save(CERT_FILE); var_dump($auth->configure(ZMQAuth::AUTH_TYPE_CURVE, '*', CERTS_DIR) === $auth); // Test ZMQAuth#configure throws an exception when the auth type isn't // recognised. try { $auth->configure(-1, '*', CERTS_DIR); } catch (ZMQAuthException $e) { var_dump($e->getMessage()); } unlink(CERT_FILE); unlink(CERT_FILE . '_secret'); rmdir(CERTS_DIR); rmdir(TEST_DIR); --EXPECT-- bool(true) bool(true) string(62) "Unknown auth type. Are you using one of the ZMQAuth constants?" zmq-1.1.3/tests/048-pollsetitems.phpt0000644000076500000240000000223312653534763014353 0ustar --TEST-- Test pollset items --SKIPIF-- --FILE-- add(create_client(), ZMQ::POLL_IN); $poll->add($stream, ZMQ::POLL_IN); $poll->add(create_client(), ZMQ::POLL_IN); foreach ($poll->items() as $item) { unset($item); } var_dump($poll->items()); var_dump($poll->clear()->items()); echo "OK"; --EXPECTF-- array(3) { ["o:%s"]=> object(ZMQSocket)#%d (%d) { } ["r:%d"]=> resource(%d) of type (stream) ["o:%s"]=> object(ZMQSocket)#%d (%d) { } } array(0) { } OKzmq-1.1.3/tests/049-events.phpt0000644000076500000240000000217112653534763013135 0ustar --TEST-- Test events --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_DEALER); $client->monitor("inproc://socket-monitor"); $monitor = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_PAIR); $monitor->connect("inproc://socket-monitor"); $server = $context->getSocket(ZMQ::SOCKET_DEALER); $server->bind("tcp://*:5050"); $client->connect("tcp://127.0.0.1:5050"); $event = $monitor->recvEvent(); var_dump ($event, $event["event"] == ZMQ::EVENT_CONNECT_DELAYED); $event = $monitor->recvEvent(); var_dump ($event, $event["event"] == ZMQ::EVENT_CONNECTED); echo "OK"; --EXPECTF-- array(3) { ["event"]=> int(2) ["value"]=> int(%d) ["address"]=> string(20) "tcp://127.0.0.1:5050" } bool(true) array(3) { ["event"]=> int(1) ["value"]=> int(%d) ["address"]=> string(20) "tcp://127.0.0.1:5050" } bool(true) OKzmq-1.1.3/tests/050-sharedcontext.phpt0000644000076500000240000000127312653534763014476 0ustar --TEST-- Test shared context --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REQ, 'persistent id'); $dsn = uniqid("inproc://shared-ctx-"); $socket1->bind ($dsn); $socket2->connect ($dsn); $socket2->send("hello"); var_dump($socket1->recv()); var_dump ($context->isPersistent()); var_dump ($context->getSocketCount()); echo "OK"; --EXPECT-- string(5) "hello" bool(true) int(2) OKzmq-1.1.3/tests/051-socketcount.phpt0000644000076500000240000000265112653534763014166 0ustar --TEST-- Test socket count variations --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_REQ, 'persistent id'); var_dump ($context->getSocketCount()); unset($socket1); var_dump ($context->getSocketCount()); unset($socket2); var_dump ($context->getSocketCount()); $context = new ZMQContext(7, true); $socket1 = new ZMQSocket($context, ZMQ::SOCKET_REP); $socket2 = $context->getSocket(ZMQ::SOCKET_REQ, 'persistent id'); var_dump ($context->getSocketCount()); unset($socket1); var_dump ($context->getSocketCount()); // Persistent socket should stay in count unset($socket2); var_dump ($context->getSocketCount()); $context = ZMQContext::acquire(); $socket1 = new ZMQSocket($context, ZMQ::SOCKET_REP); $socket2 = $context->getSocket(ZMQ::SOCKET_REQ, 'persistent id'); var_dump ($context->getSocketCount()); unset($socket1); var_dump ($context->getSocketCount()); // Persistent socket should stay in count unset($socket2); var_dump ($context->getSocketCount()); echo "OK"; --EXPECT-- int(2) int(1) int(0) int(2) int(1) int(1) int(2) int(1) int(1) OKzmq-1.1.3/tests/052-pthreads.phpt0000644000076500000240000000233112653534763013433 0ustar --TEST-- Test pthreads integration --SKIPIF-- --FILE-- sendThisBack = $sendThisBack; } public function run() { $context = ZMQContext::acquire(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH); $socket->connect ("inproc://pthreads-test"); $socket->send($this->sendThisBack); sleep(2); } } $context = ZMQContext::acquire(); $socket = $context->getSocket(ZMQ::SOCKET_PULL); $socket->bind("inproc://pthreads-test"); $socket->setSockOpt(ZMQ::SOCKOPT_HWM, 1000); $request = array(); for ($i = 0; $i < $threads; $i++) { $requests[$i] = new MyWorker("thr_$i"); $requests[$i]->start(); } var_dump($context->getSocketCount()); for ($i = 0; $i < $threads; $i++) { $requests[$i]->join(); } for ($i = 0; $i < $threads; $i++) { $socket->recv(); } echo "OK"; --EXPECT-- int(11) OKzmq-1.1.3/tests/053-z85.phpt0000644000076500000240000000241712653534763012255 0ustar --TEST-- Test z85 --SKIPIF-- --FILE-- --FILE-- getSocket(\ZMQ::SOCKET_ROUTER); $socket->setSockOpt(\ZMQ::SOCKOPT_ROUTER_MANDATORY, 1); echo "OK"; --EXPECT-- OK zmq-1.1.3/tests/bug_gh_43.phpt0000644000076500000240000000071512653534763013062 0ustar --TEST-- Test for Github issue #43 --SKIPIF-- --FILE-- --EXPECTF-- Warning: ZMQDevice::__construct() expects at most 3 parameters, 4 given in %s/bug_gh_43.php on line %d OKzmq-1.1.3/tests/bug_gh_49.phpt0000644000076500000240000000234112653534763013065 0ustar --TEST-- Test for Github issue #49 --SKIPIF-- --FILE-- bind ('inproc://test'); $client = new ZMQSocket ($context, ZMQ::SOCKET_REQ); $client->connect ('inproc://test'); $poll = new ZMQPoll(); $poll->add ($server, ZMQ::POLL_IN); $poll->add ($client, ZMQ::POLL_IN); for ($i = 0; $i < 10; $i++) { $readable = array(); $writable = array(); if ($i % 2) { $server->send ($i); } else { $client->send ($i); } $event = $poll->poll ($readable, $writable); if (!$event) { continue; } foreach ($readable as $socket) { $msg = $socket->recv(); if ($socket === $server) { echo 'client to server msg:' . $msg . PHP_EOL; } else { echo 'server to client msg:' . $msg . PHP_EOL; } } } ?> --EXPECT-- client to server msg:0 server to client msg:1 client to server msg:2 server to client msg:3 client to server msg:4 server to client msg:5 client to server msg:6 server to client msg:7 client to server msg:8 server to client msg:9zmq-1.1.3/tests/bug_gh_50.phpt0000644000076500000240000000232112653534763013053 0ustar --TEST-- Test for Github issue #50 --SKIPIF-- --FILE-- bind ('inproc://test'); $client = new ZMQSocket ($context, ZMQ::SOCKET_SUB); $client->setsockopt (ZMQ::SOCKOPT_SUBSCRIBE, ""); $client->connect ('inproc://test'); $client2 = new ZMQSocket ($context, ZMQ::SOCKET_SUB); $client2->setsockopt (ZMQ::SOCKOPT_SUBSCRIBE, ""); $client2->connect ('inproc://test'); $poll = new ZMQPoll (); $poll->add ($client, ZMQ::POLL_IN); $poll->add ($client2, ZMQ::POLL_IN); $readable = array(); $writable = array(); $server->send ("Hello all"); $res = $poll->poll ($readable, $writable, 1000); var_dump ($poll->count () == $res, $readable, $writable); foreach ($readable as $r) $r->recv (); $poll->remove ($client2); $server->send ("Hello all"); $res = $poll->poll ($readable, $writable, 1000); var_dump ($poll->count () == $res, $readable, $writable); ?> --EXPECT-- bool(true) array(2) { [0]=> object(ZMQSocket)#3 (0) { } [1]=> object(ZMQSocket)#4 (0) { } } array(0) { } bool(true) array(1) { [0]=> object(ZMQSocket)#3 (0) { } } array(0) { }zmq-1.1.3/tests/bug_gh_59_2.phpt0000644000076500000240000000172612653534763013315 0ustar --TEST-- Test for Github issue #59 --SKIPIF-- --FILE-- getSocket(\ZMQ::SOCKET_REP); $rep->connect('ipc://test2.ipc'); $msg = $rep->recv(); $rep->send($msg.'bar'); sleep(2); exit; } $context = new ZMQContext(1, false); $dealer = $context->getSocket(ZMQ::SOCKET_DEALER); $pids[] = forkRepWorker($dealer); $pids[] = forkRepWorker($dealer); $dealer->bind('ipc://test2.ipc'); sleep (1); $dealer->sendmulti(array('A', '', 'foo')); $dealer->sendmulti(array('B', '', 'bar')); $msgs = array(); $msgs[] = $dealer->recvmulti(); $msgs[] = $dealer->recvmulti(); foreach ($pids as $pid) { pcntl_waitpid($pid, $status, WUNTRACED); } var_dump(count ($msgs)); echo "OK"; --EXPECT-- int(2) OKzmq-1.1.3/tests/bug_gh_59.phpt0000644000076500000240000000101012653534763013056 0ustar --TEST-- Test for Github issue #59 --SKIPIF-- --FILE-- --FILE-- bind ('inproc://test'); $fd = $server->getSockOpt(ZMQ::SOCKOPT_FD); $read = array($fd); $write = NULL; $except = NULL; stream_select($read, $write, $except, 0); echo "OK"; ?> --EXPECT-- OK zmq-1.1.3/tests/rose.jpg0000644000076500000240000000305412653534763012075 0ustar ÿØÿàJFIFHHÿÛC  !"$"$ÿÛCÿÀ.F"ÿÄÿÄ3!1QAa"‘±#2Rq¡ÁBáñÿÄÿÄ*!1AQaq‘±2ðÑÿÚ ?rTº‚@Ê^̇勺8åŠc éµ¶8$Õp¦LÃMRæù&d%–XVF¦•7$ìF%"LÊ‚D±{D‰ 50&¥3¢–@ÑiÌå骒2lØœJ‹Iæ¶– ¯ ‰án^YnYÏ Þ-¨èÌQ$ˆÂ'*‹ ÷'½ÎÖMD\kõ XXóDäFà‘¿m¾aœÏ0HÎPGCÔbF™¢–³5ŽA„sÜâÜ£¾$¤qødR ÷]Áï¾$™eŽ‹™–.ŽEÍ…­~ýp-'KZªpª·´Ö˜=/mü^ü.#Ä3W’fÔÇ“Q<†Ò[¥ûãïdjs­$t²@üä µ…Î y3-llFpŸ™y‰ôèqºàÞ”Ò•zÖ³/Ìò•ûEe'%Õ#ÙöÂá—ùïƒTõ%‚å߇ˆLŽ4ø}9¨YáüXëä߬ 5>KG‘e0ÁsU˜Dj EhÕUA;üp±ÒúÓ„ºPKOPœº*tÛÂÏì[ùÂÅŒÎMÉÖº‹xãt…å‘T';1°\œôVO¨êòØ\UIOO”ÂIðì<ÈíÛõ”õ ` JHee[ïlkµ|T¹T¹F[[(FR‹’ªGê=ðBŽZ%;Ì÷lÛséiYªr‚¾»E%x¨QÅf½‹v2mõÃ1B¯1ðÛwUs¹ô¿ÓŠööesEÏ(pË+›´c¯º}~X€¥ ¹¤ôÿ˜L›ûåÞÑÚèªK¢Ou±`¶‹gLÊ´éN~Únáe`±…·[ùâ9FIF話•CqûcÒȈç©o ‚çaÐ÷3ìmaæqãvE¸ÎÍÜróš'Áƒ?~ñ8pÛ‹ª–C‹9©«iu6a6[^ÔR‚2ñª™,ö%nA°Ùq’Ê+©ê*)ãñ§Ç C«’7Añ8§[,¢‘)j+[0ÔUµ$ÎÐËÍ _QUG5#QÖ +*H…] ¼ÁÜc²t®_CRg1RƕـQ5½çì ì1]Ä-§u:GšÓ´U`†² ,©èOù/¡¿ÃfЗxkÃ}S6@ªFeàxï˜ágžU’âF ~øf³1žqø’3•é|xÝÃáåEó•Ì¡¯2r^ŸÂhùm×Þ õôéÝ Ó©[·iý;tõëŠý¥Q¬S7 ¶V6=õ‡“9¥ ÊÒ"¦IäRZ+ ¯ÞýñLÖ½¹lÑFˆ0QE‚µ¿ž¸ƒžFõEDÏv•Ëmä<‡ÀXb§šC-·ó$}1µd©Ks…ª¹í=ó7h/fyÄ/w(…‘.vóßã…¾dÕ~βH,’†¸&ÿ—¥üð±™(ÖÛÀÁ$GÿÙzmq-1.1.3/tests/skipif.inc0000644000076500000240000000012212653534763012374 0ustar zmq-1.1.3/tests/skipif-czmq2.inc0000644000076500000240000000025412653534763013434 0ustar zmq-1.1.3/tests/skipif-libzmq2.inc0000644000076500000240000000023212653534763013754 0ustar zmq-1.1.3/tests/skipif-libzmq3.inc0000644000076500000240000000023212653534763013755 0ustar zmq-1.1.3/tests/skipif-libzmq4.inc0000644000076500000240000000023212653534763013756 0ustar zmq-1.1.3/tests/libzmq2-sockopt.phpt0000644000076500000240000003017712653534763014366 0ustar --TEST-- Test setting socket options --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_HWM, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_HWM); if ($socket->getSockOpt(ZMQ::SOCKOPT_HWM) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_HWM: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_SWAP")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SWAP, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SWAP); if ($socket->getSockOpt(ZMQ::SOCKOPT_SWAP) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SWAP: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=uint64 php_type=int */ if (defined ("ZMQ::SOCKOPT_AFFINITY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_AFFINITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_AFFINITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_IDENTITY")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IDENTITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_RATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RATE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RATE); if ($socket->getSockOpt(ZMQ::SOCKOPT_RATE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RATE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_RECOVERY_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECOVERY_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_RECOVERY_IVL_MSEC")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL_MSEC, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL_MSEC); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL_MSEC) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECOVERY_IVL_MSEC: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_MCAST_LOOP")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_MCAST_LOOP, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MCAST_LOOP); if ($socket->getSockOpt(ZMQ::SOCKOPT_MCAST_LOOP) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_MCAST_LOOP: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=uint64 php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=uint64 php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_LINGER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_LINGER, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_LINGER); if ($socket->getSockOpt(ZMQ::SOCKOPT_LINGER) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_LINGER: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL_MAX")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL_MAX: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_BACKLOG")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_BACKLOG, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG); if ($socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_BACKLOG: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_SUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_SUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_SUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_UNSUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_UNSUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TYPE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TYPE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_TYPE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_TYPE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_TYPE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVMORE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_RCVMORE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_RCVMORE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_RCVMORE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=socket php_type=resource */ if (defined ("ZMQ::SOCKOPT_FD")) { $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_FD); if (is_resource($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_FD: expected=[resource] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_FD, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_FD" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=uint32 php_type=int */ if (defined ("ZMQ::SOCKOPT_EVENTS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_EVENTS); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_EVENTS: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_EVENTS, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_EVENTS" . PHP_EOL; } catch (ZMQSocketException $e) {} } if ($tested == 0) { echo "Did not test any constants" . PHP_EOL; } echo "OK"; --EXPECT-- OK zmq-1.1.3/tests/libzmq3-sockopt.phpt0000644000076500000240000004177112653534763014371 0ustar --TEST-- Test setting socket options --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_ROUTER); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_ROUTER_RAW, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_ROUTER_RAW); echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_RAW" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_IPV4ONLY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IPV4ONLY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IPV4ONLY); if ($socket->getSockOpt(ZMQ::SOCKOPT_IPV4ONLY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IPV4ONLY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TYPE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TYPE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_TYPE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_TYPE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_TYPE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDHWM")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDHWM, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDHWM); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDHWM) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDHWM: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVHWM")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVHWM, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVHWM); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVHWM) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVHWM: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=uint64 php_type=int */ if (defined ("ZMQ::SOCKOPT_AFFINITY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_AFFINITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_AFFINITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_SUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_SUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_SUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_UNSUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_UNSUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_IDENTITY")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IDENTITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RATE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RATE); if ($socket->getSockOpt(ZMQ::SOCKOPT_RATE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RATE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECOVERY_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECOVERY_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_LINGER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_LINGER, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_LINGER); if ($socket->getSockOpt(ZMQ::SOCKOPT_LINGER) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_LINGER: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL_MAX")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL_MAX: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_BACKLOG")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_BACKLOG, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG); if ($socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_BACKLOG: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_MAXMSGSIZE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE); if ($socket->getSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_MAXMSGSIZE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_MULTICAST_HOPS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS); if ($socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_MULTICAST_HOPS: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_XPUB_VERBOSE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSE); echo "Should not be able to get ZMQ::SOCKOPT_XPUB_VERBOSE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_TCP_ACCEPT_FILTER")) { $test_value = "127.0.0.1"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_TCP_ACCEPT_FILTER, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_TCP_ACCEPT_FILTER); echo "Should not be able to get ZMQ::SOCKOPT_TCP_ACCEPT_FILTER" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVMORE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_RCVMORE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_RCVMORE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_RCVMORE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=socket php_type=resource */ if (defined ("ZMQ::SOCKOPT_FD")) { $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_FD); if (is_resource($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_FD: expected=[resource] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_FD, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_FD" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_EVENTS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_EVENTS); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_EVENTS: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_EVENTS, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_EVENTS" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_LAST_ENDPOINT")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_LAST_ENDPOINT); if (is_string($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_LAST_ENDPOINT: expected=[string] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_LAST_ENDPOINT, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_LAST_ENDPOINT" . PHP_EOL; } catch (ZMQSocketException $e) {} } if ($tested == 0) { echo "Did not test any constants" . PHP_EOL; } echo "OK"; --EXPECT-- OK zmq-1.1.3/tests/libzmq4-sockopt.phpt0000644000076500000240000006357012653534763014373 0ustar --TEST-- Test setting socket options --SKIPIF-- --FILE-- getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_HEARTBEAT_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_HEARTBEAT_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_HEARTBEAT_TTL")) { $test_value = 4000; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TTL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TTL); if ($socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TTL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_HEARTBEAT_TTL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT")) { $test_value = 6000; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT); if ($socket->getSockOpt(ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TOS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TOS, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TOS); if ($socket->getSockOpt(ZMQ::SOCKOPT_TOS) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TOS: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_ROUTER_HANDOVER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_ROUTER); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_ROUTER_HANDOVER, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_ROUTER_HANDOVER); echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_HANDOVER" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_ROUTER_MANDATORY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_ROUTER); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_ROUTER_MANDATORY, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_ROUTER_MANDATORY); echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_MANDATORY" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_PROBE_ROUTER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_PROBE_ROUTER, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_PROBE_ROUTER); echo "Should not be able to get ZMQ::SOCKOPT_PROBE_ROUTER" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_REQ_RELAXED")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_REQ); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_REQ_RELAXED, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_REQ_RELAXED); echo "Should not be able to get ZMQ::SOCKOPT_REQ_RELAXED" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_REQ_CORRELATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_REQ); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_REQ_CORRELATE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_REQ_CORRELATE); echo "Should not be able to get ZMQ::SOCKOPT_REQ_CORRELATE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_CONFLATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUSH); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_CONFLATE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_CONFLATE); echo "Should not be able to get ZMQ::SOCKOPT_CONFLATE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_ZAP_DOMAIN")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_ZAP_DOMAIN, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_ZAP_DOMAIN); if ($socket->getSockOpt(ZMQ::SOCKOPT_ZAP_DOMAIN) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_ZAP_DOMAIN: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_MECHANISM")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MECHANISM); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_MECHANISM: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_MECHANISM, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_MECHANISM" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_PLAIN_SERVER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_PLAIN_SERVER, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_SERVER); if ($socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_SERVER) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_PLAIN_SERVER: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_PLAIN_USERNAME")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_PLAIN_USERNAME, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_USERNAME); if ($socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_USERNAME) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_PLAIN_USERNAME: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_PLAIN_PASSWORD")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_PLAIN_PASSWORD, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_PASSWORD); if ($socket->getSockOpt(ZMQ::SOCKOPT_PLAIN_PASSWORD) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_PLAIN_PASSWORD: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_IPV6")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IPV6, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IPV6); if ($socket->getSockOpt(ZMQ::SOCKOPT_IPV6) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IPV6: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_IMMEDIATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IMMEDIATE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IMMEDIATE); if ($socket->getSockOpt(ZMQ::SOCKOPT_IMMEDIATE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IMMEDIATE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_ROUTER_RAW")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_ROUTER); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_ROUTER_RAW, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_ROUTER_RAW); echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_RAW" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_IPV4ONLY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IPV4ONLY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IPV4ONLY); if ($socket->getSockOpt(ZMQ::SOCKOPT_IPV4ONLY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IPV4ONLY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TYPE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TYPE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_TYPE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_TYPE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_TYPE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDHWM")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDHWM, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDHWM); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDHWM) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDHWM: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVHWM")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVHWM, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVHWM); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVHWM) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVHWM: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=uint64 php_type=int */ if (defined ("ZMQ::SOCKOPT_AFFINITY")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_AFFINITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_AFFINITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_AFFINITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_SUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_SUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_SUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_UNSUBSCRIBE")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_UNSUBSCRIBE); echo "Should not be able to get ZMQ::SOCKOPT_UNSUBSCRIBE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_IDENTITY")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY); if ($socket->getSockOpt(ZMQ::SOCKOPT_IDENTITY) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_IDENTITY: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RATE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RATE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RATE); if ($socket->getSockOpt(ZMQ::SOCKOPT_RATE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RATE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECOVERY_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECOVERY_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECOVERY_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_PUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVBUF")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVBUF, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVBUF) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVBUF: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_LINGER")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_LINGER, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_LINGER); if ($socket->getSockOpt(ZMQ::SOCKOPT_LINGER) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_LINGER: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RECONNECT_IVL_MAX")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX); if ($socket->getSockOpt(ZMQ::SOCKOPT_RECONNECT_IVL_MAX) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RECONNECT_IVL_MAX: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_BACKLOG")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_BACKLOG, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG); if ($socket->getSockOpt(ZMQ::SOCKOPT_BACKLOG) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_BACKLOG: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int64 php_type=int */ if (defined ("ZMQ::SOCKOPT_MAXMSGSIZE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE); if ($socket->getSockOpt(ZMQ::SOCKOPT_MAXMSGSIZE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_MAXMSGSIZE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_MULTICAST_HOPS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS); if ($socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_HOPS) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_MULTICAST_HOPS: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_RCVTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_RCVTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_SNDTIMEO")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_SNDTIMEO, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO); if ($socket->getSockOpt(ZMQ::SOCKOPT_SNDTIMEO) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_SNDTIMEO: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_XPUB_VERBOSE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSE, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSE); echo "Should not be able to get ZMQ::SOCKOPT_XPUB_VERBOSE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="rw" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-write $socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL, $test_value); $retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL); if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL) !== $test_value) { echo "Failed to set ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL: expected=[$test_value] actual=[$retval]" . PHP_EOL; } $tested++; } /* socket option is marked mode="w" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_TCP_ACCEPT_FILTER")) { $test_value = "127.0.0.1"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test write-only $socket->setSockOpt(ZMQ::SOCKOPT_TCP_ACCEPT_FILTER, $test_value); $tested++; try { $socket->getSockOpt(ZMQ::SOCKOPT_TCP_ACCEPT_FILTER); echo "Should not be able to get ZMQ::SOCKOPT_TCP_ACCEPT_FILTER" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_RCVMORE")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_RCVMORE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_RCVMORE, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_RCVMORE" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=socket php_type=resource */ if (defined ("ZMQ::SOCKOPT_FD")) { $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_FD); if (is_resource($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_FD: expected=[resource] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_FD, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_FD" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=int php_type=int */ if (defined ("ZMQ::SOCKOPT_EVENTS")) { $test_value = 1; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_EVENTS); if (is_int($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_EVENTS: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_EVENTS, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_EVENTS" . PHP_EOL; } catch (ZMQSocketException $e) {} } /* socket option is marked mode="r" type=string php_type=string */ if (defined ("ZMQ::SOCKOPT_LAST_ENDPOINT")) { $test_value = "test"; $socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_SUB); // Test read-only $retval = $socket->getSockOpt(ZMQ::SOCKOPT_LAST_ENDPOINT); if (is_string($retval) === false) { echo "Incorrect return type for ZMQ::SOCKOPT_LAST_ENDPOINT: expected=[string] actual=[" .gettype($retval). "]" . PHP_EOL; } $tested++; try { $socket->setSockOpt(ZMQ::SOCKOPT_LAST_ENDPOINT, 'x'); echo "Should not be able to set ZMQ::SOCKOPT_LAST_ENDPOINT" . PHP_EOL; } catch (ZMQSocketException $e) {} } if ($tested == 0) { echo "Did not test any constants" . PHP_EOL; } echo "OK"; --EXPECT-- OK zmq-1.1.3/tests/zeromq_test_helper.inc0000644000076500000240000000130112653534763015022 0ustar getSocket(ZMQ::SOCKET_REP, $persistent_id) ->bind(ZEROMQ_TEST_DSN); return $server; } function create_client($persistent_id = null) { $context = new ZMQContext(); $client = $context->getSocket(ZMQ::SOCKET_REQ, $persistent_id) ->connect(ZEROMQ_TEST_DSN); return $client; } function bind_callback(ZMQSocket $socket, $persistent_id = null) { static $port = 5566; $socket->bind(ZEROMQ_TEST_DSN . "-{$port}"); $port++; }zmq-1.1.3/config.m40000644000076500000240000001202312653534763010764 0ustar PHP_ARG_WITH(zmq, whether to enable 0MQ support, [ --with-zmq[=DIR] Enable 0MQ support. DIR is the prefix to libzmq installation directory.], yes) PHP_ARG_WITH(czmq, whether to enable CZMQ support, [ --with-czmq[=DIR] Enable CZMQ support. DIR is the prefix to CZMQ installation directory.], no, no) if test "$PHP_ZMQ" != "no"; then AC_PATH_PROG(PKG_CONFIG, pkg-config, no) if test "x$PKG_CONFIG" = "xno"; then AC_MSG_RESULT([pkg-config not found]) AC_MSG_ERROR([Please reinstall the pkg-config distribution]) fi ORIG_PKG_CONFIG_PATH=$PKG_CONFIG_PATH PHP_ZMQ_EXPLICIT_PKG_CONFIG_PATH="" AC_MSG_CHECKING(libzmq installation) if test "x$PHP_ZMQ" = "xyes"; then if test "x${PKG_CONFIG_PATH}" = "x"; then # # "By default, pkg-config looks in the directory prefix/lib/pkgconfig for these files" # # Add a bit more search paths for common installation locations. Can be overridden by setting # PKG_CONFIG_PATH env variable or passing --with-zmq=PATH # export PKG_CONFIG_PATH="/usr/local/${PHP_LIBDIR}/pkgconfig:/usr/${PHP_LIBDIR}/pkgconfig:/opt/${PHP_LIBDIR}/pkgconfig:/opt/local/${PHP_LIBDIR}/pkgconfig" fi else export PKG_CONFIG_PATH="${PHP_ZMQ}/${PHP_LIBDIR}/pkgconfig" export PHP_ZMQ_EXPLICIT_PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" fi if $PKG_CONFIG --exists libzmq; then PHP_ZMQ_VERSION=`$PKG_CONFIG libzmq --modversion` PHP_ZMQ_PREFIX=`$PKG_CONFIG libzmq --variable=prefix` AC_MSG_RESULT([found version $PHP_ZMQ_VERSION, under $PHP_ZMQ_PREFIX]) PHP_ZMQ_LIBS=`$PKG_CONFIG libzmq --libs` PHP_ZMQ_CFLAGS=`$PKG_CONFIG libzmq --cflags` PHP_EVAL_LIBLINE($PHP_ZMQ_LIBS, ZMQ_SHARED_LIBADD) PHP_EVAL_INCLINE($PHP_ZMQ_CFLAGS) else AC_MSG_ERROR(Unable to find libzmq installation) fi # Test functions ORIG_CFLAGS="$CFLAGS" ORIG_LDFLAGS="$LDFLAGS" CFLAGS="$CFLAGS $PHP_ZMQ_CFLAGS" LDFLAGS="$LDFLAGS $PHP_ZMQ_LIBS" $PKG_CONFIG libzmq --atleast-version 4.0.0 if test $? = 0; then AC_CHECK_LIB( [zmq], [zmq_socket_monitor], [AC_DEFINE( [PHP_ZMQ_HAVE_SOCKET_MONITOR], [1], [Whether zmq_socket_monitor function is available] )] ) fi AC_CHECK_LIB( [zmq], [zmq_proxy_steerable], [AC_DEFINE( [PHP_ZMQ_HAVE_PROXY_STEERABLE], [1], [Whether zmq_proxy_steerable function is available] )] ) AC_CHECK_LIB( [zmq], [zmq_z85_decode], [AC_DEFINE( [PHP_ZMQ_HAVE_Z85], [1], [Whether zmq_z85_decode function is available] )] ) AC_CHECK_LIB( [zmq], [zmq_curve_keypair], [AC_DEFINE( [PHP_ZMQ_HAVE_CURVE_KEYPAIR], [1], [Whether zmq_curve_keypair function is available] )] ) AC_CHECK_LIB( [zmq], [zmq_ctx_get], [AC_DEFINE( [PHP_ZMQ_HAVE_CTX_OPTIONS], [1], [Whether zmq_ctx_get/set is available] )] ) AC_CHECK_LIB( [zmq], [zmq_unbind], [AC_DEFINE( [PHP_ZMQ_HAVE_UNBIND], [1], [Whether zmq_unbind function is available] )] ) AC_CHECK_LIB( [zmq], [zmq_disconnect], [AC_DEFINE( [PHP_ZMQ_HAVE_DISCONNECT], [1], [Whether zmq_disconnect function is available] )] ) CFLAGS="$ORIG_CFLAGS" LDFLAGS="$ORIG_LDFLAGS" if test "$PHP_CZMQ" != "no"; then if test "x$PHP_CZMQ" != "xyes"; then export PKG_CONFIG_PATH="${PHP_CZMQ}/${PHP_LIBDIR}/pkgconfig:${PHP_ZMQ_EXPLICIT_PKG_CONFIG_PATH}" fi AC_MSG_CHECKING(for czmq) if $PKG_CONFIG --exists libczmq; then AC_MSG_RESULT([yes]) AC_MSG_CHECKING([czmq version is below 3.0.0]) if $PKG_CONFIG libczmq --max-version=3.0.0; then AC_MSG_RESULT([ok]) else AC_MSG_ERROR([Only czmq 2.x is supported at the moment]) fi PHP_CZMQ_VERSION=`$PKG_CONFIG libczmq --modversion` PHP_CZMQ_PREFIX=`$PKG_CONFIG libczmq --variable=prefix` AC_MSG_RESULT([found version $PHP_CZMQ_VERSION in $PHP_CZMQ_PREFIX]) PHP_CZMQ_LIBS=`$PKG_CONFIG libczmq --libs` PHP_CZMQ_INCS=`$PKG_CONFIG libczmq --cflags` PHP_EVAL_LIBLINE($PHP_CZMQ_LIBS, ZMQ_SHARED_LIBADD) PHP_EVAL_INCLINE($PHP_CZMQ_INCS) AC_DEFINE([HAVE_CZMQ], [], [czmq was found]) AC_DEFINE([HAVE_CZMQ_2], [], [czmq was found]) else AC_MSG_RESULT([no]) fi fi AC_CHECK_HEADERS([stdint.h],[php_zmq_have_stdint=yes; break;]) if test $php_zmq_have_stdint != "yes"; then AC_MSG_ERROR(Unable to find stdint.h) fi AC_CHECK_HEADERS(time.h sys/time.h mach/mach_time.h) AC_SEARCH_LIBS(clock_gettime, rt) AC_CHECK_FUNCS(clock_gettime gettimeofday mach_absolute_time) PHP_SUBST(ZMQ_SHARED_LIBADD) PHP_ZMQ_VERNUM=`${PHP_CONFIG} --vernum` if test "$PHP_ZMQ_VERNUM" -lt "70000"; then subdir="php5" PHP_ADD_BUILD_DIR($abs_builddir/$subdir, 1) PHP_NEW_EXTENSION(zmq, $subdir/zmq.c $subdir/zmq_pollset.c $subdir/zmq_device.c $subdir/zmq_sockopt.c $subdir/zmq_fd_stream.c $subdir/zmq_clock.c, $ext_shared) else PHP_NEW_EXTENSION(zmq, zmq.c zmq_helpers.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c zmq_shared_ctx.c, $ext_shared) fi PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH" fi zmq-1.1.3/config.w320000644000076500000240000000141012653534763011055 0ustar ARG_WITH("zmq", "0MQ support", "no"); if (PHP_ZMQ != "no") { if (CHECK_HEADER_ADD_INCLUDE("zmq.h", "CFLAGS_ZMQ", PHP_PHP_BUILD + "\\include;" + PHP_ZMQ) && CHECK_LIB("libzmq.lib", "zmq", PHP_PHP_BUILD + "\\lib;" + PHP_ZMQ)) { EXTENSION('zmq', 'zmq.c zmq_helpers.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c zmq_shared_ctx.c'); AC_DEFINE('HAVE_ZMQ', 1); AC_DEFINE('PHP_ZMQ_HAVE_SOCKET_MONITOR', 1); AC_DEFINE('PHP_ZMQ_HAVE_PROXY_STEERABLE', 1); AC_DEFINE('PHP_ZMQ_HAVE_Z85', 1); AC_DEFINE('PHP_ZMQ_HAVE_CURVE_KEYPAIR', 1); AC_DEFINE('PHP_ZMQ_HAVE_CTX_OPTIONS', 1); AC_DEFINE('PHP_ZMQ_HAVE_UNBIND', 1); AC_DEFINE('PHP_ZMQ_HAVE_DISCONNECT', 1); } else { WARNING("zmq not enabled; libraries and headers not found"); } } zmq-1.1.3/php-zmq.spec0000644000076500000240000000626412653534763011537 0ustar # Define version and release number %global version 1.1.3 Name: php-zmq Version: %{version} Release: %{release}%{?dist} Summary: PHP 0MQ/zmq/zeromq extension # See https://github.com/mkoppanen/php-zmq/pull/58 for discussion License: BSD Group: Development/Libraries URL: http://github.com/mkoppanen/php-zmq # Get the source files from https://github.com/mkoppanen/php-zmq/tags Source: %{name}-%{version}.tar.gz Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: php-devel BuildRequires: php-cli BuildRequires: zeromq-devel >= 2.0.7 Requires: zeromq >= 2.0.7 %{?filter_setup: %filter_from_provides /^zmq.so/d %filter_setup } %description PHP extension for the 0MQ/zmq/zeromq messaging system %prep %setup -q -n %{name}-%{version} %build /usr/bin/phpize %configure %{__make} %{?_smp_mflags} %install %{__make} install INSTALL_ROOT=%{buildroot} # Create the ini location %{__mkdir} -p %{buildroot}/%{_sysconfdir}/php.d # Preliminary extension ini echo "extension=zmq.so" > %{buildroot}/%{_sysconfdir}/php.d/zmq.ini %check echo "n" | make test %clean [ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot} %files %doc README LICENSE %{_libdir}/php/modules/zmq.so %config(noreplace) %{_sysconfdir}/php.d/zmq.ini %changelog * Thu Dec 20 2012 Adrian Siminiceanu - Fixed the %filter_from_provides and %filter_setup macros error in EPEL5. - Use the version define globally in all the places. - Fixed the release number match the number of changes the spec file suffered. - Fixed the source to work with the archive files from https://github.com/mkoppanen/php-zmq/tags - Added back the cleanup section - Added back the buildroot since it does not build anymore on a RH system * Mon Jul 09 2012 Ralph Bean - 0.6.0-5.20120613git516bd6f - Fixed the license field back to just "BSD". The files thought to be PHP-licensed were in fact generated by "phpize" in the %%build section. * Thu Jun 14 2012 Ralph Bean - 0.6.0-4.20120613git516bd6f - Fixed the private-shared-object-provides for reals with John Ciesla's help. * Wed Jun 13 2012 Ralph Bean - 0.6.0-3.20120613git516bd6f - Updated License to BSD and PHP. - Removed spurious gcc BuildRequires. - Fixed private-shared-object-provides. * Wed Jun 13 2012 Ralph Bean - 0.6.0-2.20120613git516bd6f - Using tarball of git checkout since the 0.6.0 release won't build anymore. - Using valid shortname for BSD license. - Added README and LICENSE to the doc - Use %%global instead of %%define. - Changed 0MQ to 0MQ/zmq/zeromq in Summary and Description to help with search. - Fully qualified Source URL. - Updated to modern BuildRequires. - Separated %%build out into %%build and %%install. - Removed unnecessary references to buildroot. - Removed unnecessary %%defattr. - Changed Group from Web/Applications to Development/Libraries. - Removed hardcoded Packager tag. - Added %%check section. - Marked /etc/php.d/zmq.ini as a config file. * Wed Jun 15 2011 Rick Moran - Minor Changes. * Thu Apr 8 2010 Mikko Koppanen - Initial spec file zmq-1.1.3/php_zmq.h0000644000076500000240000000513212653534763011107 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_H_ # define _PHP_ZMQ_H_ #define PHP_ZMQ_EXTNAME "zmq" #define PHP_ZMQ_VERSION "1.1.3" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef ZTS # include "TSRM.h" #endif #include "php.h" extern zend_module_entry zmq_module_entry; #define phpext_zmq_ptr &zmq_module_entry #endif /* _PHP_ZMQ_H_ */ zmq-1.1.3/php_zmq_private.h0000644000076500000240000001550512653534763012646 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_PRIVATE_H_ # define _PHP_ZMQ_PRIVATE_H_ #include "ext/standard/info.h" #include "Zend/zend_exceptions.h" #include "Zend/zend_llist.h" #include "main/php_ini.h" #include #ifdef HAVE_CZMQ # include # if CZMQ_VERSION_MAJOR >= 2 # define HAVE_CZMQ_2 # endif #endif #ifdef PHP_WIN32 # include "win32/php_stdint.h" #else # include #endif typedef struct _php_zmq_pollset php_zmq_pollset; /* {{{ typedef struct _php_zmq_context */ typedef struct _php_zmq_context { /* zmq context */ void *z_ctx; /* Amount of io-threads */ int io_threads; /* Is this a persistent context */ zend_bool is_persistent; /* Should this context live to end of process */ zend_bool use_shared_ctx; /* How many active sockets */ zend_long socket_count; /* Who created me */ int pid; } php_zmq_context; /* }}} */ /* {{{ typedef struct _php_zmq_socket */ typedef struct _php_zmq_socket { void *z_socket; int socket_type; php_zmq_context *ctx; HashTable connect; HashTable bind; zend_bool is_persistent; /* Who created me */ int pid; } php_zmq_socket; /* }}} */ /* {{{ typedef struct _php_zmq_context_object */ typedef struct _php_zmq_context_object { php_zmq_context *context; zend_object zo; } php_zmq_context_object; /* }}} */ /* {{{ typedef struct _php_zmq_socket_object */ typedef struct _php_zmq_socket_object { php_zmq_socket *socket; /* options for the context */ char *persistent_id; /* zval of the context */ zval context_obj; zend_object zo; } php_zmq_socket_object; /* }}} */ /* {{{ typedef struct _php_zmq_poll_object */ typedef struct _php_zmq_poll_object { php_zmq_pollset *set; zend_object zo; } php_zmq_poll_object; /* }}} */ typedef struct _php_zmq_device_cb_t { zend_bool initialized; long timeout; zend_fcall_info fci; zend_fcall_info_cache fci_cache; zval user_data; uint64_t scheduled_at; } php_zmq_device_cb_t; /* {{{ typedef struct _php_zmq_device_object */ typedef struct _php_zmq_device_object { php_zmq_device_cb_t idle_cb; php_zmq_device_cb_t timer_cb; zval front; zval back; zval capture; zend_object zo; } php_zmq_device_object; /* }}} */ #ifdef ZTS # define ZMQ_G(v) TSRMG(php_zmq_globals_id, zend_php_zmq_globals *, v) #else # define ZMQ_G(v) (php_zmq_globals.v) #endif #define ZMQ_RETURN_THIS RETURN_ZVAL(getThis(), 1, 0); #define PHP_ZMQ_ERROR_HANDLING_INIT() zend_error_handling error_handling; #define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling TSRMLS_CC); #define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC); /* Compatibility macros between zeromq 2.x and 3.x */ #ifndef ZMQ_DONTWAIT # define ZMQ_DONTWAIT ZMQ_NOBLOCK #endif #ifndef ZMQ_HWM # define ZMQ_HWM (ZMQ_DONTWAIT + 2000) #endif #ifndef ZMQ_FORWARDER # define ZMQ_FORWARDER 0 #endif #ifndef ZMQ_QUEUE # define ZMQ_QUEUE 0 #endif #ifndef ZMQ_STREAMER # define ZMQ_STREAMER 0 #endif #if ZMQ_VERSION_MAJOR == 2 # define zmq_sendmsg zmq_send # define zmq_recvmsg zmq_recv # define PHP_ZMQ_TIMEOUT 1000 #else # define PHP_ZMQ_TIMEOUT 1 #endif #define PHP_ZMQ_INTERNAL_ERROR -99 PHP_METHOD(zmqsocket, getsockopt); PHP_METHOD(zmqsocket, setsockopt); zend_bool php_zmq_device(php_zmq_device_object *intern); zend_class_entry *php_zmq_socket_exception_sc_entry_get (); zend_class_entry *php_zmq_device_exception_sc_entry_get (); php_stream *php_zmq_create_zmq_fd(zval *obj); void php_zmq_register_sockopt_constants (zend_class_entry *ce); typedef struct _php_zmq_clock_ctx_t php_zmq_clock_ctx_t; php_zmq_clock_ctx_t *php_zmq_clock_init (); uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx); void php_zmq_clock_destroy (php_zmq_clock_ctx_t **clock_ctx); char *php_zmq_get_libzmq_version(); zend_long php_zmq_get_libzmq_version_id(); char *php_zmq_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache); zend_bool php_zmq_shared_ctx_init(); void php_zmq_shared_ctx_assign_to(php_zmq_context *context); void php_zmq_shared_ctx_destroy(); int php_zmq_shared_ctx_socket_count(); void php_zmq_shared_ctx_socket_count_incr(); void php_zmq_shared_ctx_socket_count_decr(); ZEND_BEGIN_MODULE_GLOBALS(php_zmq) php_zmq_clock_ctx_t *clock_ctx; ZEND_END_MODULE_GLOBALS(php_zmq) #ifdef HAVE_CZMQ_2 # define PHP_ZMQ_AUTH_TYPE_PLAIN 0 # define PHP_ZMQ_AUTH_TYPE_CURVE 1 typedef struct _php_zmq_cert { zcert_t *zcert; zend_object zo; } php_zmq_cert_object; typedef struct _php_zmq_auth { zctx_t *shadow_context; zauth_t *zauth; zend_object zo; } php_zmq_auth_object; #endif #endif /* _PHP_ZMQ_PRIVATE_H_ */ zmq-1.1.3/php_zmq_pollset.h0000644000076500000240000001023712653534763012653 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #ifndef _PHP_ZMQ_POLLSET_H_ # define _PHP_ZMQ_POLLSET_H_ #define PHP_ZMQ_POLLSET_ERR_NO_STREAM -1 #define PHP_ZMQ_POLLSET_ERR_CANNOT_CAST -2 #define PHP_ZMQ_POLLSET_ERR_CAST_FAILED -3 #define PHP_ZMQ_POLLSET_ERR_NO_INIT -4 #define PHP_ZMQ_POLLSET_ERR_NO_POLL -5 #define PHP_ZMQ_POLLSET_ERR_KEY_FAIL -6 #define PHP_ZMQ_POLLSET_ERR_INVALID_TYPE -7 /** {{{ php_zmq_pollset *php_zmq_pollset_init(); */ php_zmq_pollset *php_zmq_pollset_init(); /* }}} */ /** {{{ zend_bool php_zmq_pollset_items(php_zmq_pollset *set, zval *return_value); */ zend_bool php_zmq_pollset_items(php_zmq_pollset *set, zval *return_value); /* }}} */ /** {{{ zend_string *php_zmq_pollset_add(php_zmq_pollset *set, zval *entry, int events, int *error); */ zend_string *php_zmq_pollset_add(php_zmq_pollset *set, zval *entry, int events, int *error); /* }}} */ /** {{{ zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry); */ zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry); /* }}} */ /** {{{ zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, zend_string *key); */ zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, zend_string *key); /* }}} */ /** {{{ void php_zmq_pollset_clear(php_zmq_pollset *set); */ void php_zmq_pollset_clear(php_zmq_pollset *set); /* }}} */ /** {{{ int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array); */ int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array); /* }}} */ /** {{{ size_t php_zmq_pollset_num_items(php_zmq_pollset *set); */ size_t php_zmq_pollset_num_items(php_zmq_pollset *set); /* }}} */ /** {{{ void php_zmq_pollset_delete_all(php_zmq_pollset *set); */ zval *php_zmq_pollset_errors(); /* }}} */ /** {{{ void php_zmq_pollset_deinit(php_zmq_pollset **set); */ void php_zmq_pollset_destroy(php_zmq_pollset **set); /* }}} */ #endif /* _PHP_ZMQ_POLLSET_H_ */ zmq-1.1.3/zmq.c0000644000076500000240000023730112653534763010240 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #include "php_zmq_pollset.h" ZEND_DECLARE_MODULE_GLOBALS(php_zmq); static zend_class_entry *php_zmq_sc_entry; static zend_class_entry *php_zmq_context_sc_entry; static zend_class_entry *php_zmq_socket_sc_entry; static zend_class_entry *php_zmq_poll_sc_entry; static zend_class_entry *php_zmq_device_sc_entry; static zend_class_entry *php_zmq_exception_sc_entry; static zend_class_entry *php_zmq_context_exception_sc_entry; static zend_class_entry *php_zmq_socket_exception_sc_entry; static zend_class_entry *php_zmq_poll_exception_sc_entry; static zend_class_entry *php_zmq_device_exception_sc_entry; static zend_object_handlers zmq_object_handlers; static zend_object_handlers zmq_socket_object_handlers; static zend_object_handlers zmq_context_object_handlers; static zend_object_handlers zmq_poll_object_handlers; static zend_object_handlers zmq_device_object_handlers; #ifdef HAVE_CZMQ_2 static zend_class_entry *php_zmq_cert_sc_entry; static zend_class_entry *php_zmq_auth_sc_entry; static zend_class_entry *php_zmq_cert_exception_sc_entry; static zend_class_entry *php_zmq_auth_exception_sc_entry; static zend_object_handlers zmq_cert_object_handlers; static zend_object_handlers zmq_auth_object_handlers; #endif #include "zmq_object_access.c" zend_class_entry *php_zmq_context_exception_sc_entry_get () { return php_zmq_context_exception_sc_entry; } zend_class_entry *php_zmq_socket_exception_sc_entry_get () { return php_zmq_socket_exception_sc_entry; } zend_class_entry *php_zmq_device_exception_sc_entry_get () { return php_zmq_device_exception_sc_entry; } static zend_long php_zmq_context_socket_count_get(php_zmq_context *context) { zend_long value = 0; if (context->use_shared_ctx) { value = php_zmq_shared_ctx_socket_count(); } else { value = context->socket_count; } return value; } static void php_zmq_context_socket_count_incr(php_zmq_context *context) { if (context->use_shared_ctx) { php_zmq_shared_ctx_socket_count_incr(); } else { context->socket_count++; } } static void php_zmq_context_socket_count_decr(php_zmq_context *context) { if (context->use_shared_ctx) { php_zmq_shared_ctx_socket_count_decr(); } else { context->socket_count--; } } /* list entries */ static int le_zmq_socket, le_zmq_context; /** {{{ static int php_zmq_socket_list_entry(void) */ static int php_zmq_socket_list_entry(void) { return le_zmq_socket; } /* }}} */ /* {{{ static int php_zmq_context_list_entry(void) */ static int php_zmq_context_list_entry(void) { return le_zmq_context; } /* }}} */ /* {{{ static void php_zmq_context_destroy(php_zmq_context *context) Destroy the context */ static void php_zmq_context_destroy(php_zmq_context *context) { if (context->pid == getpid()) { (void) zmq_term(context->z_ctx); } pefree(context, context->is_persistent); } /* }}} */ /* {{{ static void php_zmq_socket_destroy(php_zmq_socket *zmq_sock) Destroy the socket (note: does not touch context) */ static void php_zmq_socket_destroy(php_zmq_socket *zmq_sock) { zend_hash_destroy(&(zmq_sock->connect)); zend_hash_destroy(&(zmq_sock->bind)); /* Decrement socket count */ php_zmq_context_socket_count_decr(zmq_sock->ctx); if (zmq_sock->pid == getpid ()) { (void) zmq_close(zmq_sock->z_socket); } pefree(zmq_sock, zmq_sock->is_persistent); } /* }}} */ /* --- START ZMQContext --- */ /* {{{ static php_zmq_context *php_zmq_context_new(zend_long io_threads, zend_bool is_persistent, zend_bool use_shared_ctx) Create a new zmq context */ static php_zmq_context *php_zmq_context_new(zend_long io_threads, zend_bool is_persistent, zend_bool use_shared_ctx) { php_zmq_context *context = pecalloc(1, sizeof(php_zmq_context), is_persistent); if (use_shared_ctx) { php_zmq_shared_ctx_assign_to(context); } else { context->z_ctx = zmq_init(io_threads); } if (!context->z_ctx) { pefree(context, is_persistent); return NULL; } context->io_threads = io_threads; context->is_persistent = is_persistent; context->pid = getpid(); context->socket_count = 0; context->use_shared_ctx = use_shared_ctx; return context; } /* }}} */ /* {{{ static php_zmq_context *php_zmq_context_get(zend_long io_threads, zend_bool is_persistent) */ static php_zmq_context *php_zmq_context_get(zend_long io_threads, zend_bool is_persistent) { php_zmq_context *context; zend_string *plist_key = NULL; if (is_persistent) { zend_resource *le_p = NULL; plist_key = strpprintf(0, "zmq_context=[%ld]", io_threads); if ((le_p = zend_hash_find_ptr(&EG(persistent_list), plist_key)) != NULL) { if (le_p->type == php_zmq_context_list_entry()) { if (plist_key) { zend_string_release(plist_key); } return (php_zmq_context *) le_p->ptr; } } } context = php_zmq_context_new(io_threads, is_persistent, 0); if (!context) { if (plist_key) { zend_string_release(plist_key); } return NULL; } if (is_persistent) { zend_resource le; le.type = php_zmq_context_list_entry(); le.ptr = context; GC_REFCOUNT(&le) = 1; /* plist_key is not a persistent allocated key, thus we use str_update here */ if (zend_hash_str_update_mem(&EG(persistent_list), plist_key->val, plist_key->len, &le, sizeof(le)) == NULL) { if (plist_key) { zend_string_release(plist_key); } php_error_docref(NULL, E_ERROR, "Could not register persistent entry for the context"); /* not reached */ } } if (plist_key) { zend_string_release(plist_key); } return context; } /* }}} */ /* {{{ proto ZMQ ZMQ::__construct() Private constructor */ PHP_METHOD(zmq, __construct) {} /* }}} */ /* {{{ proto integer ZMQ::clock() A monotonic clock */ PHP_METHOD(zmq, clock) { if (zend_parse_parameters_none() == FAILURE) { return; } RETURN_LONG((long) php_zmq_clock (ZMQ_G (clock_ctx))); } /* }}} */ #ifdef PHP_ZMQ_HAVE_Z85 /* {{{ proto string ZMQ::z85Encode(string $data) */ PHP_METHOD(zmq, z85encode) { zend_string *data; char *buffer; size_t buffer_size; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data) == FAILURE) { return; } if (!data->len) { RETURN_NULL(); } buffer_size = 5 * data->len / 4 + 1; buffer = emalloc(buffer_size); if (!zmq_z85_encode (buffer, (const uint8_t *) data->val, data->len)) { efree(buffer); RETURN_NULL(); } RETVAL_STRINGL(buffer, buffer_size - 1); efree(buffer); return; } /* }}} */ /* {{{ proto string ZMQ::z85Decode(string $z85_encoded_data) */ PHP_METHOD(zmq, z85decode) { zend_string *data; uint8_t *buffer; size_t buffer_size; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data) == FAILURE) { return; } if (!data->len) { RETURN_NULL(); } buffer_size = 4 * data->len / 5; buffer = emalloc(buffer_size); if (!zmq_z85_decode (buffer, data->val)) { efree(buffer); RETURN_NULL(); } RETVAL_STRINGL((char *) buffer, buffer_size); efree(buffer); return; } /* }}} */ #endif #ifdef PHP_ZMQ_HAVE_CURVE_KEYPAIR #define PHP_ZMQ_KEY_SIZE 41 /* {{{ proto array ZMQ::curveKeypair() */ PHP_METHOD(zmq, curvekeypair) { char public_key[PHP_ZMQ_KEY_SIZE], secret_key[PHP_ZMQ_KEY_SIZE]; if (zend_parse_parameters_none() == FAILURE) { return; } if (zmq_curve_keypair(public_key, secret_key) == 0) { array_init(return_value); add_assoc_stringl(return_value, "public_key", public_key, PHP_ZMQ_KEY_SIZE - 1); add_assoc_stringl(return_value, "secret_key", secret_key, PHP_ZMQ_KEY_SIZE - 1); } } /* }}} */ #endif /* {{{ proto ZMQContext ZMQContext::__construct(integer $io_threads[, boolean $is_persistent = true]) Build a new ZMQContext object */ PHP_METHOD(zmqcontext, __construct) { php_zmq_context_object *intern; long io_threads = 1; zend_bool is_persistent = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lb", &io_threads, &is_persistent) == FAILURE) { return; } intern = php_zmq_context_fetch_object(Z_OBJ_P(getThis())); intern->context = php_zmq_context_get(io_threads, is_persistent); if (!intern->context) { zend_throw_exception_ex(php_zmq_context_exception_sc_entry, errno, "Error creating context: %s", zmq_strerror(errno)); return; } return; } /* }}} */ /* {{{ proto ZMQContext ZMQContext::acquire() Acquires a handle to the process global context */ PHP_METHOD(zmqcontext, acquire) { php_zmq_context *context; php_zmq_context_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } context = php_zmq_context_new(1, 1, 1); // Create a global context object_init_ex(return_value, php_zmq_context_sc_entry); intern = php_zmq_context_fetch_object(Z_OBJ_P(return_value)); intern->context = context; return; } /* }}} */ /* {{{ proto integer ZMQContext::getSocketCount() Number of active sockets in this context */ PHP_METHOD(zmqcontext, getsocketcount) { php_zmq_context_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; RETURN_LONG(php_zmq_context_socket_count_get(intern->context)); } /* }}} */ #ifdef PHP_ZMQ_HAVE_CTX_OPTIONS /* {{{ proto ZMQContext ZMQContext::setOpt(int option, int value) Set a context option */ PHP_METHOD(zmqcontext, setOpt) { php_zmq_context_object *intern; zend_long option, value; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &option, &value) == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; switch (option) { case ZMQ_MAX_SOCKETS: { if (zmq_ctx_set(intern->context->z_ctx, option, value) != 0) { zend_throw_exception_ex(php_zmq_context_exception_sc_entry_get (), errno, "Failed to set the option ZMQ::CTXOPT_MAX_SOCKETS value: %s", zmq_strerror(errno)); return; } } break; default: { zend_throw_exception(php_zmq_context_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR); return; } } return; } /* }}} */ /* {{{ proto ZMQContext ZMQContext::getOpt(int option) Set a context option */ PHP_METHOD(zmqcontext, getOpt) { php_zmq_context_object *intern; zend_long option; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &option) == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; switch (option) { case ZMQ_MAX_SOCKETS: { int value = zmq_ctx_get(intern->context->z_ctx, option); RETURN_LONG(value); } break; default: { zend_throw_exception(php_zmq_context_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR); return; } } return; } /* }}} */ #endif /* {{{ static php_zmq_socket *php_zmq_socket_new(php_zmq_context *context, int type, zend_bool is_persistent) Create a new zmq socket */ static php_zmq_socket *php_zmq_socket_new(php_zmq_context *context, int type, zend_bool is_persistent) { php_zmq_socket *zmq_sock; zmq_sock = pecalloc(1, sizeof(php_zmq_socket), is_persistent); zmq_sock->z_socket = zmq_socket(context->z_ctx, type); zmq_sock->pid = getpid(); zmq_sock->ctx = context; zmq_sock->socket_type = type; if (!zmq_sock->z_socket) { pefree(zmq_sock, is_persistent); return NULL; } /* Increment socket count */ php_zmq_context_socket_count_incr(context); zmq_sock->is_persistent = is_persistent; zend_hash_init(&(zmq_sock->connect), 0, NULL, NULL, is_persistent); zend_hash_init(&(zmq_sock->bind), 0, NULL, NULL, is_persistent); return zmq_sock; } /* }}} */ static zend_string *php_zmq_socket_plist_key(zend_long type, zend_string *persistent_id, zend_bool use_shared_ctx) { return strpprintf(0, "zmq_socket:[%ld]-[%s]-[%d]", type, persistent_id->val, use_shared_ctx); } static void php_zmq_socket_store(php_zmq_socket *zmq_sock_p, zend_long type, zend_string *persistent_id, zend_bool use_shared_ctx) { zend_string *plist_key = NULL; zend_resource le; le.type = php_zmq_socket_list_entry(); le.ptr = zmq_sock_p; GC_REFCOUNT(&le) = 1; plist_key = php_zmq_socket_plist_key(type, persistent_id, use_shared_ctx); /* plist_key is not a persistent allocated key, thus we use str_update here */ if (zend_hash_str_update_mem(&EG(persistent_list), plist_key->val, plist_key->len, &le, sizeof(le)) == NULL) { if (plist_key) { zend_string_release(plist_key); } php_error_docref(NULL, E_ERROR, "Could not register persistent entry for the socket"); /* not reached */ } if (plist_key) { zend_string_release(plist_key); } } /* {{{ static php_zmq_socket *php_zmq_socket_get(php_zmq_context *context, zend_long type, zend_string *persistent_id, zend_bool *is_new) Tries to get context from plist and allocates a new context if context does not exist */ static php_zmq_socket *php_zmq_socket_get(php_zmq_context *context, zend_long type, zend_string *persistent_id, zend_bool *is_new) { php_zmq_socket *zmq_sock_p; zend_string *plist_key = NULL; zend_bool is_persistent = 0; is_persistent = (context->is_persistent && persistent_id && persistent_id->len) ? 1 : 0; *is_new = 0; if (is_persistent) { zend_resource *le_p = NULL; plist_key = php_zmq_socket_plist_key(type, persistent_id, context->use_shared_ctx); if ((le_p = zend_hash_find_ptr(&EG(persistent_list), plist_key)) != NULL) { if (le_p->type == php_zmq_socket_list_entry()) { if (plist_key) { zend_string_release(plist_key); } return (php_zmq_socket *) le_p->ptr; } } } zmq_sock_p = php_zmq_socket_new(context, type, is_persistent); if (plist_key) { zend_string_release(plist_key); } if (!zmq_sock_p) { return NULL; } *is_new = 1; return zmq_sock_p; } /* }}} */ static zend_bool php_zmq_connect_callback(zval *socket, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id) { zval retval; zval params[2]; zend_bool rv = 1; /* Call the cb */ params[0] = *socket; if (persistent_id && persistent_id->len) { ZVAL_STR(¶ms[1], zend_string_copy(persistent_id)); } else { ZVAL_NULL(¶ms[1]); } fci->params = params; fci->param_count = 2; fci->retval = &retval; fci->no_separation = 1; if (zend_call_function(fci, fci_cache) == FAILURE) { if (!EG(exception)) { char *func_name = php_zmq_printable_func(fci, fci_cache); zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, 0, "Failed to invoke 'on_new_socket' callback %s()", func_name); efree(func_name); } rv = 0; } zval_ptr_dtor(¶ms[1]); if (Z_TYPE(retval) != IS_UNDEF) { zval_ptr_dtor(&retval); } if (EG(exception)) { rv = 0; } return rv; } /* {{{ proto ZMQContext ZMQContext::getSocket(integer $type[, string $persistent_id = null[, callback $on_new_socket = null]]) Build a new ZMQContext object */ PHP_METHOD(zmqcontext, getsocket) { php_zmq_socket *socket; php_zmq_socket_object *interns; php_zmq_context_object *intern; zend_long type; zend_string *persistent_id = NULL; int rc; zend_bool is_new; zend_fcall_info fci; zend_fcall_info_cache fci_cache; PHP_ZMQ_ERROR_HANDLING_INIT() PHP_ZMQ_ERROR_HANDLING_THROW() fci.size = 0; rc = zend_parse_parameters(ZEND_NUM_ARGS(), "l|S!f!", &type, &persistent_id, &fci, &fci_cache); PHP_ZMQ_ERROR_HANDLING_RESTORE() if (rc == FAILURE) { return; } intern = php_zmq_context_fetch_object(Z_OBJ_P(getThis())); socket = php_zmq_socket_get(intern->context, type, persistent_id, &is_new); if (!socket) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Error creating socket: %s", zmq_strerror(errno)); return; } object_init_ex(return_value, php_zmq_socket_sc_entry); interns = php_zmq_socket_fetch_object(Z_OBJ_P(return_value)); interns->socket = socket; /* Need to add refcount if context is not persistent */ if (!intern->context->is_persistent) { ZVAL_OBJ(&interns->context_obj, &intern->zo); Z_ADDREF(interns->context_obj); } if (is_new) { if (fci.size) { if (!php_zmq_connect_callback(return_value, &fci, &fci_cache, persistent_id)) { php_zmq_socket_destroy(socket); interns->socket = NULL; zval_dtor(return_value); return; } } if (socket->is_persistent) { php_zmq_socket_store(socket, type, persistent_id, intern->context->use_shared_ctx); } } if (socket->is_persistent) { interns->persistent_id = estrdup(persistent_id->val); } return; } /* }}} */ /* {{{ proto ZMQContext ZMQContext::isPersistent() Whether the context is persistent */ PHP_METHOD(zmqcontext, ispersistent) { php_zmq_context_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_CONTEXT_OBJECT; RETURN_BOOL(intern->context->is_persistent); } /* }}} */ /* {{{ proto ZMQContext ZMQContext::__clone() Clones the instance of the ZMQContext class */ PHP_METHOD(zmqcontext, __clone) { } /* }}} */ /* --- END ZMQContext --- */ /* --- START ZMQSocket --- */ /* {{{ proto ZMQSocket ZMQSocket::__construct(ZMQContext $context, integer $type[, string $persistent_id = null[, callback $on_new_socket = null]]) Build a new ZMQSocket object */ PHP_METHOD(zmqsocket, __construct) { php_zmq_socket *socket; php_zmq_socket_object *intern; php_zmq_context_object *internc; zend_long type; zend_string *persistent_id = NULL; int rc; zval *obj; zend_bool is_new; zend_fcall_info fci; zend_fcall_info_cache fci_cache; PHP_ZMQ_ERROR_HANDLING_INIT() PHP_ZMQ_ERROR_HANDLING_THROW() fci.size = 0; rc = zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|S!f!", &obj, php_zmq_context_sc_entry, &type, &persistent_id, &fci, &fci_cache); PHP_ZMQ_ERROR_HANDLING_RESTORE() if (rc == FAILURE) { return; } internc = php_zmq_context_fetch_object(Z_OBJ_P(obj)); socket = php_zmq_socket_get(internc->context, type, persistent_id, &is_new); if (!socket) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Error creating socket: %s", zmq_strerror(errno)); return; } intern = PHP_ZMQ_SOCKET_OBJECT; intern->socket = socket; /* Need to add refcount if context is not persistent */ if (!internc->context->is_persistent) { ZVAL_OBJ(&intern->context_obj, &internc->zo); Z_ADDREF(intern->context_obj); } if (is_new) { if (fci.size) { if (!php_zmq_connect_callback(getThis(), &fci, &fci_cache, persistent_id)) { php_zmq_socket_destroy(socket); intern->socket = NULL; return; } } if (socket->is_persistent) { php_zmq_socket_store(socket, type, persistent_id, internc->context->use_shared_ctx); } } if (socket->is_persistent) { intern->persistent_id = estrdup(persistent_id->val); } return; } /* }}} */ /* {{{ static zend_bool php_zmq_send(php_zmq_socket_object *intern, char *message_param, long flags) */ static zend_bool php_zmq_send(php_zmq_socket_object *intern, zend_string *message_param, long flags) { int rc, errno_; zmq_msg_t message; if (zmq_msg_init_size(&message, message_param->len) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to initialize message structure: %s", zmq_strerror(errno)); return 0; } memcpy(zmq_msg_data(&message), message_param->val, message_param->len); rc = zmq_sendmsg(intern->socket->z_socket, &message, flags); errno_ = errno; zmq_msg_close(&message); if (rc == -1) { if (errno_ == EAGAIN) { return 0; } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno_, "Failed to send message: %s", zmq_strerror(errno_)); return 0; } return 1; } /* }}} */ static void php_zmq_sendmsg_impl(INTERNAL_FUNCTION_PARAMETERS) { php_zmq_socket_object *intern; zend_string *message_param; long flags = 0; zend_bool ret; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &message_param, &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; ret = php_zmq_send(intern, message_param, flags); if (ret) { ZMQ_RETURN_THIS; } else { RETURN_FALSE; } } /* {{{ proto ZMQSocket ZMQSocket::send(string $message[, integer $flags = 0]) Send a message. Return true if message was sent and false on EAGAIN */ PHP_METHOD(zmqsocket, send) { php_zmq_sendmsg_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ static int php_zmq_send_cb(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) { php_zmq_socket_object *intern; int flags, *rc, *to_send; intern = va_arg(args, php_zmq_socket_object *); flags = va_arg(args, int); to_send = va_arg(args, int *); rc = va_arg(args, int *); if (--(*to_send)) { flags = flags | ZMQ_SNDMORE; } else { flags = flags & ~ZMQ_SNDMORE; } zend_string *str = zval_get_string(zv); *rc = php_zmq_send(intern, str, flags); zend_string_release(str); if (!*rc) { return ZEND_HASH_APPLY_STOP; } return ZEND_HASH_APPLY_KEEP; } /* {{{ proto ZMQSocket ZMQSocket::sendmulti(arrays $messages[, integer $flags = 0]) Send a multipart message. Return true if message was sent and false on EAGAIN */ PHP_METHOD(zmqsocket, sendmulti) { zval *messages; php_zmq_socket_object *intern; int to_send, ret = 0; long flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &messages, &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; to_send = zend_hash_num_elements(Z_ARRVAL_P(messages)); zend_hash_apply_with_arguments(Z_ARRVAL_P(messages), (apply_func_args_t) php_zmq_send_cb, 4, intern, flags, &to_send, &ret); if (ret) { ZMQ_RETURN_THIS; } else { RETURN_FALSE; } } /* {{{ static zend_bool php_zmq_recv(php_zmq_socket_object *intern, long flags, zval *return_value) */ static zend_string *php_zmq_recv(php_zmq_socket_object *intern, long flags) { int rc, errno_; zmq_msg_t message; zend_string *str = NULL; if (zmq_msg_init(&message) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to initialize message structure: %s", zmq_strerror(errno)); return NULL; } rc = zmq_recvmsg(intern->socket->z_socket, &message, flags); errno_ = errno; if (rc == -1) { zmq_msg_close(&message); if (errno == EAGAIN) { return NULL; } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno_, "Failed to receive message: %s", zmq_strerror(errno_)); return NULL; } str = zend_string_init(zmq_msg_data(&message), zmq_msg_size(&message), 1); zmq_msg_close(&message); return str; } /* }}} */ static void php_zmq_recvmsg_impl(INTERNAL_FUNCTION_PARAMETERS) { zend_string *str = NULL; php_zmq_socket_object *intern; long flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; str = php_zmq_recv(intern, flags); if (!str) { RETURN_FALSE; } RETURN_STR(str); } /* {{{ proto string ZMQ::recv([integer $flags = 0]) Receive a message */ PHP_METHOD(zmqsocket, recv) { php_zmq_recvmsg_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ /* {{{ proto array ZMQ::recvmulti([integer $flags = 0]) Receive an array of message parts */ PHP_METHOD(zmqsocket, recvmulti) { php_zmq_socket_object *intern; size_t value_len; long flags = 0; #if ZMQ_VERSION_MAJOR < 3 int64_t value; #else int value; #endif if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; array_init(return_value); value_len = sizeof (value); do { zend_string *part = php_zmq_recv(intern, flags); if (!part) { zval_dtor(return_value); RETURN_FALSE; } add_next_index_str(return_value, part); zmq_getsockopt(intern->socket->z_socket, ZMQ_RCVMORE, &value, &value_len); } while (value > 0); return; } /* }}} */ #if PHP_ZMQ_HAVE_SOCKET_MONITOR /* {{{ proto array ZMQ::recvevent([integer $flags = 0]) Receive an event from monitor endpoint */ PHP_METHOD(zmqsocket, recvevent) { php_zmq_socket_object *intern; zend_long flags = 0; int value; uint8_t *data; uint16_t event; zend_string *metadata, *address; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; metadata = php_zmq_recv(intern, flags); if (!metadata || metadata->len != sizeof (uint16_t) + sizeof (uint32_t)) { if (metadata) { zend_string_release(metadata); } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Invalid monitor message received: %s", zmq_strerror(errno)); return; } address = php_zmq_recv(intern, flags); if (!address) { zend_string_release(metadata); zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Invalid monitor message received: %s", zmq_strerror(errno)); return; } data = (uint8_t *) metadata->val; event = *(uint16_t *) (data); value = *(uint32_t *) (data + sizeof(uint16_t)); array_init(return_value); add_assoc_long(return_value, "event", event); add_assoc_long(return_value, "value", value); add_assoc_str(return_value, "address", address); zend_string_release(metadata); return; } /* }}} */ /* {{{ proto ZMQSocket ZMQ::monitor(string $dsn[, integer $events = ZMQ::EVENTS_ALL]) Add a monitor */ PHP_METHOD(zmqsocket, monitor) { php_zmq_socket_object *intern; zend_string *dsn; zend_long events = ZMQ_EVENT_ALL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &dsn, &events) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (zmq_socket_monitor(intern->socket->z_socket, dsn->val, events) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to add socket monitor: %s", zmq_strerror(errno)); return; } ZMQ_RETURN_THIS; } /* }}} */ #endif /** {{{ string ZMQ::getPersistentId() Returns the persistent id of the object */ PHP_METHOD(zmqsocket, getpersistentid) { php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (intern->socket->is_persistent && intern->persistent_id) { RETURN_STRING(intern->persistent_id); } RETURN_NULL(); } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::bind(string $dsn[, boolean $force = false]) Bind the socket to an endpoint */ PHP_METHOD(zmqsocket, bind) { php_zmq_socket_object *intern; zend_string *dsn; zend_bool force = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &dsn, &force) == FAILURE) { return; } intern = php_zmq_socket_fetch_object(Z_OBJ_P(getThis())); /* already connected ? */ if (!force && zend_hash_exists(&(intern->socket->bind), dsn)) { ZMQ_RETURN_THIS; } if (zmq_bind(intern->socket->z_socket, dsn->val) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to bind the ZMQ: %s", zmq_strerror(errno)); return; } zend_hash_str_add_empty_element(&(intern->socket->bind), dsn->val, dsn->len); ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::connect(string $dsn[, boolean $force = false]) Connect the socket to an endpoint */ PHP_METHOD(zmqsocket, connect) { php_zmq_socket_object *intern; zend_string *dsn; zend_bool force = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &dsn, &force) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; /* already connected ? */ if (!force && zend_hash_exists(&(intern->socket->connect), dsn)) { ZMQ_RETURN_THIS; } if (zmq_connect(intern->socket->z_socket, dsn->val) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to connect the ZMQ: %s", zmq_strerror(errno)); return; } zend_hash_str_add_empty_element(&(intern->socket->connect), dsn->val, dsn->len); ZMQ_RETURN_THIS; } /* }}} */ #ifdef PHP_ZMQ_HAVE_UNBIND /* {{{ proto ZMQSocket ZMQSocket::unbind(string $dsn) Unbind the socket from an endpoint */ PHP_METHOD(zmqsocket, unbind) { php_zmq_socket_object *intern; zend_string *dsn; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &dsn) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (zmq_unbind(intern->socket->z_socket, dsn->val) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to unbind the ZMQ socket: %s", zmq_strerror(errno)); return; } zend_hash_del(&(intern->socket->bind), dsn); ZMQ_RETURN_THIS; } /* }}} */ #endif #ifdef PHP_ZMQ_HAVE_DISCONNECT /* {{{ proto ZMQSocket ZMQSocket::disconnect(string $dsn) Disconnect the socket from an endpoint */ PHP_METHOD(zmqsocket, disconnect) { php_zmq_socket_object *intern; zend_string *dsn; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &dsn) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (zmq_disconnect(intern->socket->z_socket, dsn->val) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry, errno, "Failed to disconnect the ZMQ socket: %s", zmq_strerror(errno)); return; } zend_hash_del(&(intern->socket->connect), dsn); ZMQ_RETURN_THIS; } /* }}} */ #endif static int php_zmq_get_keys(zval *ppzval, int num_args, va_list args, zend_hash_key *hash_key) { zval *retval = va_arg(args, zval *); add_next_index_string(retval, hash_key->key->val); return ZEND_HASH_APPLY_KEEP; } /* }}} */ /* {{{ proto array ZMQ::getEndpoints() Returns endpoints where this socket is connected/bound to. Contains two keys ('bind', 'connect') */ PHP_METHOD(zmqsocket, getendpoints) { php_zmq_socket_object *intern; zval connect, bind; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; array_init(return_value); array_init(&connect); array_init(&bind); zend_hash_apply_with_arguments(&(intern->socket->connect), (apply_func_args_t) php_zmq_get_keys, 1, &connect); zend_hash_apply_with_arguments(&(intern->socket->bind), (apply_func_args_t) php_zmq_get_keys, 1, &bind); add_assoc_zval(return_value, "connect", &connect); add_assoc_zval(return_value, "bind", &bind); return; } /* }}} */ /* {{{ proto integer ZMQSocket::getSocketType() Returns the socket type */ PHP_METHOD(zmqsocket, getsockettype) { int type; size_t type_siz; php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; type_siz = sizeof (int); if (zmq_getsockopt(intern->socket->z_socket, ZMQ_TYPE, &type, &type_siz) != -1) { RETURN_LONG(type); } RETURN_LONG(-1); } /* }}} */ /* {{{ proto boolean ZMQSocket::isPersistent() Whether the socket is persistent */ PHP_METHOD(zmqsocket, ispersistent) { php_zmq_socket_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; RETURN_BOOL(intern->socket->is_persistent); } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::__clone() Clones the instance of the ZMQSocket class */ PHP_METHOD(zmqsocket, __clone) { } /* }}} */ /* -- END ZMQSocket--- */ /* -- START ZMQPoll --- */ /* {{{ proto integer ZMQPoll::add(ZMQSocket $object, integer $events) Add a ZMQSocket object into the pollset */ PHP_METHOD(zmqpoll, add) { php_zmq_poll_object *intern; zval *object; long events; int error; zend_string *key; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", &object, &events) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; switch (Z_TYPE_P(object)) { case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(object), php_zmq_socket_sc_entry)) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "The first argument must be an instance of ZMQSocket or a resource", PHP_ZMQ_INTERNAL_ERROR); return; } break; case IS_RESOURCE: /* noop */ break; default: zend_throw_exception(php_zmq_poll_exception_sc_entry, "The first argument must be an instance of ZMQSocket or a resource", PHP_ZMQ_INTERNAL_ERROR); return; break; } key = php_zmq_pollset_add(intern->set, object, events, &error); if (!key) { const char *message = NULL; switch (error) { case PHP_ZMQ_POLLSET_ERR_NO_STREAM: message = "The supplied resource is not a valid stream resource"; break; case PHP_ZMQ_POLLSET_ERR_CANNOT_CAST: message = "The supplied resource is not castable"; break; case PHP_ZMQ_POLLSET_ERR_CAST_FAILED: message = "Failed to cast the supplied stream resource"; break; case PHP_ZMQ_POLLSET_ERR_NO_INIT: message = "The ZMQSocket object has not been initialized properly"; break; case PHP_ZMQ_POLLSET_ERR_NO_POLL: message = "The ZMQSocket object has not been initialized with polling"; break; default: message = "Unknown error"; break; } zend_throw_exception(php_zmq_poll_exception_sc_entry, message, PHP_ZMQ_INTERNAL_ERROR); return; } RETURN_STR(key); } /* }}} */ /* {{{ proto boolean ZMQPoll::remove(mixed $item) Remove item from poll set */ PHP_METHOD(zmqpoll, remove) { php_zmq_poll_object *intern; zval *item; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &item) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; if (php_zmq_pollset_num_items(intern->set) == 0) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "No sockets assigned to the ZMQPoll", PHP_ZMQ_INTERNAL_ERROR); return; } switch (Z_TYPE_P(item)) { case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(item), php_zmq_socket_sc_entry)) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "The object must be an instanceof ZMQSocket", PHP_ZMQ_INTERNAL_ERROR); return; } /* break intentionally missing */ case IS_RESOURCE: RETVAL_BOOL(php_zmq_pollset_delete(intern->set, item)); break; default: { zend_string *str = zval_get_string(item); zend_bool retval; retval = php_zmq_pollset_delete_by_key(intern->set, str); zend_string_release(str); RETVAL_BOOL(retval); } break; } return; } /* }}} */ /* {{{ proto integer ZMQPoll::poll(array &$readable, array &$writable[, integer $timeout = -1]) Poll the sockets */ PHP_METHOD(zmqpoll, poll) { php_zmq_poll_object *intern; zval *r_array, *w_array; long timeout = -1; int rc; if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!a!|l", &r_array, &w_array, &timeout) == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; if (php_zmq_pollset_num_items(intern->set) == 0) { zend_throw_exception(php_zmq_poll_exception_sc_entry, "No sockets assigned to the ZMQPoll", PHP_ZMQ_INTERNAL_ERROR); return; } rc = php_zmq_pollset_poll(intern->set, timeout * PHP_ZMQ_TIMEOUT, r_array, w_array); if (rc == -1) { zend_throw_exception_ex(php_zmq_poll_exception_sc_entry, errno, "Poll failed: %s", zmq_strerror(errno)); return; } RETURN_LONG(rc); } /* }}} */ /* {{{ proto integer ZMQPoll::count() Returns the number of items in the set */ PHP_METHOD(zmqpoll, count) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; RETURN_LONG(php_zmq_pollset_num_items(intern->set)); } /* }}} */ /* {{{ proto ZMQPoll ZMQPoll::clear() Clear the pollset */ PHP_METHOD(zmqpoll, clear) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; php_zmq_pollset_clear(intern->set); ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto array ZMQPoll::items() Clear the pollset */ PHP_METHOD(zmqpoll, items) { php_zmq_poll_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; array_init(return_value); php_zmq_pollset_items(intern->set, return_value); } /* }}} */ /* {{{ proto array ZMQPoll::getLastErrors() Returns last errors */ PHP_METHOD(zmqpoll, getlasterrors) { php_zmq_poll_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } intern = PHP_ZMQ_POLL_OBJECT; RETVAL_ZVAL(php_zmq_pollset_errors(intern->set), 1, 0); return; } /* }}} */ /* {{{ proto ZMQPoll ZMQPoll::__clone() Clones the instance of the ZMQPoll class */ PHP_METHOD(zmqpoll, __clone) { } /* }}} */ /* -- END ZMQPoll */ /* {{{ proto void ZMQDevice::__construct(ZMQSocket frontend, ZMQSocket backend) Construct a device */ PHP_METHOD(zmqdevice, __construct) { php_zmq_device_object *intern; zval *f, *b, *c = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|O!", &f, php_zmq_socket_sc_entry, &b, php_zmq_socket_sc_entry, &c, php_zmq_socket_sc_entry) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; ZVAL_OBJ(&intern->front, Z_OBJ_P(f)); Z_ADDREF(intern->front); ZVAL_OBJ(&intern->back, Z_OBJ_P(b)); Z_ADDREF(intern->back); if (c) { ZVAL_OBJ(&intern->capture, Z_OBJ_P(c)); Z_ADDREF(intern->capture); } else { ZVAL_UNDEF(&intern->capture); } } /* }}} */ /* {{{ proto void ZMQDevice::run() Start a device */ PHP_METHOD(zmqdevice, run) { php_zmq_device_object *intern; zend_bool rc; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; rc = php_zmq_device (intern); if (!rc && !EG (exception)) { zend_throw_exception_ex(php_zmq_device_exception_sc_entry, errno, "Failed to start the device: %s", zmq_strerror (errno)); return; } return; } /* }}} */ static void s_clear_device_callback (php_zmq_device_cb_t *cb) { if (cb->initialized) { zval_ptr_dtor(&cb->fci.function_name); cb->fci.size = 0; if (!Z_ISUNDEF(cb->user_data)) { zval_ptr_dtor(&cb->user_data); } memset (cb, 0, sizeof (php_zmq_device_cb_t)); cb->initialized = 0; } } static void s_init_device_callback (php_zmq_device_cb_t *cb, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, long timeout, zval *user_data) { memcpy (&cb->fci, fci, sizeof (zend_fcall_info)); memcpy (&cb->fci_cache, fci_cache, sizeof (zend_fcall_info_cache)); Z_TRY_ADDREF (fci->function_name); cb->initialized = 1; cb->scheduled_at = php_zmq_clock (ZMQ_G (clock_ctx)) + timeout; cb->timeout = timeout; if (user_data) { ZVAL_COPY(&cb->user_data, user_data); } else { ZVAL_NULL(&cb->user_data); } } /* {{{ proto void ZMQDevice::setIdleTimeout (int $milliseconds) Set the idle timeout value */ PHP_METHOD(zmqdevice, setidletimeout) { php_zmq_device_object *intern; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &timeout) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; intern->idle_cb.timeout = timeout; ZMQ_RETURN_THIS; } /* }}} */ PHP_METHOD(zmqdevice, getidletimeout) { php_zmq_device_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; RETURN_LONG(intern->idle_cb.timeout); } PHP_METHOD(zmqdevice, settimertimeout) { php_zmq_device_object *intern; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &timeout) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; intern->timer_cb.timeout = timeout; ZMQ_RETURN_THIS; } PHP_METHOD(zmqdevice, gettimertimeout) { php_zmq_device_object *intern; if (zend_parse_parameters_none() == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; RETURN_LONG(intern->timer_cb.timeout); } /* {{{ proto void ZMQDevice::setIdleCallback (callable $function, integer timeout [, mixed $userdata]) Set the idle timeout value */ PHP_METHOD(zmqdevice, setidlecallback) { php_zmq_device_object *intern; zval *user_data = NULL; zend_fcall_info fci; zend_fcall_info_cache fci_cache; long timeout = 0; if (ZEND_NUM_ARGS() == 2) { php_error_docref(NULL, E_DEPRECATED, "The signature for setIdleCallback has changed, please update your code"); if (zend_parse_parameters(ZEND_NUM_ARGS(), "f|z!", &fci, &fci_cache, &user_data) == FAILURE) { return; } } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "fl|z!", &fci, &fci_cache, &timeout, &user_data) == FAILURE) { return; } } intern = PHP_ZMQ_DEVICE_OBJECT; /* Hack for backwards compatible behaviour */ if (!timeout) { if (intern->idle_cb.timeout) { timeout = intern->idle_cb.timeout; } } s_clear_device_callback (&intern->idle_cb); if (fci.size > 0) { s_init_device_callback (&intern->idle_cb, &fci, &fci_cache, timeout, user_data); } ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto void ZMQDevice::setTimerCallback (callable $function, integer timeout [, mixed $userdata]) Set the timer function */ PHP_METHOD(zmqdevice, settimercallback) { php_zmq_device_object *intern; zval *user_data = NULL; zend_fcall_info fci; zend_fcall_info_cache fci_cache; long timeout; if (zend_parse_parameters(ZEND_NUM_ARGS(), "fl|z!", &fci, &fci_cache, &timeout, &user_data) == FAILURE) { return; } intern = PHP_ZMQ_DEVICE_OBJECT; s_clear_device_callback (&intern->timer_cb); if (fci.size > 0) { s_init_device_callback (&intern->timer_cb, &fci, &fci_cache, timeout, user_data); } ZMQ_RETURN_THIS; } /* }}} */ /* {{{ proto ZMQDevice ZMQDevice::__clone() Clones the instance of the ZMQDevice class */ PHP_METHOD(zmqdevice, __clone) { } /* }}} */ /* -- END ZMQPoll */ #ifdef HAVE_CZMQ_2 /* --- START q --- */ static void php_zmq_cert_object_free_storage(zend_object *object) { php_zmq_cert_object *intern = php_zmq_cert_fetch_object(object); if (!intern) { return; } if (intern->zcert) { zcert_destroy(&intern->zcert); } zend_object_std_dtor(&intern->zo); } static zend_object *php_zmq_cert_new(zend_class_entry *class_type) { php_zmq_cert_object *intern = ecalloc(1, sizeof(php_zmq_cert_object) + zend_object_properties_size(class_type)); /* zcert is initialised in ZMQCert#__construct. */ intern->zcert = NULL; zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_cert_object_handlers; return &intern->zo; } PHP_METHOD(zmqcert, __construct) { zend_string *filename = NULL; zend_error_handling error_handling; int parse_parameters_result; php_zmq_cert_object *intern; zend_replace_error_handling(EH_THROW, php_zmq_cert_exception_sc_entry, &error_handling); parse_parameters_result = zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &filename); zend_restore_error_handling(&error_handling); if (parse_parameters_result != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; if (!filename) { intern->zcert = zcert_new(); if (!intern->zcert) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to create the underlying zcert object. Is libsodium installed?", filename); } return; } intern->zcert = zcert_load(filename->val); if (!intern->zcert) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to load the certificate from %s", filename->val); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert___construct_args, 0, 0, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO(); PHP_METHOD(zmqcert, getPublicKey) { php_zmq_cert_object *intern; byte *public_key; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; public_key = zcert_public_key(intern->zcert); if (!public_key) { RETURN_NULL(); } RETURN_STRINGL((char *) public_key, 32); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getPublicKey_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getSecretKey) { php_zmq_cert_object *intern; byte *secret_key; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; secret_key = zcert_secret_key(intern->zcert); if (!secret_key) { RETURN_NULL(); } RETURN_STRINGL((char *) secret_key, 32); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getSecretKey_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getPublicTxt) { php_zmq_cert_object *intern; char *public_txt; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; public_txt = zcert_public_txt(intern->zcert); if (!public_txt) { RETURN_NULL(); } RETURN_STRING(public_txt); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getPublicTxt_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getSecretTxt) { php_zmq_cert_object *intern; char *secret_txt; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; secret_txt = zcert_secret_txt(intern->zcert); if (!secret_txt) { RETURN_NULL(); } RETURN_STRING(secret_txt); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getSecretTxt_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, setMeta) { php_zmq_cert_object *intern; zend_string *name; zend_string *format; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &name, &format) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; zcert_set_meta(intern->zcert, name->val, format->val); return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_setMeta_args, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getMeta) { zend_string *name; php_zmq_cert_object *intern; char *result; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; result = zcert_meta(intern->zcert, name->val); if (!result) { RETURN_NULL(); } RETURN_STRING(result); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getMeta_args, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, getMetaKeys) { php_zmq_cert_object *intern; zlist_t *meta_keys; char *meta_key; if (zend_parse_parameters_none() != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; meta_keys = zcert_meta_keys(intern->zcert); meta_key = (char *) zlist_first(meta_keys); array_init(return_value); while (meta_key) { add_next_index_string(return_value, meta_key); meta_key = zlist_next(meta_keys); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_getMetaKeys_args, 0, 0, 0) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, save) { php_zmq_cert_object *intern; zend_string *filename; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filename) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; if (zcert_save(intern->zcert, filename->val) == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to save the certificate to %s", filename->val); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_save_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, savePublic) { zend_string *filename; php_zmq_cert_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filename) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; if (zcert_save_public(intern->zcert, filename->val) == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to save the public certificate to %s", filename->val); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_savePublic_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, saveSecret) { zend_string *filename; php_zmq_cert_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filename) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; if (zcert_save_secret(intern->zcert, filename->val) == -1) { zend_throw_exception_ex(php_zmq_cert_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to save the secret certificate to %s", filename->val); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqcert_saveSecret_args, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() PHP_METHOD(zmqcert, apply) { php_zmq_cert_object *intern; zval *object; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &object, php_zmq_socket_sc_entry) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; zcert_apply(intern->zcert, php_zmq_socket_fetch_object(Z_OBJ_P(object))->socket->z_socket); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_apply_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQSocket, ZMQSocket, 0) ZEND_END_ARG_INFO() static zend_object *php_zmq_cert_clone(zval *object) { zend_object *result; php_zmq_cert_object *intern; php_zmq_cert_object *that; intern = php_zmq_cert_fetch_object(Z_OBJ_P(object)); result = php_zmq_cert_new(php_zmq_cert_sc_entry); that = php_zmq_cert_fetch_object(result); that->zcert = zcert_dup(intern->zcert); return result; } PHP_METHOD(zmqcert, equals) { php_zmq_cert_object *intern; zval *object; php_zmq_cert_object *that; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &object, php_zmq_cert_sc_entry) != SUCCESS) { return; } intern = PHP_ZMQ_CERT_OBJECT; that = php_zmq_cert_fetch_object(Z_OBJ_P(object)); RETURN_BOOL(zcert_eq(intern->zcert, that->zcert) == 1); } ZEND_BEGIN_ARG_INFO_EX(zmqcert_equals_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQCert, ZMQCert, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_cert_class_methods[] = { PHP_ME(zmqcert, __construct, zmqcert___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqcert, getPublicKey, zmqcert_getPublicKey_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getSecretKey, zmqcert_getSecretKey_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getPublicTxt, zmqcert_getPublicTxt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getSecretTxt, zmqcert_getSecretTxt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, setMeta, zmqcert_setMeta_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getMeta, zmqcert_getMeta_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, getMetaKeys, zmqcert_getMetaKeys_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, save, zmqcert_save_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, savePublic, zmqcert_savePublic_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, saveSecret, zmqcert_saveSecret_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcert, apply, zmqcert_apply_args, ZEND_ACC_PUBLIC) /* PHP_ME(zmqcert, __clone, zmqcert___clone_args, ZEND_ACC_PUBLIC) */ PHP_ME(zmqcert, equals, zmqcert_equals_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* --- END ZMQCert --- */ /* --- START ZMQAuth --- */ static void php_zmq_auth_object_free_storage(zend_object *object) { php_zmq_auth_object *intern = php_zmq_auth_fetch_object(object); if (!intern) { return; } if (intern->zauth) { zauth_destroy(&intern->zauth); } if (intern->shadow_context) { zctx_destroy(&intern->shadow_context); } zend_object_std_dtor(&intern->zo); } static zend_object *php_zmq_auth_new(zend_class_entry *class_type) { php_zmq_auth_object *intern = ecalloc(1, sizeof(php_zmq_auth_object) + zend_object_properties_size(class_type)); /* zcert is initialised in ZMQCert#__construct. */ intern->zauth = NULL; zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_auth_object_handlers; return &intern->zo; } PHP_METHOD(zmqauth, __construct) { php_zmq_auth_object *intern; zval *object; zend_error_handling error_handling; int parse_parameters_result; php_zmq_context_object *context_object; zend_replace_error_handling(EH_THROW, php_zmq_cert_exception_sc_entry, &error_handling); parse_parameters_result = zend_parse_parameters(ZEND_NUM_ARGS(), "O", &object, php_zmq_context_sc_entry); zend_restore_error_handling(&error_handling); if (parse_parameters_result != SUCCESS) { return; } intern = PHP_ZMQ_AUTH_OBJECT; context_object = php_zmq_context_fetch_object(Z_OBJ_P(object)); // NOTE (phuedx, 2014-05-14): A zauth object needs a context so that it // can take over authentication for all incoming connections in that // context. Creating a shadow context from the specified context allows // us to continue working with CZMQ. intern->shadow_context = zctx_shadow_zmq_ctx(context_object->context->z_ctx); if (!intern->shadow_context) { zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to create the underlying shadow context object."); return; } intern->zauth = zauth_new(intern->shadow_context); if (!intern->zauth) { zctx_destroy(&intern->shadow_context); zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Failed to create the underlying zauth object."); } return; } ZEND_BEGIN_ARG_INFO_EX(zmqauth___construct_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, ZMQContext, ZMQContext, 0) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, allow) { zend_string *address; php_zmq_auth_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &address) != SUCCESS) { return; } intern = PHP_ZMQ_AUTH_OBJECT; zauth_allow(intern->zauth, address->val); RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_allow_args, 0, 0, 1) ZEND_ARG_INFO(0, address) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, deny) { zend_string *address; php_zmq_auth_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &address) != SUCCESS) { return; } intern = PHP_ZMQ_AUTH_OBJECT; zauth_deny(intern->zauth, address->val); RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_deny_args, 0, 0, 1) ZEND_ARG_INFO(0, address) ZEND_END_ARG_INFO(); PHP_METHOD(zmqauth, configure) { php_zmq_auth_object *intern; zend_long type; zend_string *domain; zend_string *filename; intern = PHP_ZMQ_AUTH_OBJECT if (zend_parse_parameters(ZEND_NUM_ARGS(), "lSS", &type, &domain, &filename) != SUCCESS) { return; } intern = PHP_ZMQ_AUTH_OBJECT; switch (type) { case PHP_ZMQ_AUTH_TYPE_PLAIN: zauth_configure_plain(intern->zauth, domain->val, filename->val); break; case PHP_ZMQ_AUTH_TYPE_CURVE: zauth_configure_curve(intern->zauth, domain->val, filename->val); break; // TODO (phuedx, 2014-05-16): CZMQ now supports GSSAPI (see // zauth_configure_gssapi). default: zend_throw_exception_ex(php_zmq_auth_exception_sc_entry, PHP_ZMQ_INTERNAL_ERROR, "Unknown auth type. Are you using one of the ZMQAuth constants?"); break; } RETURN_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(zmqauth_configure_args, 0, 0, 3) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, domain) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO(); static zend_function_entry php_zmq_auth_class_methods[] = { PHP_ME(zmqauth, __construct, zmqauth___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqauth, allow, zmqauth_allow_args, ZEND_ACC_PUBLIC) PHP_ME(zmqauth, deny, zmqauth_deny_args, ZEND_ACC_PUBLIC) PHP_ME(zmqauth, configure, zmqauth_configure_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* --- END ZMQAuth --- */ #endif // HAVE_CZMQ_2 ZEND_BEGIN_ARG_INFO_EX(zmq_construct_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_clock_args, 0, 0, 0) ZEND_END_ARG_INFO() #ifdef PHP_ZMQ_HAVE_Z85 ZEND_BEGIN_ARG_INFO_EX(zmq_z85encode_args, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_z85decode_args, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() #endif #ifdef PHP_ZMQ_HAVE_CURVE_KEYPAIR ZEND_BEGIN_ARG_INFO_EX(zmq_curvekeypair_args, 0, 0, 0) ZEND_END_ARG_INFO() #endif static zend_function_entry php_zmq_class_methods[] = { PHP_ME(zmq, __construct, zmq_construct_args, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(zmq, clock, zmq_clock_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #ifdef PHP_ZMQ_HAVE_Z85 PHP_ME(zmq, z85encode, zmq_z85encode_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(zmq, z85decode, zmq_z85decode_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif #ifdef PHP_ZMQ_HAVE_CURVE_KEYPAIR PHP_ME(zmq, curvekeypair, zmq_curvekeypair_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_context_construct_args, 0, 0, 0) ZEND_ARG_INFO(0, io_threads) ZEND_ARG_INFO(0, persistent) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_acquire_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_getsocketcount_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_getsocket_args, 0, 0, 2) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, on_new_socket) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_ispersistent_args, 0, 0, 2) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() #ifdef PHP_ZMQ_HAVE_CTX_OPTIONS ZEND_BEGIN_ARG_INFO_EX(zmq_context_setopt_args, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_context_getopt_args, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_END_ARG_INFO() #endif static zend_function_entry php_zmq_context_class_methods[] = { PHP_ME(zmqcontext, __construct, zmq_context_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqcontext, acquire, zmq_context_acquire_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(zmqcontext, getsocketcount, zmq_context_getsocketcount_args,ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, getsocket, zmq_context_getsocket_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, ispersistent, zmq_context_ispersistent_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, __clone, zmq_context_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) #ifdef PHP_ZMQ_HAVE_CTX_OPTIONS PHP_ME(zmqcontext, setOpt, zmq_context_setopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqcontext, getOpt, zmq_context_getopt_args, ZEND_ACC_PUBLIC) #endif {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_socket_construct_args, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, ZMQContext, ZMQContext, 0) ZEND_ARG_INFO(0, type) ZEND_ARG_INFO(0, persistent_id) ZEND_ARG_INFO(0, on_new_socket) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_bind_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_connect_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() #ifdef PHP_ZMQ_HAVE_SOCKET_MONITOR ZEND_BEGIN_ARG_INFO_EX(zmq_socket_monitor_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, events) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_recvevent_args, 0, 0, 0) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() #endif #ifdef PHP_ZMQ_HAVE_UNBIND ZEND_BEGIN_ARG_INFO_EX(zmq_socket_unbind_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_END_ARG_INFO() #endif #ifdef PHP_ZMQ_HAVE_DISCONNECT ZEND_BEGIN_ARG_INFO_EX(zmq_socket_disconnect_args, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_INFO_EX(zmq_socket_setsockopt_args, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getendpoints_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getsockettype_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_send_args, 0, 0, 1) ZEND_ARG_INFO(0, message) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_recv_args, 0, 0, 0) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getpersistentid_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_getsockopt_args, 0, 0, 1) ZEND_ARG_INFO(0, key) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_ispersistent_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_socket_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_socket_class_methods[] = { PHP_ME(zmqsocket, __construct, zmq_socket_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqsocket, send, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, recv, zmq_socket_recv_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, sendmulti, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, recvmulti, zmq_socket_recv_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, bind, zmq_socket_bind_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, connect, zmq_socket_connect_args, ZEND_ACC_PUBLIC) #ifdef PHP_ZMQ_HAVE_SOCKET_MONITOR PHP_ME(zmqsocket, monitor, zmq_socket_monitor_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, recvevent, zmq_socket_recvevent_args, ZEND_ACC_PUBLIC) #endif #ifdef PHP_ZMQ_HAVE_UNBIND PHP_ME(zmqsocket, unbind, zmq_socket_unbind_args, ZEND_ACC_PUBLIC) #endif #ifdef PHP_ZMQ_HAVE_DISCONNECT PHP_ME(zmqsocket, disconnect, zmq_socket_disconnect_args, ZEND_ACC_PUBLIC) #endif PHP_ME(zmqsocket, setsockopt, zmq_socket_setsockopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getendpoints, zmq_socket_getendpoints_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getsockettype, zmq_socket_getsockettype_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, ispersistent, zmq_socket_ispersistent_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getpersistentid, zmq_socket_getpersistentid_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, getsockopt, zmq_socket_getsockopt_args, ZEND_ACC_PUBLIC) PHP_ME(zmqsocket, __clone, zmq_socket_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) PHP_MALIAS(zmqsocket, sendmsg, send, zmq_socket_send_args, ZEND_ACC_PUBLIC) PHP_MALIAS(zmqsocket, recvmsg, recv, zmq_socket_recv_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_poll_add_args, 0, 0, 2) ZEND_ARG_INFO(0, entry) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_poll_args, 0, 0, 2) ZEND_ARG_INFO(1, readable) ZEND_ARG_INFO(1, writable) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_getlasterrors_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_remove_args, 0, 0, 2) ZEND_ARG_INFO(0, remove) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_count_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_clear_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_items_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_poll_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_poll_class_methods[] = { PHP_ME(zmqpoll, add, zmq_poll_add_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, poll, zmq_poll_poll_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, getlasterrors, zmq_poll_getlasterrors_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, remove, zmq_poll_remove_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, count, zmq_poll_count_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, clear, zmq_poll_clear_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, items, zmq_poll_items_args, ZEND_ACC_PUBLIC) PHP_ME(zmqpoll, __clone, zmq_poll_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; ZEND_BEGIN_ARG_INFO_EX(zmq_device_construct_args, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, frontend, ZMQSocket, 0) ZEND_ARG_OBJ_INFO(0, backend, ZMQSocket, 0) ZEND_ARG_OBJ_INFO(0, capture, ZMQSocket, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_run_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_setidlecallback_args, 0, 0, 2) ZEND_ARG_INFO(0, idle_callback) ZEND_ARG_INFO(0, timeout) ZEND_ARG_INFO(0, user_data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_settimercallback_args, 0, 0, 2) ZEND_ARG_INFO(0, idle_callback) ZEND_ARG_INFO(0, timeout) ZEND_ARG_INFO(0, user_data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_setidletimeout_args, 0, 0, 1) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_settimertimeout_args, 0, 0, 1) ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_getidletimeout_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_gettimertimeout_args, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(zmq_device_clone_args, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry php_zmq_device_class_methods[] = { PHP_ME(zmqdevice, __construct, zmq_device_construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) PHP_ME(zmqdevice, run, zmq_device_run_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, setidlecallback, zmq_device_setidlecallback_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, setidletimeout, zmq_device_setidletimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, getidletimeout, zmq_device_getidletimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, settimercallback, zmq_device_settimercallback_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, settimertimeout, zmq_device_settimertimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, gettimertimeout, zmq_device_gettimertimeout_args, ZEND_ACC_PUBLIC) PHP_ME(zmqdevice, __clone, zmq_device_clone_args, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; zend_function_entry zmq_functions[] = { {NULL, NULL, NULL} }; static void php_zmq_context_object_free_storage(zend_object *object) { php_zmq_context_object *intern = php_zmq_context_fetch_object(object); if (!intern) { return; } if (intern->context) { if (!intern->context->is_persistent) { php_zmq_context_destroy(intern->context); } } zend_object_std_dtor(&intern->zo); } static void php_zmq_socket_object_free_storage(zend_object *object) { php_zmq_socket_object *intern = php_zmq_socket_fetch_object(object); if (!intern) { return; } if (intern->socket) { if (intern->socket->is_persistent && intern->persistent_id) { efree(intern->persistent_id); } if (!intern->socket->is_persistent) { php_zmq_socket_destroy(intern->socket); } } if (!Z_ISUNDEF(intern->context_obj)) { zval_ptr_dtor(&intern->context_obj); } zend_object_std_dtor(&intern->zo); } static void php_zmq_poll_object_free_storage(zend_object *object) { php_zmq_poll_object *intern = php_zmq_poll_fetch_object(object); if (!intern) { return; } php_zmq_pollset_destroy(&intern->set); zend_object_std_dtor(&intern->zo); } static void php_zmq_device_object_free_storage(zend_object *object) { php_zmq_device_object *intern = php_zmq_device_fetch_object(object); if (!intern) { return; } s_clear_device_callback (&intern->idle_cb); s_clear_device_callback (&intern->timer_cb); if (!Z_ISUNDEF(intern->front)) { zval_ptr_dtor(&intern->front); } if (!Z_ISUNDEF(intern->back)) { zval_ptr_dtor(&intern->back); } if (!Z_ISUNDEF(intern->capture)) { zval_ptr_dtor(&intern->capture); } zend_object_std_dtor(&intern->zo); } static zend_object *php_zmq_context_object_new_ex(zend_class_entry *class_type, php_zmq_context_object **ptr) { php_zmq_context_object *intern = ecalloc(1, sizeof(php_zmq_context_object) + zend_object_properties_size(class_type)); /* Context is initialized in the constructor */ intern->context = NULL; if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_context_object_handlers; return &intern->zo; } static zend_object *php_zmq_socket_object_new_ex(zend_class_entry *class_type, php_zmq_socket_object **ptr) { php_zmq_socket_object *intern; /* Allocate memory for it */ intern = ecalloc(1, sizeof(php_zmq_socket_object) + zend_object_properties_size(class_type)); intern->socket = NULL; intern->persistent_id = NULL; ZVAL_UNDEF(&intern->context_obj); if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_socket_object_handlers; return &intern->zo; } static zend_object *php_zmq_poll_object_new_ex(zend_class_entry *class_type, php_zmq_poll_object **ptr) { php_zmq_poll_object *intern = ecalloc(1, sizeof(php_zmq_poll_object) + zend_object_properties_size(class_type)); intern->set = php_zmq_pollset_init(); if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_poll_object_handlers; return &intern->zo; } static zend_object *php_zmq_device_object_new_ex(zend_class_entry *class_type, php_zmq_device_object **ptr) { php_zmq_device_object *intern = ecalloc(1, sizeof(php_zmq_device_object) + zend_object_properties_size(class_type)); memset (&intern->idle_cb, 0, sizeof (php_zmq_device_cb_t)); memset (&intern->timer_cb, 0, sizeof (php_zmq_device_cb_t)); ZVAL_UNDEF(&intern->front); ZVAL_UNDEF(&intern->back); ZVAL_UNDEF(&intern->capture); if (ptr) { *ptr = intern; } zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &zmq_device_object_handlers; return &intern->zo; } static zend_object *php_zmq_context_object_new(zend_class_entry *class_type) { return php_zmq_context_object_new_ex(class_type, NULL); } static zend_object *php_zmq_socket_object_new(zend_class_entry *class_type) { return php_zmq_socket_object_new_ex(class_type, NULL); } static zend_object *php_zmq_poll_object_new(zend_class_entry *class_type) { return php_zmq_poll_object_new_ex(class_type, NULL); } static zend_object *php_zmq_device_object_new(zend_class_entry *class_type) { return php_zmq_device_object_new_ex(class_type, NULL); } ZEND_RSRC_DTOR_FUNC(php_zmq_context_dtor) { if (res->ptr) { php_zmq_context *ctx = (php_zmq_context *)res->ptr; php_zmq_context_destroy(ctx); res->ptr = NULL; } } ZEND_RSRC_DTOR_FUNC(php_zmq_socket_dtor) { if (res->ptr) { php_zmq_socket *zms = (php_zmq_socket *)res->ptr; php_zmq_socket_destroy(zms); res->ptr = NULL; } } static void php_zmq_init_globals (zend_php_zmq_globals *zmq_globals) { zmq_globals->clock_ctx = NULL; } PHP_MINIT_FUNCTION(zmq) { char *version; zend_class_entry ce, ce_context, ce_socket, ce_poll, ce_device; zend_class_entry ce_exception, ce_context_exception, ce_socket_exception, ce_poll_exception, ce_device_exception; #ifdef HAVE_CZMQ_2 zend_class_entry ce_cert, ce_cert_exception, ce_auth, ce_auth_exception; #endif le_zmq_context = zend_register_list_destructors_ex(NULL, php_zmq_context_dtor, "ZMQ persistent context", module_number); le_zmq_socket = zend_register_list_destructors_ex(NULL, php_zmq_socket_dtor, "ZMQ persistent socket", module_number); memcpy(&zmq_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_context_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_socket_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_poll_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_device_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); #ifdef HAVE_CZMQ_2 memcpy(&zmq_cert_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&zmq_auth_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); #endif INIT_CLASS_ENTRY(ce, "ZMQ", php_zmq_class_methods); ce.create_object = NULL; zmq_object_handlers.clone_obj = NULL; php_zmq_sc_entry = zend_register_internal_class(&ce); INIT_CLASS_ENTRY(ce_context, "ZMQContext", php_zmq_context_class_methods); ce_context.create_object = php_zmq_context_object_new; zmq_context_object_handlers.offset = XtOffsetOf(php_zmq_context_object, zo); zmq_context_object_handlers.clone_obj = NULL; zmq_context_object_handlers.free_obj = php_zmq_context_object_free_storage; php_zmq_context_sc_entry = zend_register_internal_class(&ce_context); INIT_CLASS_ENTRY(ce_socket, "ZMQSocket", php_zmq_socket_class_methods); ce_socket.create_object = php_zmq_socket_object_new; zmq_socket_object_handlers.offset = XtOffsetOf(php_zmq_socket_object, zo); zmq_socket_object_handlers.clone_obj = NULL; zmq_socket_object_handlers.free_obj = php_zmq_socket_object_free_storage; php_zmq_socket_sc_entry = zend_register_internal_class(&ce_socket); INIT_CLASS_ENTRY(ce_poll, "ZMQPoll", php_zmq_poll_class_methods); ce_poll.create_object = php_zmq_poll_object_new; zmq_poll_object_handlers.offset = XtOffsetOf(php_zmq_poll_object, zo); zmq_poll_object_handlers.clone_obj = NULL; zmq_poll_object_handlers.free_obj = php_zmq_poll_object_free_storage; php_zmq_poll_sc_entry = zend_register_internal_class(&ce_poll); INIT_CLASS_ENTRY(ce_device, "ZMQDevice", php_zmq_device_class_methods); ce_device.create_object = php_zmq_device_object_new; zmq_device_object_handlers.offset = XtOffsetOf(php_zmq_device_object, zo); zmq_device_object_handlers.clone_obj = NULL; zmq_device_object_handlers.free_obj = php_zmq_device_object_free_storage; php_zmq_device_sc_entry = zend_register_internal_class(&ce_device); #ifdef HAVE_CZMQ_2 INIT_CLASS_ENTRY(ce_cert, "ZMQCert", php_zmq_cert_class_methods); ce_cert.create_object = php_zmq_cert_new; zmq_cert_object_handlers.offset = XtOffsetOf(php_zmq_cert_object, zo); zmq_cert_object_handlers.clone_obj = php_zmq_cert_clone; zmq_cert_object_handlers.free_obj = php_zmq_cert_object_free_storage; php_zmq_cert_sc_entry = zend_register_internal_class(&ce_cert); INIT_CLASS_ENTRY(ce_auth, "ZMQAuth", php_zmq_auth_class_methods); ce_auth.create_object = php_zmq_auth_new; zmq_auth_object_handlers.offset = XtOffsetOf(php_zmq_auth_object, zo); zmq_auth_object_handlers.clone_obj = NULL; zmq_auth_object_handlers.free_obj = php_zmq_auth_object_free_storage; php_zmq_auth_sc_entry = zend_register_internal_class(&ce_auth); #endif INIT_CLASS_ENTRY(ce_exception, "ZMQException", NULL); php_zmq_exception_sc_entry = zend_register_internal_class_ex(&ce_exception, zend_exception_get_default()); php_zmq_exception_sc_entry->ce_flags &= ~ZEND_ACC_FINAL; INIT_CLASS_ENTRY(ce_context_exception, "ZMQContextException", NULL); php_zmq_context_exception_sc_entry = zend_register_internal_class_ex(&ce_context_exception, php_zmq_exception_sc_entry); php_zmq_context_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; INIT_CLASS_ENTRY(ce_socket_exception, "ZMQSocketException", NULL); php_zmq_socket_exception_sc_entry = zend_register_internal_class_ex(&ce_socket_exception, php_zmq_exception_sc_entry); php_zmq_socket_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; INIT_CLASS_ENTRY(ce_poll_exception, "ZMQPollException", NULL); php_zmq_poll_exception_sc_entry = zend_register_internal_class_ex(&ce_poll_exception, php_zmq_exception_sc_entry); php_zmq_poll_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; INIT_CLASS_ENTRY(ce_device_exception, "ZMQDeviceException", NULL); php_zmq_device_exception_sc_entry = zend_register_internal_class_ex(&ce_device_exception, php_zmq_exception_sc_entry); php_zmq_device_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; #ifdef HAVE_CZMQ_2 INIT_CLASS_ENTRY(ce_cert_exception, "ZMQCertException", NULL); php_zmq_cert_exception_sc_entry = zend_register_internal_class_ex(&ce_cert_exception, php_zmq_exception_sc_entry); php_zmq_cert_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; INIT_CLASS_ENTRY(ce_auth_exception, "ZMQAuthException", NULL); php_zmq_auth_exception_sc_entry = zend_register_internal_class_ex(&ce_auth_exception, php_zmq_exception_sc_entry); php_zmq_auth_exception_sc_entry->ce_flags |= ZEND_ACC_FINAL; #endif ZEND_INIT_MODULE_GLOBALS(php_zmq, php_zmq_init_globals, NULL); ZMQ_G(clock_ctx) = php_zmq_clock_init (); if (!ZMQ_G(clock_ctx)) { php_error_docref(NULL, E_WARNING, "Failed to initialise clock"); return FAILURE; } #define PHP_ZMQ_REGISTER_CONST_LONG(const_name, value) \ zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value); #define PHP_ZMQ_REGISTER_CONST_STRING(const_name, value) \ zend_declare_class_constant_string (php_zmq_sc_entry, const_name, sizeof(const_name)-1, value); #define PHP_ZMQ_REGISTER_CONST_BOOL(const_name, value) \ zend_declare_class_constant_bool (php_zmq_sc_entry, const_name, sizeof(const_name)-1, value); /* Socket constants */ PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PAIR", ZMQ_PAIR); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PUB", ZMQ_PUB); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_SUB", ZMQ_SUB); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_REQ", ZMQ_REQ); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_REP", ZMQ_REP); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XREQ", ZMQ_XREQ); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XREP", ZMQ_XREP); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PUSH", ZMQ_PUSH); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_PULL", ZMQ_PULL); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_DEALER", ZMQ_DEALER); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_ROUTER", ZMQ_ROUTER); #ifdef ZMQ_XSUB PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XSUB", ZMQ_XSUB); #endif #ifdef ZMQ_XPUB PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_XPUB", ZMQ_XPUB); #endif #ifdef ZMQ_STREAM PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_STREAM", ZMQ_STREAM); #endif /* 2.0? */ PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_UPSTREAM", ZMQ_PULL); PHP_ZMQ_REGISTER_CONST_LONG("SOCKET_DOWNSTREAM", ZMQ_PUSH); #ifdef ZMQ_SNDLABEL PHP_ZMQ_REGISTER_CONST_LONG("MODE_SNDLABEL", ZMQ_SNDLABEL); #endif PHP_ZMQ_REGISTER_CONST_LONG("POLL_IN", ZMQ_POLLIN); PHP_ZMQ_REGISTER_CONST_LONG("POLL_OUT", ZMQ_POLLOUT); PHP_ZMQ_REGISTER_CONST_LONG("MODE_SNDMORE", ZMQ_SNDMORE); PHP_ZMQ_REGISTER_CONST_LONG("MODE_NOBLOCK", ZMQ_DONTWAIT); PHP_ZMQ_REGISTER_CONST_LONG("MODE_DONTWAIT", ZMQ_DONTWAIT); PHP_ZMQ_REGISTER_CONST_LONG("ERR_INTERNAL", PHP_ZMQ_INTERNAL_ERROR); PHP_ZMQ_REGISTER_CONST_LONG("ERR_EAGAIN", EAGAIN); PHP_ZMQ_REGISTER_CONST_LONG("ERR_ENOTSUP", ENOTSUP); PHP_ZMQ_REGISTER_CONST_LONG("ERR_EFSM", EFSM); PHP_ZMQ_REGISTER_CONST_LONG("ERR_ETERM", ETERM); version = php_zmq_get_libzmq_version(); PHP_ZMQ_REGISTER_CONST_STRING("LIBZMQ_VER", version); PHP_ZMQ_REGISTER_CONST_STRING("LIBZMQ_VERSION", version); PHP_ZMQ_REGISTER_CONST_LONG("LIBZMQ_VERSION_ID", php_zmq_get_libzmq_version_id()); PHP_ZMQ_REGISTER_CONST_LONG("LIBZMQ_VERSION_MAJOR", ZMQ_VERSION_MAJOR); PHP_ZMQ_REGISTER_CONST_LONG("LIBZMQ_VERSION_MINOR", ZMQ_VERSION_MINOR); PHP_ZMQ_REGISTER_CONST_LONG("LIBZMQ_VERSION_PATCH", ZMQ_VERSION_PATCH); efree(version); php_zmq_register_sockopt_constants (php_zmq_sc_entry); #ifdef ZMQ_MAX_SOCKETS PHP_ZMQ_REGISTER_CONST_LONG("CTXOPT_MAX_SOCKETS", ZMQ_MAX_SOCKETS); #endif #ifdef ZMQ_MAX_SOCKETS_DFLT PHP_ZMQ_REGISTER_CONST_LONG("CTXOPT_MAX_SOCKETS_DEFAULT", ZMQ_MAX_SOCKETS_DFLT); #endif #ifdef HAVE_CZMQ_2 PHP_ZMQ_REGISTER_CONST_STRING("CURVE_ALLOW_ANY", CURVE_ALLOW_ANY); zend_declare_class_constant_long(php_zmq_auth_sc_entry, "AUTH_TYPE_PLAIN", 15, (long)PHP_ZMQ_AUTH_TYPE_PLAIN); zend_declare_class_constant_long(php_zmq_auth_sc_entry, "AUTH_TYPE_CURVE", 15, (long)PHP_ZMQ_AUTH_TYPE_CURVE); #endif #ifdef PHP_ZMQ_HAVE_SOCKET_MONITOR PHP_ZMQ_REGISTER_CONST_LONG("EVENT_CONNECTED", ZMQ_EVENT_CONNECTED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_CONNECT_DELAYED", ZMQ_EVENT_CONNECT_DELAYED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_CONNECT_RETRIED", ZMQ_EVENT_CONNECT_RETRIED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_LISTENING", ZMQ_EVENT_LISTENING); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_BIND_FAILED", ZMQ_EVENT_BIND_FAILED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_ACCEPTED", ZMQ_EVENT_ACCEPTED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_ACCEPT_FAILED", ZMQ_EVENT_ACCEPT_FAILED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_CLOSED", ZMQ_EVENT_CLOSED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_CLOSE_FAILED", ZMQ_EVENT_CLOSE_FAILED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_DISCONNECTED", ZMQ_EVENT_DISCONNECTED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_MONITOR_STOPPED", ZMQ_EVENT_MONITOR_STOPPED); PHP_ZMQ_REGISTER_CONST_LONG("EVENT_ALL", ZMQ_EVENT_ALL); #endif #undef PHP_ZMQ_REGISTER_CONST_LONG #undef PHP_ZMQ_REGISTER_CONST_STRING if (!php_zmq_shared_ctx_init()) { return FAILURE; } return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(zmq) { php_zmq_shared_ctx_destroy(); php_zmq_clock_destroy (&ZMQ_G (clock_ctx)); return SUCCESS; } PHP_MINFO_FUNCTION(zmq) { char *version = php_zmq_get_libzmq_version(); php_info_print_table_start(); php_info_print_table_header(2, "ZMQ extension", "enabled"); php_info_print_table_row(2, "ZMQ extension version", PHP_ZMQ_VERSION); php_info_print_table_row(2, "libzmq version", version); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); efree(version); } zend_module_entry zmq_module_entry = { STANDARD_MODULE_HEADER, PHP_ZMQ_EXTNAME, zmq_functions, /* Functions */ PHP_MINIT(zmq), /* MINIT */ PHP_MSHUTDOWN(zmq), /* MSHUTDOWN */ NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(zmq), /* MINFO */ PHP_ZMQ_VERSION, /* version */ STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_ZMQ ZEND_GET_MODULE(zmq) #endif /* COMPILE_DL_ZMQ */ zmq-1.1.3/zmq_device.c0000644000076500000240000002273312653534763011560 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ /* Based on zeromq 2.1.x devices, which is: Copyright (c) 2007-2011 iMatix Corporation Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file */ #include "php_zmq.h" #include "php_zmq_private.h" #include "zmq_object_access.c" ZEND_EXTERN_MODULE_GLOBALS(php_zmq) static zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRMLS_DC) { zend_bool retval = 0; zval params[1]; zval fc_retval; ZVAL_COPY(¶ms[0], &cb->user_data); cb->fci.params = params; cb->fci.param_count = 1; /* Call the cb */ cb->fci.no_separation = 1; cb->fci.retval = &fc_retval; if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) { if (!EG(exception)) { char *func_name = php_zmq_printable_func(&cb->fci, &cb->fci_cache); zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0 TSRMLS_CC, "Failed to invoke device callback %s()", func_name); zval_ptr_dtor(¶ms[0]); efree(func_name); } } if (!Z_ISUNDEF(fc_retval)) { retval = zval_is_true(&fc_retval); } zval_ptr_dtor(¶ms[0]); zval_ptr_dtor(&fc_retval); cb->scheduled_at = current_ts + cb->timeout; return retval; } static int s_capture_message (void *socket, zmq_msg_t *msg, int more) { int rc; zmq_msg_t msg_cp; rc = zmq_msg_init (&msg_cp); if (rc == -1) return -1; rc = zmq_msg_copy (&msg_cp, msg); if (rc == -1) { zmq_msg_close (&msg_cp); return -1; } return zmq_sendmsg (socket, &msg_cp, more ? ZMQ_SNDMORE : 0); } static int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC) { int timeout = -1; uint64_t current = php_zmq_clock (ZMQ_G (clock_ctx)); /* Do we have timer? */ if (intern->timer_cb.initialized && intern->timer_cb.timeout) { /* This is when we need to launch timer */ timeout = (int) (intern->timer_cb.scheduled_at - current); /* If we are tiny bit late, make sure it's asap */ if (timeout <= 0) { return 1 * PHP_ZMQ_TIMEOUT; } } /* Do we have idle callback? */ if (intern->idle_cb.initialized && intern->idle_cb.timeout) { /* Do we need to reduce next timing? */ int idle_timeout = (int) (intern->idle_cb.scheduled_at - current); /* Might happen if we get scheduled tiny bit late */ if (idle_timeout <= 0) { return 1 * PHP_ZMQ_TIMEOUT; } if (timeout == -1 || idle_timeout < timeout) timeout = idle_timeout; } if (timeout > 0) timeout *= PHP_ZMQ_TIMEOUT; return timeout; } zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) { int errno_; uint64_t last_message_received; void *capture_sock; php_zmq_socket_object *front, *back; zmq_msg_t msg; #if ZMQ_VERSION_MAJOR >= 3 int more; #else int64_t more; #endif #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 int label; size_t labelsz = sizeof(label); #endif size_t moresz; zmq_pollitem_t items [2]; int rc = zmq_msg_init (&msg); if (rc != 0) { return 0; } front = php_zmq_socket_fetch_object(Z_OBJ(intern->front)); back = php_zmq_socket_fetch_object(Z_OBJ(intern->back)); items [0].socket = front->socket->z_socket; items [0].fd = 0; items [0].events = ZMQ_POLLIN; items [0].revents = 0; items [1].socket = back->socket->z_socket; items [1].fd = 0; items [1].events = ZMQ_POLLIN; items [1].revents = 0; capture_sock = NULL; if (!Z_ISUNDEF(intern->capture)) { php_zmq_socket_object *capture = php_zmq_socket_fetch_object(Z_OBJ(intern->capture)); capture_sock = capture->socket->z_socket; } last_message_received = php_zmq_clock (ZMQ_G (clock_ctx)); intern->timer_cb.scheduled_at = last_message_received + intern->timer_cb.timeout; intern->idle_cb.scheduled_at = last_message_received + intern->idle_cb.timeout; while (1) { uint64_t current_ts = 0; /* Calculate poll_timeout based on idle / timer cb */ int timeout = s_calculate_timeout (intern TSRMLS_CC); rc = zmq_poll(&items [0], 2, timeout); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } current_ts = php_zmq_clock (ZMQ_G (clock_ctx)); if (rc > 0) last_message_received = current_ts; /* Do we have a timer callback? */ if (intern->timer_cb.initialized && intern->timer_cb.timeout > 0) { /* Is it timer to call the timer ? */ if (intern->timer_cb.scheduled_at <= current_ts) { if (!s_invoke_device_cb (&intern->timer_cb, current_ts TSRMLS_CC)) { zmq_msg_close (&msg); return 1; } } } /* Do we have a idle callback? */ if (rc == 0 && intern->idle_cb.initialized && intern->idle_cb.timeout > 0) { /* Is it timer to call the idle callback ? */ if ((current_ts - last_message_received) >= intern->idle_cb.timeout && intern->idle_cb.scheduled_at <= current_ts) { if (!s_invoke_device_cb (&intern->idle_cb, current_ts TSRMLS_CC)) { zmq_msg_close (&msg); return 1; } } continue; } if (items [0].revents & ZMQ_POLLIN) { while (1) { rc = zmq_recvmsg(items [0].socket, &msg, 0); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } moresz = sizeof(more); rc = zmq_getsockopt(items [0].socket, ZMQ_RCVMORE, &more, &moresz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 labelsz = sizeof(label); rc = zmq_getsockopt(items [0].socket, ZMQ_RCVLABEL, &label, &labelsz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } rc = zmq_sendmsg (items [1].socket, &msg, label ? ZMQ_SNDLABEL : (more ? ZMQ_SNDMORE : 0)); more = more | label; #else if (capture_sock) { rc = s_capture_message (capture_sock, &msg, more); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } } rc = zmq_sendmsg (items [1].socket, &msg, more ? ZMQ_SNDMORE : 0); #endif if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } if (!more) break; } } if (items [1].revents & ZMQ_POLLIN) { while (1) { rc = zmq_recvmsg(items [1].socket, &msg, 0); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } moresz = sizeof (more); rc = zmq_getsockopt(items [1].socket, ZMQ_RCVMORE, &more, &moresz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); return errno_; } #if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0 labelsz = sizeof(label); rc = zmq_getsockopt(items [1].socket, ZMQ_RCVLABEL, &label, &labelsz); if (rc < 0) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } rc = zmq_sendmsg (items [0].socket, &msg, label ? ZMQ_SNDLABEL : (more ? ZMQ_SNDMORE : 0)); more = more | label; #else if (capture_sock) { rc = s_capture_message (capture_sock, &msg, more); if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } } rc = zmq_sendmsg (items [0].socket, &msg, more ? ZMQ_SNDMORE : 0); #endif if (rc == -1) { errno_ = errno; zmq_msg_close (&msg); errno = errno_; return 0; } if (!more) break; } } } zmq_msg_close (&msg); return 0; } zmq-1.1.3/zmq_fd_stream.c0000644000076500000240000001025012653534763012254 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #include "zmq_object_access.c" #ifndef PHP_WIN32 typedef int fd_t; #else typedef SOCKET fd_t; #endif typedef struct _php_zmq_stream_container { zval object; } php_zmq_stream_container; static size_t php_zmq_fd_read(php_stream *stream, char *buf, size_t count) { return 0; } static size_t php_zmq_fd_write(php_stream *stream, const char *buf, size_t count) { return 0; } static int php_zmq_fd_close(php_stream *stream, int close_handle) { php_zmq_stream_container *container = (php_zmq_stream_container *) stream->abstract; zval_ptr_dtor(&(container->object)); efree (container); return EOF; } static int php_zmq_fd_flush(php_stream *stream) { return FAILURE; } static int php_zmq_fd_cast(php_stream *stream, int cast_as, void **ret) { php_zmq_stream_container *container = (php_zmq_stream_container *) stream->abstract; php_zmq_socket_object *intern = php_zmq_socket_fetch_object(Z_OBJ(container->object)); switch (cast_as) { case PHP_STREAM_AS_FD_FOR_SELECT: case PHP_STREAM_AS_FD: case PHP_STREAM_AS_SOCKETD: if (ret) { size_t optsiz = sizeof (fd_t); if (!intern->socket) { return FAILURE; } if (zmq_getsockopt(intern->socket->z_socket, ZMQ_FD, (fd_t *) ret, &optsiz) != 0) { return FAILURE; } } return SUCCESS; default: return FAILURE; } } static php_stream_ops php_stream_zmq_fd_ops = { php_zmq_fd_write, php_zmq_fd_read, php_zmq_fd_close, php_zmq_fd_flush, "ZMQ_FD", NULL, /* seek */ php_zmq_fd_cast, /* cast */ NULL, /* stat */ NULL /* set_option */ }; php_stream *php_zmq_create_zmq_fd(zval *obj) { php_stream *stream; php_zmq_stream_container *container; container = ecalloc(1, sizeof(php_zmq_stream_container)); stream = php_stream_alloc(&php_stream_zmq_fd_ops, container, NULL, "r"); if (stream) { ZVAL_COPY(&(container->object), obj); return stream; } return NULL; } /* }}} */ zmq-1.1.3/zmq_pollset.c0000644000076500000240000002351112653534763011776 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #include "php_zmq_pollset.h" #include "zmq_object_access.c" #include "ext/spl/php_spl.h" #define PHP_ZMQ_ALLOC_SIZE 20 /* {{{ typedef struct _php_zmq_pollset */ typedef struct _php_zmq_pollset { zmq_pollitem_t *items; zend_string **keys; zval *zv; size_t num_items; size_t allocated; size_t alloc_size; zval errors; } php_zmq_pollset; /* }}} */ static void s_pollset_clear(php_zmq_pollset *set, zend_bool reinit) { size_t i; if (set->items) { efree(set->items); } if (set->zv) { for (i = 0; i < set->num_items; i++) { zval_ptr_dtor(&set->zv[i]); } efree(set->zv); } if (set->keys) { for (i = 0; i < set->num_items; i++) { zend_string_release(set->keys[i]); } efree(set->keys); } if (reinit) { set->items = ecalloc(set->alloc_size, sizeof(zmq_pollitem_t)); set->keys = ecalloc(set->alloc_size, sizeof(zend_string *)); set->zv = ecalloc(set->alloc_size, sizeof(zval)); set->allocated = set->alloc_size; set->num_items = 0; } } static size_t s_pollset_append(php_zmq_pollset *set, zmq_pollitem_t *item, zend_string *key, zval *entry) { size_t index = set->num_items; if (set->allocated <= set->num_items + 1) { set->items = erealloc (set->items, (set->allocated + set->alloc_size) * sizeof(zmq_pollitem_t)); set->keys = erealloc (set->keys, (set->allocated + set->alloc_size) * sizeof(zend_string *)); set->zv = erealloc (set->zv, (set->allocated + set->alloc_size) * sizeof(zval)); set->allocated += set->alloc_size; } memcpy (&(set->items[index]), item, sizeof(zmq_pollitem_t)); set->keys[index] = key; ZVAL_COPY_VALUE(&set->zv[index], entry); Z_ADDREF(set->zv[index]); set->num_items++; return index; } static void s_pollset_delete(php_zmq_pollset *set, size_t index) { zend_string_release(set->keys[index]); zval_ptr_dtor(&set->zv[index]); memmove( set->items + index, set->items + index + 1, (set->num_items - index - 1) * sizeof(zmq_pollitem_t) ); memmove( set->keys + index, set->keys + index + 1, (set->num_items - index - 1) * sizeof(zend_string *) ); memmove( set->zv + index, set->zv + index + 1, (set->num_items - index - 1) * sizeof(zval) ); set->num_items--; if ((set->allocated - set->alloc_size > set->num_items) && (set->allocated - set->alloc_size > set->alloc_size)) { set->items = erealloc (set->items, (set->allocated - set->alloc_size) * sizeof(zmq_pollitem_t)); set->keys = erealloc (set->keys, (set->allocated - set->alloc_size) * sizeof(zend_string *)); set->zv = erealloc (set->zv, (set->allocated - set->alloc_size) * sizeof(zval)); set->allocated -= set->alloc_size; } } static zend_bool s_index_for_key(php_zmq_pollset *set, zend_string *key, size_t *index) { zend_bool retval = 0; size_t i; for (i = 0; i < set->num_items; i++) { if (zend_string_equals (set->keys[i], key)) { *index = i; retval = 1; break; } } return retval; } static zval *s_zval_for_index(php_zmq_pollset *set, size_t index) { return &set->zv[index]; } static zend_string *s_create_key(zval *entry) { if (Z_TYPE_P(entry) == IS_RESOURCE) { return strpprintf(0, "r:%ld", Z_RES_P(entry)->handle); } else { zend_string *hash = php_spl_object_hash(entry); zend_string *key = strpprintf(0, "o:%s", hash->val); zend_string_release(hash); return key; } } php_zmq_pollset *php_zmq_pollset_init() { php_zmq_pollset *set = ecalloc (1, sizeof(php_zmq_pollset)); array_init(&set->errors); set->items = ecalloc(PHP_ZMQ_ALLOC_SIZE, sizeof(zmq_pollitem_t)); set->keys = ecalloc(PHP_ZMQ_ALLOC_SIZE, sizeof(zend_string *)); set->zv = ecalloc(PHP_ZMQ_ALLOC_SIZE, sizeof(zval)); set->allocated = PHP_ZMQ_ALLOC_SIZE; set->alloc_size = PHP_ZMQ_ALLOC_SIZE; set->num_items = 0; return set; } zend_bool php_zmq_pollset_items(php_zmq_pollset *set, zval *return_value) { size_t i; if (set->num_items == 0) { return 0; } for (i = 0; i < set->num_items; i++) { zval *zv = s_zval_for_index(set, i); if (zv) { Z_ADDREF_P(zv); add_assoc_zval(return_value, set->keys[i]->val, zv); } } return 1; } size_t php_zmq_pollset_num_items(php_zmq_pollset *set) { return set->num_items; } zend_string *php_zmq_pollset_add(php_zmq_pollset *set, zval *entry, int events, int *error) { zend_string *key; size_t num_items, index; zmq_pollitem_t item; *error = 0; key = s_create_key(entry); // Does this already exist? if (s_index_for_key(set, key, &index)) { return key; } num_items = php_zmq_pollset_num_items(set); memset(&item, 0, sizeof(zmq_pollitem_t)); if (Z_TYPE_P(entry) == IS_RESOURCE) { int fd; php_stream *stream; php_stream_from_zval_no_verify(stream, entry); if (!stream) { *error = PHP_ZMQ_POLLSET_ERR_NO_STREAM; zend_string_release(key); return NULL; } if (php_stream_can_cast(stream, (PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL | PHP_STREAM_AS_SOCKETD) & ~REPORT_ERRORS) == FAILURE) { *error = PHP_ZMQ_POLLSET_ERR_CANNOT_CAST; zend_string_release(key); return NULL; } if (php_stream_cast(stream, (PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL | PHP_STREAM_AS_SOCKETD) & ~REPORT_ERRORS, (void*)&fd, 0) == FAILURE) { *error = PHP_ZMQ_POLLSET_ERR_CAST_FAILED; zend_string_release(key); return NULL; } item.fd = fd; item.socket = NULL; } else { php_zmq_socket_object *intern = php_zmq_socket_fetch_object(Z_OBJ_P(entry)); item.socket = intern->socket->z_socket; item.fd = 0; } item.events = events; s_pollset_append(set, &item, zend_string_copy(key), entry); return key; } zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, zend_string *key) { size_t index; if (!s_index_for_key(set, key, &index)) { return 0; } s_pollset_delete(set, index); return 1; } zend_bool php_zmq_pollset_delete(php_zmq_pollset *set, zval *entry) { zend_bool retval; zend_string *key = s_create_key(entry); retval = php_zmq_pollset_delete_by_key(set, key); zend_string_release(key); return retval; } int php_zmq_pollset_poll(php_zmq_pollset *set, int timeout, zval *r_array, zval *w_array) { int rc, i; zend_bool readable = 0, writable = 0; if (!set->items) { return -1; } zend_hash_clean(Z_ARRVAL(set->errors)); if (r_array && Z_TYPE_P(r_array) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(r_array)) > 0) { zend_hash_clean(Z_ARRVAL_P(r_array)); } readable = 1; } if (w_array && Z_TYPE_P(w_array) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(w_array)) > 0) { zend_hash_clean(Z_ARRVAL_P(w_array)); } writable = 1; } rc = zmq_poll(set->items, set->num_items, timeout); if (rc == -1) { return -1; } if (rc > 0) { for (i = 0; i < set->num_items; i++) { if (readable && set->items[i].revents & ZMQ_POLLIN) { zval *zv = s_zval_for_index(set, i); if (zv) { Z_ADDREF_P(zv); add_next_index_zval(r_array, zv); } } if (writable && set->items[i].revents & ZMQ_POLLOUT) { zval *zv = s_zval_for_index(set, i); if (zv) { Z_ADDREF_P(zv); add_next_index_zval(w_array, zv); } } if (set->items[i].revents & ZMQ_POLLERR) { add_next_index_str(&set->errors, zend_string_copy(set->keys[i])); } } } return rc; } void php_zmq_pollset_clear(php_zmq_pollset *set) { // Clear errors zend_hash_clean(Z_ARRVAL(set->errors)); // clear the pollset s_pollset_clear(set, 1); } zval *php_zmq_pollset_errors(php_zmq_pollset *set) { return &set->errors; } void php_zmq_pollset_destroy(php_zmq_pollset **ptr) { php_zmq_pollset *set = *ptr; // clear the pollset s_pollset_clear(set, 0); // Errors zval_dtor(&(set->errors)); efree(set); *ptr = NULL; } zmq-1.1.3/zmq_sockopt.c0000644000076500000240000037104412653534763012005 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2016, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ /* WARNING! WARNING! This file is generated code. See README for editing */ #include "php_zmq.h" #include "php_zmq_private.h" #include "zmq_object_access.c" /* sockopts_register.gsl */ void php_zmq_register_sockopt_constants (zend_class_entry *php_zmq_sc_entry) { #define PHP_ZMQ_REGISTER_SOCKOPT(const_name, value) zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name) - 1, value); #if ZMQ_VERSION_MAJOR == 4 # ifdef ZMQ_HEARTBEAT_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HEARTBEAT_IVL", ZMQ_HEARTBEAT_IVL); # endif # ifdef ZMQ_HEARTBEAT_TTL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HEARTBEAT_TTL", ZMQ_HEARTBEAT_TTL); # endif # ifdef ZMQ_HEARTBEAT_TIMEOUT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HEARTBEAT_TIMEOUT", ZMQ_HEARTBEAT_TIMEOUT); # endif # ifdef ZMQ_TOS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TOS", ZMQ_TOS); # endif # ifdef ZMQ_ROUTER_HANDOVER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_HANDOVER", ZMQ_ROUTER_HANDOVER); # endif # ifdef ZMQ_ROUTER_MANDATORY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_MANDATORY", ZMQ_ROUTER_MANDATORY); # endif # ifdef ZMQ_PROBE_ROUTER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PROBE_ROUTER", ZMQ_PROBE_ROUTER); # endif # ifdef ZMQ_REQ_RELAXED PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_REQ_RELAXED", ZMQ_REQ_RELAXED); # endif # ifdef ZMQ_REQ_CORRELATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_REQ_CORRELATE", ZMQ_REQ_CORRELATE); # endif # ifdef ZMQ_CONFLATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CONFLATE", ZMQ_CONFLATE); # endif # ifdef ZMQ_ZAP_DOMAIN PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ZAP_DOMAIN", ZMQ_ZAP_DOMAIN); # endif # ifdef ZMQ_MECHANISM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MECHANISM", ZMQ_MECHANISM); # endif # ifdef ZMQ_PLAIN_SERVER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_SERVER", ZMQ_PLAIN_SERVER); # endif # ifdef ZMQ_PLAIN_USERNAME PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_USERNAME", ZMQ_PLAIN_USERNAME); # endif # ifdef ZMQ_PLAIN_PASSWORD PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_PLAIN_PASSWORD", ZMQ_PLAIN_PASSWORD); # endif # ifdef ZMQ_CURVE_SERVER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SERVER", ZMQ_CURVE_SERVER); # endif # ifdef ZMQ_CURVE_PUBLICKEY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_PUBLICKEY", ZMQ_CURVE_PUBLICKEY); # endif # ifdef ZMQ_CURVE_SECRETKEY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SECRETKEY", ZMQ_CURVE_SECRETKEY); # endif # ifdef ZMQ_CURVE_SERVERKEY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_CURVE_SERVERKEY", ZMQ_CURVE_SERVERKEY); # endif # ifdef ZMQ_GSSAPI_SERVER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_GSSAPI_SERVER", ZMQ_GSSAPI_SERVER); # endif # ifdef ZMQ_GSSAPI_PLAINTEXT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_GSSAPI_PLAINTEXT", ZMQ_GSSAPI_PLAINTEXT); # endif # ifdef ZMQ_GSSAPI_PRINCIPAL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_GSSAPI_PRINCIPAL", ZMQ_GSSAPI_PRINCIPAL); # endif # ifdef ZMQ_GSSAPI_SERVICE_PRINCIPAL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_GSSAPI_SERVICE_PRINCIPAL", ZMQ_GSSAPI_SERVICE_PRINCIPAL); # endif # ifdef ZMQ_IPV6 PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV6", ZMQ_IPV6); # endif # ifdef ZMQ_IMMEDIATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IMMEDIATE", ZMQ_IMMEDIATE); # endif # ifdef ZMQ_ROUTER_RAW PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_RAW", ZMQ_ROUTER_RAW); # endif # ifdef ZMQ_IPV4ONLY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV4ONLY", ZMQ_IPV4ONLY); # endif # ifdef ZMQ_DELAY_ATTACH_ON_CONNECT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_DELAY_ATTACH_ON_CONNECT", ZMQ_DELAY_ATTACH_ON_CONNECT); # endif # ifdef ZMQ_TYPE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE); # endif # ifdef ZMQ_SNDHWM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDHWM", ZMQ_SNDHWM); # endif # ifdef ZMQ_RCVHWM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); # endif # ifdef ZMQ_AFFINITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY); # endif # ifdef ZMQ_SUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE); # endif # ifdef ZMQ_UNSUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE); # endif # ifdef ZMQ_IDENTITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY); # endif # ifdef ZMQ_RATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE); # endif # ifdef ZMQ_RECOVERY_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL); # endif # ifdef ZMQ_SNDBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF); # endif # ifdef ZMQ_RCVBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF); # endif # ifdef ZMQ_LINGER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER); # endif # ifdef ZMQ_RECONNECT_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL); # endif # ifdef ZMQ_RECONNECT_IVL_MAX PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX); # endif # ifdef ZMQ_BACKLOG PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG); # endif # ifdef ZMQ_MAXMSGSIZE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MAXMSGSIZE", ZMQ_MAXMSGSIZE); # endif # ifdef ZMQ_MULTICAST_HOPS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MULTICAST_HOPS", ZMQ_MULTICAST_HOPS); # endif # ifdef ZMQ_RCVTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO); # endif # ifdef ZMQ_SNDTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO); # endif # ifdef ZMQ_XPUB_VERBOSE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_XPUB_VERBOSE", ZMQ_XPUB_VERBOSE); # endif # ifdef ZMQ_TCP_KEEPALIVE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE", ZMQ_TCP_KEEPALIVE); # endif # ifdef ZMQ_TCP_KEEPALIVE_IDLE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_IDLE", ZMQ_TCP_KEEPALIVE_IDLE); # endif # ifdef ZMQ_TCP_KEEPALIVE_CNT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_CNT", ZMQ_TCP_KEEPALIVE_CNT); # endif # ifdef ZMQ_TCP_KEEPALIVE_INTVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_INTVL", ZMQ_TCP_KEEPALIVE_INTVL); # endif # ifdef ZMQ_TCP_ACCEPT_FILTER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_ACCEPT_FILTER", ZMQ_TCP_ACCEPT_FILTER); # endif # ifdef ZMQ_RCVMORE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE); # endif # ifdef ZMQ_FD PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD); # endif # ifdef ZMQ_EVENTS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS); # endif # ifdef ZMQ_LAST_ENDPOINT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LAST_ENDPOINT", ZMQ_LAST_ENDPOINT); # endif #endif /* ZMQ_MAJOR_VERSION == 4 */ #if ZMQ_VERSION_MAJOR == 3 # ifdef ZMQ_ROUTER_RAW PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_ROUTER_RAW", ZMQ_ROUTER_RAW); # endif # ifdef ZMQ_IPV4ONLY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IPV4ONLY", ZMQ_IPV4ONLY); # endif # ifdef ZMQ_DELAY_ATTACH_ON_CONNECT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_DELAY_ATTACH_ON_CONNECT", ZMQ_DELAY_ATTACH_ON_CONNECT); # endif # ifdef ZMQ_TYPE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE); # endif # ifdef ZMQ_SNDHWM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDHWM", ZMQ_SNDHWM); # endif # ifdef ZMQ_RCVHWM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVHWM", ZMQ_RCVHWM); # endif # ifdef ZMQ_AFFINITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY); # endif # ifdef ZMQ_SUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE); # endif # ifdef ZMQ_UNSUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE); # endif # ifdef ZMQ_IDENTITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY); # endif # ifdef ZMQ_RATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE); # endif # ifdef ZMQ_RECOVERY_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL); # endif # ifdef ZMQ_SNDBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF); # endif # ifdef ZMQ_RCVBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF); # endif # ifdef ZMQ_LINGER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER); # endif # ifdef ZMQ_RECONNECT_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL); # endif # ifdef ZMQ_RECONNECT_IVL_MAX PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX); # endif # ifdef ZMQ_BACKLOG PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG); # endif # ifdef ZMQ_MAXMSGSIZE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MAXMSGSIZE", ZMQ_MAXMSGSIZE); # endif # ifdef ZMQ_MULTICAST_HOPS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MULTICAST_HOPS", ZMQ_MULTICAST_HOPS); # endif # ifdef ZMQ_RCVTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO); # endif # ifdef ZMQ_SNDTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO); # endif # ifdef ZMQ_XPUB_VERBOSE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_XPUB_VERBOSE", ZMQ_XPUB_VERBOSE); # endif # ifdef ZMQ_TCP_KEEPALIVE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE", ZMQ_TCP_KEEPALIVE); # endif # ifdef ZMQ_TCP_KEEPALIVE_IDLE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_IDLE", ZMQ_TCP_KEEPALIVE_IDLE); # endif # ifdef ZMQ_TCP_KEEPALIVE_CNT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_CNT", ZMQ_TCP_KEEPALIVE_CNT); # endif # ifdef ZMQ_TCP_KEEPALIVE_INTVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_KEEPALIVE_INTVL", ZMQ_TCP_KEEPALIVE_INTVL); # endif # ifdef ZMQ_TCP_ACCEPT_FILTER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TCP_ACCEPT_FILTER", ZMQ_TCP_ACCEPT_FILTER); # endif # ifdef ZMQ_RCVMORE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE); # endif # ifdef ZMQ_FD PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD); # endif # ifdef ZMQ_EVENTS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS); # endif # ifdef ZMQ_LAST_ENDPOINT PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LAST_ENDPOINT", ZMQ_LAST_ENDPOINT); # endif #endif /* ZMQ_MAJOR_VERSION == 3 */ #if ZMQ_VERSION_MAJOR == 2 # ifdef ZMQ_HWM PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM); # endif # ifdef ZMQ_SWAP PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SWAP", ZMQ_SWAP); # endif # ifdef ZMQ_AFFINITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY); # endif # ifdef ZMQ_IDENTITY PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY); # endif # ifdef ZMQ_RATE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE); # endif # ifdef ZMQ_RECOVERY_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL); # endif # ifdef ZMQ_RECOVERY_IVL_MSEC PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL_MSEC", ZMQ_RECOVERY_IVL_MSEC); # endif # ifdef ZMQ_MCAST_LOOP PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MCAST_LOOP", ZMQ_MCAST_LOOP); # endif # ifdef ZMQ_RCVTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO); # endif # ifdef ZMQ_SNDTIMEO PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO); # endif # ifdef ZMQ_SNDBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF); # endif # ifdef ZMQ_RCVBUF PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF); # endif # ifdef ZMQ_LINGER PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER); # endif # ifdef ZMQ_RECONNECT_IVL PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL); # endif # ifdef ZMQ_RECONNECT_IVL_MAX PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX); # endif # ifdef ZMQ_BACKLOG PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG); # endif # ifdef ZMQ_SUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE); # endif # ifdef ZMQ_UNSUBSCRIBE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE); # endif # ifdef ZMQ_TYPE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE); # endif # ifdef ZMQ_RCVMORE PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE); # endif # ifdef ZMQ_FD PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD); # endif # ifdef ZMQ_EVENTS PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS); # endif #endif /* ZMQ_MAJOR_VERSION == 2 */ #if ZMQ_VERSION_MAJOR > 2 PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM); #endif #undef PHP_ZMQ_REGISTER_SOCKOPT } /* {{{ proto mixed ZMQSocket::getSockOpt() Get a socket option */ PHP_METHOD(zmqsocket, getsockopt) { php_zmq_socket_object *intern; zend_long key; size_t value_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &key) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (!intern->socket || !intern->socket->z_socket) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket is not properly initialised", PHP_ZMQ_INTERNAL_ERROR); return; } if (key > INT_MAX) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "The key must be smaller than or equal to %d", INT_MAX); return; } #if ZMQ_VERSION_MAJOR == 4 switch (key) { # ifdef ZMQ_HEARTBEAT_IVL case ZMQ_HEARTBEAT_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, "Failed to get the option ZMQ::SOCKOPT_HEARTBEAT_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_HEARTBEAT_IVL */ # ifdef ZMQ_HEARTBEAT_TTL case ZMQ_HEARTBEAT_TTL: { 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, "Failed to get the option ZMQ::SOCKOPT_HEARTBEAT_TTL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_HEARTBEAT_TTL */ # ifdef ZMQ_HEARTBEAT_TIMEOUT case ZMQ_HEARTBEAT_TIMEOUT: { 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, "Failed to get the option ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_HEARTBEAT_TIMEOUT */ # ifdef ZMQ_TOS case ZMQ_TOS: { 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, "Failed to get the option ZMQ::SOCKOPT_TOS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TOS */ # ifdef ZMQ_ROUTER_HANDOVER case ZMQ_ROUTER_HANDOVER: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_ROUTER_HANDOVER is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_ROUTER_HANDOVER */ # ifdef ZMQ_ROUTER_MANDATORY case ZMQ_ROUTER_MANDATORY: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_ROUTER_MANDATORY is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_ROUTER_MANDATORY */ # ifdef ZMQ_PROBE_ROUTER case ZMQ_PROBE_ROUTER: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_PROBE_ROUTER is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_PROBE_ROUTER */ # ifdef ZMQ_REQ_RELAXED case ZMQ_REQ_RELAXED: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_REQ_RELAXED is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_REQ_RELAXED */ # ifdef ZMQ_REQ_CORRELATE case ZMQ_REQ_CORRELATE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_REQ_CORRELATE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_REQ_CORRELATE */ # ifdef ZMQ_CONFLATE case ZMQ_CONFLATE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_CONFLATE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_CONFLATE */ # ifdef ZMQ_ZAP_DOMAIN case ZMQ_ZAP_DOMAIN: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_ZAP_DOMAIN value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_ZAP_DOMAIN */ # ifdef ZMQ_MECHANISM case ZMQ_MECHANISM: { 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, "Failed to get the option ZMQ::SOCKOPT_MECHANISM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MECHANISM */ # ifdef ZMQ_PLAIN_SERVER case ZMQ_PLAIN_SERVER: { 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, "Failed to get the option ZMQ::SOCKOPT_PLAIN_SERVER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_PLAIN_SERVER */ # ifdef ZMQ_PLAIN_USERNAME case ZMQ_PLAIN_USERNAME: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_PLAIN_USERNAME value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_PLAIN_USERNAME */ # ifdef ZMQ_PLAIN_PASSWORD case ZMQ_PLAIN_PASSWORD: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_PLAIN_PASSWORD value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_PLAIN_PASSWORD */ # ifdef ZMQ_CURVE_SERVER case ZMQ_CURVE_SERVER: { 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, "Failed to get the option ZMQ::SOCKOPT_CURVE_SERVER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_CURVE_SERVER */ # ifdef ZMQ_CURVE_PUBLICKEY case ZMQ_CURVE_PUBLICKEY: { char value[32]; value_len = 32; 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, "Failed to get the option ZMQ::SOCKOPT_CURVE_PUBLICKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_CURVE_PUBLICKEY */ # ifdef ZMQ_CURVE_SECRETKEY case ZMQ_CURVE_SECRETKEY: { char value[32]; value_len = 32; 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, "Failed to get the option ZMQ::SOCKOPT_CURVE_SECRETKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_CURVE_SECRETKEY */ # ifdef ZMQ_CURVE_SERVERKEY case ZMQ_CURVE_SERVERKEY: { char value[32]; value_len = 32; 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, "Failed to get the option ZMQ::SOCKOPT_CURVE_SERVERKEY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_CURVE_SERVERKEY */ # ifdef ZMQ_GSSAPI_SERVER case ZMQ_GSSAPI_SERVER: { 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, "Failed to get the option ZMQ::SOCKOPT_GSSAPI_SERVER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_GSSAPI_SERVER */ # ifdef ZMQ_GSSAPI_PLAINTEXT case ZMQ_GSSAPI_PLAINTEXT: { 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, "Failed to get the option ZMQ::SOCKOPT_GSSAPI_PLAINTEXT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_GSSAPI_PLAINTEXT */ # ifdef ZMQ_GSSAPI_PRINCIPAL case ZMQ_GSSAPI_PRINCIPAL: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_GSSAPI_PRINCIPAL value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_GSSAPI_PRINCIPAL */ # ifdef ZMQ_GSSAPI_SERVICE_PRINCIPAL case ZMQ_GSSAPI_SERVICE_PRINCIPAL: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_GSSAPI_SERVICE_PRINCIPAL value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_GSSAPI_SERVICE_PRINCIPAL */ # ifdef ZMQ_IPV6 case ZMQ_IPV6: { 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, "Failed to get the option ZMQ::SOCKOPT_IPV6 value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_IPV6 */ # ifdef ZMQ_IMMEDIATE case ZMQ_IMMEDIATE: { 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, "Failed to get the option ZMQ::SOCKOPT_IMMEDIATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_IMMEDIATE */ # ifdef ZMQ_ROUTER_RAW case ZMQ_ROUTER_RAW: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_ROUTER_RAW is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_ROUTER_RAW */ # ifdef ZMQ_IPV4ONLY case ZMQ_IPV4ONLY: { 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, "Failed to get the option ZMQ::SOCKOPT_IPV4ONLY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_IPV4ONLY */ # ifdef ZMQ_TYPE 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, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TYPE */ # ifdef ZMQ_SNDHWM case ZMQ_SNDHWM: { 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, "Failed to get the option ZMQ::SOCKOPT_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDHWM */ # ifdef ZMQ_RCVHWM case ZMQ_RCVHWM: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVHWM */ # ifdef ZMQ_AFFINITY 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, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_AFFINITY */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { { if (intern->socket->socket_type != ZMQ_REQ && intern->socket->socket_type != ZMQ_REP && intern->socket->socket_type != ZMQ_DEALER && intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_IDENTITY is not valid for this socket type", errno); return; } } char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_IDENTITY */ # ifdef ZMQ_RATE case ZMQ_RATE: { 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, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL case ZMQ_RECOVERY_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, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECOVERY_IVL */ # ifdef ZMQ_SNDBUF case ZMQ_SNDBUF: { 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, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF case ZMQ_RCVBUF: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVBUF */ # ifdef ZMQ_LINGER 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, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG 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, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_BACKLOG */ # ifdef ZMQ_MAXMSGSIZE case ZMQ_MAXMSGSIZE: { 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, "Failed to get the option ZMQ::SOCKOPT_MAXMSGSIZE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MAXMSGSIZE */ # ifdef ZMQ_MULTICAST_HOPS case ZMQ_MULTICAST_HOPS: { 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, "Failed to get the option ZMQ::SOCKOPT_MULTICAST_HOPS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MULTICAST_HOPS */ # ifdef ZMQ_RCVTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDTIMEO */ # ifdef ZMQ_XPUB_VERBOSE case ZMQ_XPUB_VERBOSE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_XPUB_VERBOSE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_XPUB_VERBOSE */ # ifdef ZMQ_TCP_KEEPALIVE case ZMQ_TCP_KEEPALIVE: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE */ # ifdef ZMQ_TCP_KEEPALIVE_IDLE case ZMQ_TCP_KEEPALIVE_IDLE: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_IDLE */ # ifdef ZMQ_TCP_KEEPALIVE_CNT case ZMQ_TCP_KEEPALIVE_CNT: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_CNT */ # ifdef ZMQ_TCP_KEEPALIVE_INTVL case ZMQ_TCP_KEEPALIVE_INTVL: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_INTVL */ # ifdef ZMQ_TCP_ACCEPT_FILTER case ZMQ_TCP_ACCEPT_FILTER: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_TCP_ACCEPT_FILTER is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_TCP_ACCEPT_FILTER */ # ifdef ZMQ_RCVMORE case ZMQ_RCVMORE: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { php_stream *stream = php_zmq_create_zmq_fd(getThis()); if (stream) { php_stream_to_zval(stream, return_value); return; } RETURN_FALSE; } break; # endif /* ZMQ_FD */ # ifdef ZMQ_EVENTS case ZMQ_EVENTS: { 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, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_EVENTS */ # ifdef ZMQ_LAST_ENDPOINT case ZMQ_LAST_ENDPOINT: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_LAST_ENDPOINT value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_LAST_ENDPOINT */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } #endif /* ZMQ_VERSION_MAJOR == 4 */ #if ZMQ_VERSION_MAJOR == 3 switch (key) { # ifdef ZMQ_ROUTER_RAW case ZMQ_ROUTER_RAW: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_ROUTER_RAW is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_ROUTER_RAW */ # ifdef ZMQ_IPV4ONLY case ZMQ_IPV4ONLY: { 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, "Failed to get the option ZMQ::SOCKOPT_IPV4ONLY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_IPV4ONLY */ # ifdef ZMQ_TYPE 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, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TYPE */ # ifdef ZMQ_SNDHWM case ZMQ_SNDHWM: { 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, "Failed to get the option ZMQ::SOCKOPT_SNDHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDHWM */ # ifdef ZMQ_RCVHWM case ZMQ_RCVHWM: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVHWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVHWM */ # ifdef ZMQ_AFFINITY 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, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_AFFINITY */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { { if (intern->socket->socket_type != ZMQ_REQ && intern->socket->socket_type != ZMQ_REP && intern->socket->socket_type != ZMQ_DEALER && intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_IDENTITY is not valid for this socket type", errno); return; } } char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_IDENTITY */ # ifdef ZMQ_RATE case ZMQ_RATE: { 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, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL case ZMQ_RECOVERY_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, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECOVERY_IVL */ # ifdef ZMQ_SNDBUF case ZMQ_SNDBUF: { 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, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF case ZMQ_RCVBUF: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVBUF */ # ifdef ZMQ_LINGER 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, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG 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, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_BACKLOG */ # ifdef ZMQ_MAXMSGSIZE case ZMQ_MAXMSGSIZE: { 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, "Failed to get the option ZMQ::SOCKOPT_MAXMSGSIZE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MAXMSGSIZE */ # ifdef ZMQ_MULTICAST_HOPS case ZMQ_MULTICAST_HOPS: { 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, "Failed to get the option ZMQ::SOCKOPT_MULTICAST_HOPS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MULTICAST_HOPS */ # ifdef ZMQ_RCVTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDTIMEO */ # ifdef ZMQ_XPUB_VERBOSE case ZMQ_XPUB_VERBOSE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_XPUB_VERBOSE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_XPUB_VERBOSE */ # ifdef ZMQ_TCP_KEEPALIVE case ZMQ_TCP_KEEPALIVE: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE */ # ifdef ZMQ_TCP_KEEPALIVE_IDLE case ZMQ_TCP_KEEPALIVE_IDLE: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_IDLE */ # ifdef ZMQ_TCP_KEEPALIVE_CNT case ZMQ_TCP_KEEPALIVE_CNT: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_CNT */ # ifdef ZMQ_TCP_KEEPALIVE_INTVL case ZMQ_TCP_KEEPALIVE_INTVL: { 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, "Failed to get the option ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TCP_KEEPALIVE_INTVL */ # ifdef ZMQ_TCP_ACCEPT_FILTER case ZMQ_TCP_ACCEPT_FILTER: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_TCP_ACCEPT_FILTER is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_TCP_ACCEPT_FILTER */ # ifdef ZMQ_RCVMORE case ZMQ_RCVMORE: { 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, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { php_stream *stream = php_zmq_create_zmq_fd(getThis()); if (stream) { php_stream_to_zval(stream, return_value); return; } RETURN_FALSE; } break; # endif /* ZMQ_FD */ # ifdef ZMQ_EVENTS case ZMQ_EVENTS: { 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, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_EVENTS */ # ifdef ZMQ_LAST_ENDPOINT case ZMQ_LAST_ENDPOINT: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_LAST_ENDPOINT value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len - 1); } break; # endif /* ZMQ_LAST_ENDPOINT */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } #endif /* ZMQ_VERSION_MAJOR == 3 */ #if ZMQ_VERSION_MAJOR == 2 switch (key) { # ifdef ZMQ_HWM 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, "Failed to get the option ZMQ::SOCKOPT_HWM value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_HWM */ # ifdef ZMQ_SWAP 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, "Failed to get the option ZMQ::SOCKOPT_SWAP value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SWAP */ # ifdef ZMQ_AFFINITY 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, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_AFFINITY */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { char value[255]; value_len = 255; 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, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno)); return; } RETURN_STRINGL(value, value_len); } break; # endif /* ZMQ_IDENTITY */ # ifdef ZMQ_RATE 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, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL 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, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECOVERY_IVL */ # ifdef ZMQ_RECOVERY_IVL_MSEC 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, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL_MSEC value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECOVERY_IVL_MSEC */ # ifdef ZMQ_MCAST_LOOP 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, "Failed to get the option ZMQ::SOCKOPT_MCAST_LOOP value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_MCAST_LOOP */ # ifdef ZMQ_RCVTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO 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, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDTIMEO */ # ifdef ZMQ_SNDBUF 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, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF 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, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVBUF */ # ifdef ZMQ_LINGER 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, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX 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, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG 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, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_BACKLOG */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_TYPE 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, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_TYPE */ # ifdef ZMQ_RCVMORE 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, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { php_stream *stream = php_zmq_create_zmq_fd(getThis()); if (stream) { php_stream_to_zval(stream, return_value); return; } RETURN_FALSE; } break; # endif /* ZMQ_FD */ # ifdef ZMQ_EVENTS 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, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno)); return; } RETURN_LONG(value); } break; # endif /* ZMQ_EVENTS */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } #endif /* ZMQ_VERSION_MAJOR == 2 */ } /* }}} */ /* {{{ proto ZMQSocket ZMQSocket::setSockOpt(integer $SOCKOPT, mixed $value) Set a socket option */ PHP_METHOD(zmqsocket, setsockopt) { php_zmq_socket_object *intern; long key; zval *zv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &zv) == FAILURE) { return; } intern = PHP_ZMQ_SOCKET_OBJECT; if (!intern->socket || !intern->socket->z_socket) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket is not properly initialised", PHP_ZMQ_INTERNAL_ERROR); return; } if (key > INT_MAX) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "The key must be smaller than %d", INT_MAX); return; } /* Support setting rcvhwm and sndhwm in one call for backwards compatibility */ #if ZMQ_VERSION_MAJOR > 2 if (key == ZMQ_HWM) { int snd_hwm; size_t snd_hwm_len = sizeof(int); int value = (int) zval_get_long(zv); /* Get current value if we need to try to restore */ if (zmq_getsockopt(intern->socket->z_socket, ZMQ_SNDHWM, &snd_hwm, &snd_hwm_len) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno)); return; } /* First set snd hwm */ if (zmq_setsockopt (intern->socket->z_socket, ZMQ_SNDHWM, &value, sizeof (int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno)); return; } /* Next try to set rcv hwm */ if (zmq_setsockopt (intern->socket->z_socket, ZMQ_RCVHWM, &value, sizeof (int)) != 0) { /* Setting rcv failed, try to roll back snd */ if (zmq_setsockopt (intern->socket->z_socket, ZMQ_SNDHWM, &snd_hwm, sizeof (int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HWM option (ZMQ::SOCKOPT_SNDHWM changed): %s", zmq_strerror(errno)); return; } zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno)); return; } ZMQ_RETURN_THIS; return; } #endif #if ZMQ_VERSION_MAJOR == 4 switch (key) { # ifdef ZMQ_HEARTBEAT_IVL case ZMQ_HEARTBEAT_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HEARTBEAT_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_HEARTBEAT_IVL */ # ifdef ZMQ_HEARTBEAT_TTL case ZMQ_HEARTBEAT_TTL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HEARTBEAT_TTL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_HEARTBEAT_TTL */ # ifdef ZMQ_HEARTBEAT_TIMEOUT case ZMQ_HEARTBEAT_TIMEOUT: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_HEARTBEAT_TIMEOUT */ # ifdef ZMQ_TOS case ZMQ_TOS: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TOS option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TOS */ # ifdef ZMQ_ROUTER_HANDOVER case ZMQ_ROUTER_HANDOVER: { { if (intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_ROUTER_HANDOVER is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_ROUTER_HANDOVER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_ROUTER_HANDOVER */ # ifdef ZMQ_ROUTER_MANDATORY case ZMQ_ROUTER_MANDATORY: { { if (intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_ROUTER_MANDATORY is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_ROUTER_MANDATORY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_ROUTER_MANDATORY */ # ifdef ZMQ_PROBE_ROUTER case ZMQ_PROBE_ROUTER: { { if (intern->socket->socket_type != ZMQ_ROUTER && intern->socket->socket_type != ZMQ_DEALER && intern->socket->socket_type != ZMQ_REQ) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_PROBE_ROUTER is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_PROBE_ROUTER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_PROBE_ROUTER */ # ifdef ZMQ_REQ_RELAXED case ZMQ_REQ_RELAXED: { { if (intern->socket->socket_type != ZMQ_REQ) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_REQ_RELAXED is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_REQ_RELAXED option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_REQ_RELAXED */ # ifdef ZMQ_REQ_CORRELATE case ZMQ_REQ_CORRELATE: { { if (intern->socket->socket_type != ZMQ_REQ) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_REQ_CORRELATE is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_REQ_CORRELATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_REQ_CORRELATE */ # ifdef ZMQ_CONFLATE case ZMQ_CONFLATE: { { if (intern->socket->socket_type != ZMQ_PUSH && intern->socket->socket_type != ZMQ_PULL && intern->socket->socket_type != ZMQ_PUB && intern->socket->socket_type != ZMQ_SUB && intern->socket->socket_type != ZMQ_DEALER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_CONFLATE is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_CONFLATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_CONFLATE */ # ifdef ZMQ_ZAP_DOMAIN case ZMQ_ZAP_DOMAIN: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_ZAP_DOMAIN option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_ZAP_DOMAIN */ # ifdef ZMQ_MECHANISM case ZMQ_MECHANISM: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_MECHANISM is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_MECHANISM */ # ifdef ZMQ_PLAIN_SERVER case ZMQ_PLAIN_SERVER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_PLAIN_SERVER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_PLAIN_SERVER */ # ifdef ZMQ_PLAIN_USERNAME case ZMQ_PLAIN_USERNAME: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_PLAIN_USERNAME option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_PLAIN_USERNAME */ # ifdef ZMQ_PLAIN_PASSWORD case ZMQ_PLAIN_PASSWORD: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_PLAIN_PASSWORD option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_PLAIN_PASSWORD */ # ifdef ZMQ_CURVE_SERVER case ZMQ_CURVE_SERVER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_CURVE_SERVER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_CURVE_SERVER */ # ifdef ZMQ_CURVE_PUBLICKEY case ZMQ_CURVE_PUBLICKEY: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_CURVE_PUBLICKEY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_CURVE_PUBLICKEY */ # ifdef ZMQ_CURVE_SECRETKEY case ZMQ_CURVE_SECRETKEY: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_CURVE_SECRETKEY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_CURVE_SECRETKEY */ # ifdef ZMQ_CURVE_SERVERKEY case ZMQ_CURVE_SERVERKEY: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_CURVE_SERVERKEY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_CURVE_SERVERKEY */ # ifdef ZMQ_GSSAPI_SERVER case ZMQ_GSSAPI_SERVER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_GSSAPI_SERVER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_GSSAPI_SERVER */ # ifdef ZMQ_GSSAPI_PLAINTEXT case ZMQ_GSSAPI_PLAINTEXT: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_GSSAPI_PLAINTEXT option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_GSSAPI_PLAINTEXT */ # ifdef ZMQ_GSSAPI_PRINCIPAL case ZMQ_GSSAPI_PRINCIPAL: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_GSSAPI_PRINCIPAL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_GSSAPI_PRINCIPAL */ # ifdef ZMQ_GSSAPI_SERVICE_PRINCIPAL case ZMQ_GSSAPI_SERVICE_PRINCIPAL: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_GSSAPI_SERVICE_PRINCIPAL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_GSSAPI_SERVICE_PRINCIPAL */ # ifdef ZMQ_IPV6 case ZMQ_IPV6: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IPV6 option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IPV6 */ # ifdef ZMQ_IMMEDIATE case ZMQ_IMMEDIATE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IMMEDIATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IMMEDIATE */ # ifdef ZMQ_ROUTER_RAW case ZMQ_ROUTER_RAW: { { if (intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_ROUTER_RAW is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_ROUTER_RAW option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_ROUTER_RAW */ # ifdef ZMQ_IPV4ONLY case ZMQ_IPV4ONLY: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IPV4ONLY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IPV4ONLY */ # ifdef ZMQ_TYPE case ZMQ_TYPE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_TYPE */ # ifdef ZMQ_SNDHWM case ZMQ_SNDHWM: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDHWM */ # ifdef ZMQ_RCVHWM case ZMQ_RCVHWM: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVHWM option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVHWM */ # ifdef ZMQ_AFFINITY case ZMQ_AFFINITY: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_AFFINITY */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_SUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_UNSUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { { if (intern->socket->socket_type != ZMQ_REQ && intern->socket->socket_type != ZMQ_REP && intern->socket->socket_type != ZMQ_DEALER && intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_IDENTITY is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IDENTITY */ # ifdef ZMQ_RATE case ZMQ_RATE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL case ZMQ_RECOVERY_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECOVERY_IVL */ # ifdef ZMQ_SNDBUF case ZMQ_SNDBUF: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF case ZMQ_RCVBUF: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVBUF */ # ifdef ZMQ_LINGER case ZMQ_LINGER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL case ZMQ_RECONNECT_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX case ZMQ_RECONNECT_IVL_MAX: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG case ZMQ_BACKLOG: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_BACKLOG */ # ifdef ZMQ_MAXMSGSIZE case ZMQ_MAXMSGSIZE: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_MAXMSGSIZE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_MAXMSGSIZE */ # ifdef ZMQ_MULTICAST_HOPS case ZMQ_MULTICAST_HOPS: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_MULTICAST_HOPS option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_MULTICAST_HOPS */ # ifdef ZMQ_RCVTIMEO case ZMQ_RCVTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO case ZMQ_SNDTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDTIMEO */ # ifdef ZMQ_XPUB_VERBOSE case ZMQ_XPUB_VERBOSE: { { if (intern->socket->socket_type != ZMQ_XPUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_XPUB_VERBOSE is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_XPUB_VERBOSE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_XPUB_VERBOSE */ # ifdef ZMQ_TCP_KEEPALIVE case ZMQ_TCP_KEEPALIVE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE */ # ifdef ZMQ_TCP_KEEPALIVE_IDLE case ZMQ_TCP_KEEPALIVE_IDLE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_IDLE */ # ifdef ZMQ_TCP_KEEPALIVE_CNT case ZMQ_TCP_KEEPALIVE_CNT: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_CNT */ # ifdef ZMQ_TCP_KEEPALIVE_INTVL case ZMQ_TCP_KEEPALIVE_INTVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_INTVL */ # ifdef ZMQ_TCP_ACCEPT_FILTER case ZMQ_TCP_ACCEPT_FILTER: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_ACCEPT_FILTER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_ACCEPT_FILTER */ # ifdef ZMQ_RCVMORE case ZMQ_RCVMORE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_FD is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_FD */ # ifdef ZMQ_EVENTS case ZMQ_EVENTS: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_EVENTS is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_EVENTS */ # ifdef ZMQ_LAST_ENDPOINT case ZMQ_LAST_ENDPOINT: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_LAST_ENDPOINT is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_LAST_ENDPOINT */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } ZMQ_RETURN_THIS; #endif #if ZMQ_VERSION_MAJOR == 3 switch (key) { # ifdef ZMQ_ROUTER_RAW case ZMQ_ROUTER_RAW: { { if (intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_ROUTER_RAW is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_ROUTER_RAW option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_ROUTER_RAW */ # ifdef ZMQ_IPV4ONLY case ZMQ_IPV4ONLY: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IPV4ONLY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IPV4ONLY */ # ifdef ZMQ_TYPE case ZMQ_TYPE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_TYPE */ # ifdef ZMQ_SNDHWM case ZMQ_SNDHWM: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDHWM option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDHWM */ # ifdef ZMQ_RCVHWM case ZMQ_RCVHWM: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVHWM option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVHWM */ # ifdef ZMQ_AFFINITY case ZMQ_AFFINITY: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_AFFINITY */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_SUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_UNSUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { { if (intern->socket->socket_type != ZMQ_REQ && intern->socket->socket_type != ZMQ_REP && intern->socket->socket_type != ZMQ_DEALER && intern->socket->socket_type != ZMQ_ROUTER) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_IDENTITY is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IDENTITY */ # ifdef ZMQ_RATE case ZMQ_RATE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL case ZMQ_RECOVERY_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECOVERY_IVL */ # ifdef ZMQ_SNDBUF case ZMQ_SNDBUF: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF case ZMQ_RCVBUF: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVBUF */ # ifdef ZMQ_LINGER case ZMQ_LINGER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL case ZMQ_RECONNECT_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX case ZMQ_RECONNECT_IVL_MAX: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG case ZMQ_BACKLOG: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_BACKLOG */ # ifdef ZMQ_MAXMSGSIZE case ZMQ_MAXMSGSIZE: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_MAXMSGSIZE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_MAXMSGSIZE */ # ifdef ZMQ_MULTICAST_HOPS case ZMQ_MULTICAST_HOPS: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_MULTICAST_HOPS option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_MULTICAST_HOPS */ # ifdef ZMQ_RCVTIMEO case ZMQ_RCVTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO case ZMQ_SNDTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDTIMEO */ # ifdef ZMQ_XPUB_VERBOSE case ZMQ_XPUB_VERBOSE: { { if (intern->socket->socket_type != ZMQ_XPUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_XPUB_VERBOSE is not valid for this socket type", errno); return; } } int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_XPUB_VERBOSE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_XPUB_VERBOSE */ # ifdef ZMQ_TCP_KEEPALIVE case ZMQ_TCP_KEEPALIVE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE */ # ifdef ZMQ_TCP_KEEPALIVE_IDLE case ZMQ_TCP_KEEPALIVE_IDLE: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_IDLE */ # ifdef ZMQ_TCP_KEEPALIVE_CNT case ZMQ_TCP_KEEPALIVE_CNT: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_CNT */ # ifdef ZMQ_TCP_KEEPALIVE_INTVL case ZMQ_TCP_KEEPALIVE_INTVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_KEEPALIVE_INTVL */ # ifdef ZMQ_TCP_ACCEPT_FILTER case ZMQ_TCP_ACCEPT_FILTER: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_TCP_ACCEPT_FILTER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_TCP_ACCEPT_FILTER */ # ifdef ZMQ_RCVMORE case ZMQ_RCVMORE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_FD is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_FD */ # ifdef ZMQ_EVENTS case ZMQ_EVENTS: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_EVENTS is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_EVENTS */ # ifdef ZMQ_LAST_ENDPOINT case ZMQ_LAST_ENDPOINT: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_LAST_ENDPOINT is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_LAST_ENDPOINT */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } ZMQ_RETURN_THIS; #endif #if ZMQ_VERSION_MAJOR == 2 switch (key) { # ifdef ZMQ_HWM case ZMQ_HWM: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_HWM */ # ifdef ZMQ_SWAP case ZMQ_SWAP: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SWAP option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SWAP */ # ifdef ZMQ_AFFINITY case ZMQ_AFFINITY: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_AFFINITY */ # ifdef ZMQ_IDENTITY case ZMQ_IDENTITY: { int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_IDENTITY */ # ifdef ZMQ_RATE case ZMQ_RATE: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RATE */ # ifdef ZMQ_RECOVERY_IVL case ZMQ_RECOVERY_IVL: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECOVERY_IVL */ # ifdef ZMQ_RECOVERY_IVL_MSEC case ZMQ_RECOVERY_IVL_MSEC: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL_MSEC option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECOVERY_IVL_MSEC */ # ifdef ZMQ_MCAST_LOOP case ZMQ_MCAST_LOOP: { int64_t value = (int64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_MCAST_LOOP option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_MCAST_LOOP */ # ifdef ZMQ_RCVTIMEO case ZMQ_RCVTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVTIMEO */ # ifdef ZMQ_SNDTIMEO case ZMQ_SNDTIMEO: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDTIMEO option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDTIMEO */ # ifdef ZMQ_SNDBUF case ZMQ_SNDBUF: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SNDBUF */ # ifdef ZMQ_RCVBUF case ZMQ_RCVBUF: { uint64_t value = (uint64_t) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RCVBUF */ # ifdef ZMQ_LINGER case ZMQ_LINGER: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_LINGER */ # ifdef ZMQ_RECONNECT_IVL case ZMQ_RECONNECT_IVL: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL */ # ifdef ZMQ_RECONNECT_IVL_MAX case ZMQ_RECONNECT_IVL_MAX: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_RECONNECT_IVL_MAX */ # ifdef ZMQ_BACKLOG case ZMQ_BACKLOG: { int value = (int) zval_get_long(zv); if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int)) != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_BACKLOG */ # ifdef ZMQ_SUBSCRIBE case ZMQ_SUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_SUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_SUBSCRIBE */ # ifdef ZMQ_UNSUBSCRIBE case ZMQ_UNSUBSCRIBE: { { if (intern->socket->socket_type != ZMQ_SUB) { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_UNSUBSCRIBE is not valid for this socket type", errno); return; } } int rc; zend_string *str = zval_get_string(zv); rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len); zend_string_release(str); if (rc != 0) { zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno)); return; } } break; # endif /* ifdef ZMQ_UNSUBSCRIBE */ # ifdef ZMQ_TYPE case ZMQ_TYPE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_TYPE */ # ifdef ZMQ_RCVMORE case ZMQ_RCVMORE: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_RCVMORE */ # ifdef ZMQ_FD case ZMQ_FD: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_FD is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_FD */ # ifdef ZMQ_EVENTS case ZMQ_EVENTS: { zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_EVENTS is not supported", PHP_ZMQ_INTERNAL_ERROR); return; } break; # endif /* ifdef ZMQ_EVENTS */ default: zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), PHP_ZMQ_INTERNAL_ERROR, "Unknown option key %ld", key); return; } ZMQ_RETURN_THIS; #endif } zmq-1.1.3/zmq_clock.c0000644000076500000240000001270012653534763011405 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef HAVE_TIME_H # include #endif #ifdef HAVE_SYS_TIME_H # include #endif #ifdef HAVE_MACH_MACH_TIME_H # include #endif #if defined(PHP_WIN32) # include "win32/time.h" #endif static uint64_t s_backup_clock () { #if defined(HAVE_GETTIMEOFDAY) struct timeval tv; gettimeofday(&tv, NULL); return (uint64_t) (((uint64_t) tv.tv_sec * 1000) + ((uint64_t) tv.tv_usec / 1000)); #endif php_error (E_ERROR, "Failed to get current time"); return 0; } /* Systems supporting clock_gettime(CLOCK_MONOTONIC) */ #if defined(HAVE_CLOCK_GETTIME) && (defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC)) struct _php_zmq_clock_ctx_t {}; php_zmq_clock_ctx_t *php_zmq_clock_init () { return malloc (sizeof (php_zmq_clock_ctx_t)); } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { struct timespec ts; #if defined(CLOCK_MONOTONIC_RAW) if (clock_gettime (CLOCK_MONOTONIC_RAW, &ts) == 0) { #else if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) { #endif return (uint64_t) (((uint64_t) ts.tv_sec * 1000) + ((uint64_t) ts.tv_nsec / 1000000)); } return s_backup_clock (); } /* Mac OS X */ #elif defined(HAVE_MACH_ABSOLUTE_TIME) struct _php_zmq_clock_ctx_t { uint64_t scaling_factor; }; php_zmq_clock_ctx_t *php_zmq_clock_init () { php_zmq_clock_ctx_t *ctx; mach_timebase_info_data_t info; if (mach_timebase_info (&info) != 0) { return NULL; } ctx = malloc (sizeof (php_zmq_clock_ctx_t)); ctx->scaling_factor = (info.numer / info.denom); return ctx; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *ctx) { return (mach_absolute_time () * ctx->scaling_factor) / 1000000; } /* Windows systems. Not using QueryPerformanceCounter because of: https://www.virtualbox.org/ticket/11951 */ #elif defined(PHP_WIN32) struct _php_zmq_clock_ctx_t { int wrap_count; uint64_t last_ticks; }; php_zmq_clock_ctx_t *php_zmq_clock_init () { return calloc (1, sizeof (php_zmq_clock_ctx_t)); } static uint64_t s_get_tick_count (php_zmq_clock_ctx_t *clock_ctx) { uint64_t ticks = (uint64_t) GetTickCount (); /* Has the clock wrapped? */ if (ticks < clock_ctx->last_ticks) ++clock_ctx->wrap_count; clock_ctx->last_ticks = ticks; ticks += (uint64_t) clock_ctx->wrap_count * (uint64_t) MAXDWORD; return ticks; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { return s_get_tick_count (clock_ctx); } #elif defined(HAVE_GETTIMEOFDAY) struct _php_zmq_clock_ctx_t {}; php_zmq_clock_ctx_t *php_zmq_clock_init () { return malloc (sizeof (php_zmq_clock_ctx_t)); } static uint64_t s_get_tick_count (php_zmq_clock_ctx_t *clock_ctx) { uint64_t ticks = (uint64_t) GetTickCount (); /* Has the clock wrapped? */ if (ticks < clock_ctx->last_ticks) ++clock_ctx->wrap_count; clock_ctx->last_ticks = ticks; ticks += (uint64_t) clock_ctx->wrap_count * MAX_DWORD; return ticks; } uint64_t php_zmq_clock (php_zmq_clock_ctx_t *clock_ctx) { return s_backup_clock (); } #else # error "Cannot find a clock that would work on this platform. Please report a bug" #endif void php_zmq_clock_destroy (php_zmq_clock_ctx_t **clock_ctx) { free (*clock_ctx); } zmq-1.1.3/zmq_object_access.c0000644000076500000240000000742612653534763013112 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ static inline php_zmq_context_object *php_zmq_context_fetch_object(zend_object *obj) { return (php_zmq_context_object *)((char *)obj - XtOffsetOf(php_zmq_context_object, zo)); } static inline php_zmq_socket_object *php_zmq_socket_fetch_object(zend_object *obj) { return (php_zmq_socket_object *)((char *)obj - XtOffsetOf(php_zmq_socket_object, zo)); } static inline php_zmq_poll_object *php_zmq_poll_fetch_object(zend_object *obj) { return (php_zmq_poll_object *)((char *)obj - XtOffsetOf(php_zmq_poll_object, zo)); } static inline php_zmq_device_object *php_zmq_device_fetch_object(zend_object *obj) { return (php_zmq_device_object *)((char *)obj - XtOffsetOf(php_zmq_device_object, zo)); } #define PHP_ZMQ_CONTEXT_OBJECT php_zmq_context_fetch_object(Z_OBJ_P(getThis())); #define PHP_ZMQ_SOCKET_OBJECT php_zmq_socket_fetch_object(Z_OBJ_P(getThis())); #define PHP_ZMQ_POLL_OBJECT php_zmq_poll_fetch_object(Z_OBJ_P(getThis())); #define PHP_ZMQ_DEVICE_OBJECT php_zmq_device_fetch_object(Z_OBJ_P(getThis())); #ifdef HAVE_CZMQ_2 static inline php_zmq_cert_object *php_zmq_cert_fetch_object(zend_object *obj) { return (php_zmq_cert_object *)((char *)obj - XtOffsetOf(php_zmq_cert_object, zo)); } static inline php_zmq_auth_object *php_zmq_auth_fetch_object(zend_object *obj) { return (php_zmq_auth_object *)((char *)obj - XtOffsetOf(php_zmq_auth_object, zo)); } #define PHP_ZMQ_CERT_OBJECT php_zmq_cert_fetch_object(Z_OBJ_P(getThis())); #define PHP_ZMQ_AUTH_OBJECT php_zmq_auth_fetch_object(Z_OBJ_P(getThis())); #endifzmq-1.1.3/zmq_helpers.c0000644000076500000240000000652012653534763011757 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2013, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" /** {{{ char *php_zmq_libzmq_version() */ char *php_zmq_get_libzmq_version() { char *buffer = NULL; int major = 0, minor = 0, patch = 0; zmq_version(&major, &minor, &patch); spprintf(&buffer, 0, "%d.%d.%d", major, minor, patch); return buffer; } /* }}} */ /** {{{ zend_long php_zmq_libzmq_version_id() */ zend_long php_zmq_get_libzmq_version_id() { int major = 0, minor = 0, patch = 0; zmq_version(&major, &minor, &patch); return (major * 10000) + (minor * 100) + patch; } /* }}} */ /** {{{ char *php_zmq_printable_func() */ char *php_zmq_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) { char *buffer = NULL; if (fci->object) { spprintf (&buffer, 0, "%s::%s", fci->object->ce->name->val, fci_cache->function_handler->common.function_name); } else { if (Z_TYPE (fci->function_name) == IS_OBJECT) { spprintf (&buffer, 0, "%s", Z_OBJCE (fci->function_name)->name->val); } else { spprintf (&buffer, 0, "%s", Z_STRVAL (fci->function_name)); } } return buffer; } /* }}} */zmq-1.1.3/zmq_shared_ctx.c0000644000076500000240000001113312653534763012435 0ustar /* +-----------------------------------------------------------------------------------+ | ZMQ extension for PHP | | Copyright (c) 2010-2016, Mikko Koppanen | | All rights reserved. | +-----------------------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions are met: | | * Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | * Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | * Neither the name of the copyright holder nor the | | names of its contributors may be used to endorse or promote products | | derived from this software without specific prior written permission. | +-----------------------------------------------------------------------------------+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY | | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +-----------------------------------------------------------------------------------+ */ #include "php_zmq.h" #include "php_zmq_private.h" #ifndef PHP_ZMQ_SHARED_CONTEXT_THREADS # define PHP_ZMQ_SHARED_CONTEXT_THREADS 1 #endif static void *s_ctx; static int s_ctx_socket_count = 0; static int s_ctx_pid = 0; #ifdef ZTS static MUTEX_T s_ctx_mutex; static zend_bool s_shared_ctx_init() { if (!s_ctx) { s_ctx_mutex = tsrm_mutex_alloc(); s_ctx_pid = getpid(); s_ctx = zmq_init(PHP_ZMQ_SHARED_CONTEXT_THREADS); } return (s_ctx != NULL); } static zend_bool s_shared_ctx_lock() { if (!s_ctx_mutex) { return 0; } return tsrm_mutex_lock(s_ctx_mutex) == 0; } static zend_bool s_shared_ctx_unlock() { if (!s_ctx_mutex) { return 0; } return tsrm_mutex_unlock(s_ctx_mutex) == 0; } static void s_shared_ctx_destroy() { if (s_shared_ctx_lock()) { if (s_ctx && s_ctx_pid == getpid()) { MUTEX_T tmp_mutex = s_ctx_mutex; s_ctx_mutex = NULL; zmq_term(s_ctx); s_ctx = NULL; s_ctx_pid = -1; tsrm_mutex_unlock(tmp_mutex); tsrm_mutex_free(tmp_mutex); s_ctx_mutex = NULL; s_ctx_pid = -1; return; } else { s_shared_ctx_unlock(); } } } #else static zend_bool s_shared_ctx_init() { s_ctx = zmq_init(PHP_ZMQ_SHARED_CONTEXT_THREADS); s_ctx_pid = getpid(); return (s_ctx != NULL); } static zend_bool s_shared_ctx_lock() { return 1; } static zend_bool s_shared_ctx_unlock() { return 1; } static void s_shared_ctx_destroy() { if (s_ctx && s_ctx_pid == getpid()) { zmq_term(s_ctx); s_ctx = NULL; s_ctx_pid = -1; } } #endif zend_bool php_zmq_shared_ctx_init() { return s_shared_ctx_init(); } void php_zmq_shared_ctx_assign_to(php_zmq_context *context) { if (s_shared_ctx_lock()) { context->z_ctx = s_ctx; s_shared_ctx_unlock(); } } void php_zmq_shared_ctx_destroy() { if (php_zmq_shared_ctx_socket_count() > 0) { php_error_docref(NULL, E_WARNING, "php_zmq_shared_ctx_socket_count() > 0, please report a bug"); } s_shared_ctx_destroy(); } int php_zmq_shared_ctx_socket_count() { int value = 0; if (s_shared_ctx_lock()) { value = s_ctx_socket_count; s_shared_ctx_unlock(); } return value; } void php_zmq_shared_ctx_socket_count_incr() { if (s_shared_ctx_lock()) { s_ctx_socket_count++; s_shared_ctx_unlock(); } } void php_zmq_shared_ctx_socket_count_decr() { if (s_shared_ctx_lock()) { s_ctx_socket_count--; s_shared_ctx_unlock(); } } zmq-1.1.3/README.md0000644000076500000240000000111412653534763010533 0ustar PHP bindings for 0MQ. The documentation is available at http://php.net/zmq [![Build Status](https://travis-ci.org/mkoppanen/php-zmq.png?branch=master)](https://travis-ci.org/mkoppanen/php-zmq) The API is roughly as follows: connect("tcp://127.0.0.1:5555"); /* send and receive */ var_dump($queue->send("hello there, using socket 1")->recv()); ?> For installation instructions see http://pecl.php.net/zmq zmq-1.1.3/LICENSE0000644000076500000240000000363312653534763010271 0ustar ZeroMQ extension for PHP Copyright (c) 2010-2013, Mikko Koppanen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MIKKO KOPPANEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.