Skip to content

Commit 8846341

Browse files
authored
Merge pull request zeromq#209 from zebastian/master
sockopts: code condensed by moving to makros
2 parents 58544c8 + 8963ff3 commit 8846341

File tree

5 files changed

+302
-1989
lines changed

5 files changed

+302
-1989
lines changed

options/sockopts.gsl

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "php_zmq.h"
4545
#include "php_zmq_private.h"
4646
#include "zmq_object_access.c"
47+
#include "zmq_sockopts_makros.h"
4748

4849
.echo "generating ../zmq_sockopt.c"
4950

options/sockopts_get.gsl

+4-22
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,27 @@ PHP_METHOD(zmqsocket, getsockopt)
3737
# ifdef ZMQ_$(NAME)
3838

3939
case ZMQ_$(NAME):
40-
{
4140
. if mode = "rw" | mode = "r"
4241
. gsl from "sockopts_restrict.gsl"
4342
.-
4443
. if php_type = "int"
4544
.-
46-
$(c_type) value;
47-
value_len = sizeof($(c_type));
48-
if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
49-
zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to get the option ZMQ::SOCKOPT_$(NAME) value: %s", zmq_strerror(errno));
50-
return;
51-
}
52-
RETURN_LONG(value);
45+
SOCKOPTS_GET_INT($(NAME), $(c_type));
5346
.-
5447
. elsif php_type = "string"
5548
.-
56-
$(c_type) value[$(max_length)];
57-
value_len = $(max_length);
58-
59-
if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
60-
zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to get the option ZMQ::SOCKOPT_$(NAME) value: %s", zmq_strerror(errno));
61-
return;
62-
}
63-
.-
64-
. if binary = "yes"
65-
RETURN_STRINGL(value, value_len);
66-
. else
67-
RETURN_STRINGL(value, value_len - 1);
68-
. endif /* .if binary = "yes" */
49+
SOCKOPTS_GET_STRING($(NAME), $(max_length), $(binary = 'yes'))
6950
.-
7051
. elsif php_type = "resource"
7152
.-
53+
{
7254
php_stream *stream = php_zmq_create_zmq_fd(getThis());
7355
if (stream) {
7456
php_stream_to_zval(stream, return_value);
7557
return;
7658
}
7759
RETURN_FALSE;
60+
}
7861
.-
7962
. else
8063
#error "Unknown type: ($type)"
@@ -85,7 +68,6 @@ PHP_METHOD(zmqsocket, getsockopt)
8568
return;
8669
.-
8770
. endif /* .if mode = "rw" | mode = "r" */
88-
}
8971
break;
9072

9173
# endif /* ZMQ_$(NAME) */

options/sockopts_set.gsl

+2-17
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,18 @@ PHP_METHOD(zmqsocket, setsockopt)
7474
. for option where !defined (is_alias)
7575
# ifdef ZMQ_$(NAME)
7676
case ZMQ_$(NAME):
77-
{
7877
.-
7978
. if mode = "rw" | mode = "w"
8079
. gsl from "sockopts_restrict.gsl"
8180
.-
8281
. if php_type = "int"
8382
.-
84-
$(c_type) value = ($(c_type)) zval_get_long(zv);
85-
86-
if (zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof($(c_type))) != 0) {
87-
zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_$(NAME) option: %s", zmq_strerror(errno));
88-
return;
89-
}
83+
SOCKOPTS_SET_INT($(NAME), $(c_type))
9084
.-
9185
. elsif php_type = "string"
9286
.-
93-
int rc;
94-
zend_string *str = zval_get_string(zv);
95-
96-
rc = zmq_setsockopt(intern->socket->z_socket, key, str->val, str->len);
97-
zend_string_release(str);
87+
SOCKOPTS_SET_STRING($(NAME))
9888

99-
if (rc != 0) {
100-
zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno, "Failed to set socket ZMQ::SOCKOPT_$(NAME) option: %s", zmq_strerror(errno));
101-
return;
102-
}
10389
.-
10490
. elsif php_type = "resource"
10591
.-
@@ -113,7 +99,6 @@ PHP_METHOD(zmqsocket, setsockopt)
11399
.-
114100
. endif /* .if mode = "rw" | mode = "w" */
115101
.-
116-
}
117102
break;
118103

119104
# endif /* ifdef ZMQ_$(NAME) */

0 commit comments

Comments
 (0)