This repository has been archived by the owner on May 27, 2022. It is now read-only.
forked from zeromq/czmq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sockopts.gsl
287 lines (250 loc) · 7.67 KB
/
sockopts.gsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
.output "include/zsockopt.h"
.for version
. for option
. if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
. option.ctype = "int"
. elsif type = "blob"
. option.ctype = "char *" # Enforce C strings
. else
. echo "E: unknown type: $(type)"
. endif
. endfor
.endfor
/* =========================================================================
zsockopt - get/set 0MQ socket options
GENERATED SOURCE CODE, DO NOT EDIT
-------------------------------------------------------------------------
Copyright (c) 1991-2012 iMatix Corporation <www.imatix.com>
Copyright other contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.
This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
=========================================================================
*/
#ifndef __ZSOCKOPT_H_INCLUDED__
#define __ZSOCKOPT_H_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif
// @interface
.for version
#if (ZMQ_VERSION_MAJOR == $(major))
// Get socket options
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "r"
. if type = "blob"
// Returns freshly allocated string, free when done
. endif
$(ctype) zsocket_$(name) (void *socket);
. endif
. if defined (.minor)
# endif
. endif
. endfor
// Set socket options
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "w"
void zsocket_set_$(name) (void *socket, $(ctype) $(name));
. endif
. if defined (.minor)
# endif
. endif
. endfor
. for header
$(string.trim(.):)
. endfor
#endif
.endfor
// Self test of this class
int zsockopt_test (Bool verbose);
// @end
.for version
// Deprecated function names
#if (ZMQ_VERSION_MAJOR == $(major))
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "r"
#define zsockopt_$(name) zsocket_$(name)
. endif
. if mode = "rw" | mode = "w"
#define zsockopt_set_$(name) zsocket_set_$(name)
. endif
. if defined (.minor)
# endif
. endif
. endfor
#endif
.endfor
#ifdef __cplusplus
}
#endif
#endif
.output "src/zsockopt.c"
/* =========================================================================
zsockopt - get/set 0MQ socket options
GENERATED SOURCE CODE, DO NOT EDIT
-------------------------------------------------------------------------
Copyright (c) 1991-2012 iMatix Corporation <www.imatix.com>
Copyright other contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.
This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
=========================================================================
*/
/*
@header
The zsockopt class provides access to the 0MQ getsockopt/setsockopt API.
@discuss
This class is generated, using the GSL code generator. See the sockopts
XML file, which provides the metadata, and the sockopts.gsl template,
which does the work.
@end
*/
#include "../include/czmq_prelude.h"
#include "../include/zctx.h"
#include "../include/zsocket.h"
#include "../include/zsockopt.h"
.for version
#if (ZMQ_VERSION_MAJOR == $(major))
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "w"
// --------------------------------------------------------------------------
// Set socket ZMQ_$(NAME) value
void
zsocket_set_$(name) (void *socket, $(ctype) $(name))
{
. if ctype = "int"
. if type = "uint64"
uint64_t value = $(name);
int rc = zmq_setsockopt (socket, ZMQ_$(NAME), &value, sizeof (uint64_t));
. elsif type = "int64"
int64_t value = $(name);
int rc = zmq_setsockopt (socket, ZMQ_$(NAME), &value, sizeof (int64_t));
. elsif type = "uint32"
uint32_t value = $(name);
int rc = zmq_setsockopt (socket, ZMQ_$(NAME), &value, sizeof (uint32_t));
. else
int rc = zmq_setsockopt (socket, ZMQ_$(NAME), &$(name), sizeof (int));
. endif
. else
int rc = zmq_setsockopt (socket, ZMQ_$(NAME), $(name), strlen ($(name)));
. endif
assert (rc == 0 || errno == ETERM);
}
. endif
. if mode = "rw" | mode = "r"
// --------------------------------------------------------------------------
// Return socket ZMQ_$(NAME) value
$(ctype)
zsocket_$(name) (void *socket)
{
. if type = "uint64"
uint64_t $(name);
size_t option_len = sizeof (uint64_t);
. elsif type = "int64"
int64_t $(name);
size_t option_len = sizeof (int64_t);
. elsif type = "uint32"
uint32_t $(name);
size_t option_len = sizeof (uint32_t);
. elsif type = "int"
int $(name);
size_t option_len = sizeof (int);
. elsif type = "blob"
size_t option_len = 255;
char *$(name) = zmalloc (option_len);
. endif
zmq_getsockopt (socket, ZMQ_$(NAME), &$(name), &option_len);
. if type = "int"
return $(name);
. else
return ($(ctype)) $(name);
. endif
}
. endif
. if defined (.minor)
# endif
. endif
. endfor
. for source
$(string.trim(.):)
. endfor
#endif
.endfor
// --------------------------------------------------------------------------
// Selftest
int
zsockopt_test (Bool verbose)
{
printf (" * zsockopt: ");
// @selftest
zctx_t *ctx = zctx_new ();
assert (ctx);
void *socket;
.for version
#if (ZMQ_VERSION_MAJOR == $(major))
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
socket = zsocket_new (ctx, ZMQ_$(TEST));
assert (socket);
. if mode = "rw" | mode = "w"
. if ctype = "int"
zsocket_set_$(name) (socket, 1);
. if mode = "rw"
assert (zsocket_$(name) (socket) == 1);
. endif
. else
zsocket_set_$(name) (socket, "test"); //a
. endif
. endif
. if mode = "rw" | mode = "r"
zsocket_$(name) (socket);
. endif
zsocket_destroy (ctx, socket);
. if defined (.minor)
# endif
. endif
. endfor
. for selftest
$(string.trim(.):)
. endfor
#endif
.endfor
zctx_destroy (&ctx);
// @end
printf ("OK\\n");
return 0;
}