czmq-ffi-gen 0.14.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +19 -0
- data/README.md +11 -36
- data/lib/czmq-ffi-gen.rb +4 -2
- data/lib/czmq-ffi-gen/czmq/ffi.rb +168 -23
- data/lib/czmq-ffi-gen/czmq/ffi/version.rb +1 -1
- data/lib/czmq-ffi-gen/czmq/ffi/zactor.rb +2 -2
- data/lib/czmq-ffi-gen/czmq/ffi/zargs.rb +26 -24
- data/lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb +10 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zchunk.rb +41 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zconfig.rb +25 -2
- data/lib/czmq-ffi-gen/czmq/ffi/zfile.rb +1 -1
- data/lib/czmq-ffi-gen/czmq/ffi/zframe.rb +46 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_client.rb +113 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb +312 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb +263 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb +135 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_server_connection.rb +91 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhttp_server_options.rb +161 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zlistx.rb +34 -1
- data/lib/czmq-ffi-gen/czmq/ffi/zmsg.rb +16 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zosc.rb +487 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zpoller.rb +11 -9
- data/lib/czmq-ffi-gen/czmq/ffi/zproc.rb +53 -217
- data/lib/czmq-ffi-gen/czmq/ffi/zsock.rb +946 -2
- data/lib/czmq-ffi-gen/czmq/ffi/zsys.rb +217 -1
- data/lib/czmq-ffi-gen/czmq_ffi_extensions.rb +16 -0
- data/lib/czmq-ffi-gen/gem_version.rb +1 -1
- data/lib/czmq-ffi-gen/libzmq.rb +29 -2
- data/lib/czmq-ffi-gen/versions.rb +1 -11
- metadata +28 -33
- data/lib/czmq-ffi-gen/legacy.rb +0 -16
@@ -95,8 +95,8 @@ module CZMQ
|
|
95
95
|
#
|
96
96
|
# An example - to send $KTHXBAI string
|
97
97
|
#
|
98
|
-
# if (zstr_send (self
|
99
|
-
# zsock_wait (self
|
98
|
+
# if (zstr_send (self, "$KTHXBAI") == 0)
|
99
|
+
# zsock_wait (self);
|
100
100
|
# typedef void (zactor_destructor_fn) (
|
101
101
|
# zactor_t *self);
|
102
102
|
#
|
@@ -9,14 +9,17 @@ module CZMQ
|
|
9
9
|
# Platform independent command line argument parsing helpers
|
10
10
|
#
|
11
11
|
# There are two kind of elements provided by this class
|
12
|
-
#
|
13
|
-
#
|
12
|
+
# Named parameters, accessed by param_get and param_has methods
|
13
|
+
# * --named-parameter
|
14
|
+
# * --parameter with_value
|
15
|
+
# * -a val
|
16
|
+
# Positional arguments, accessed by zargs_first, zargs_next
|
14
17
|
#
|
15
18
|
# It DOES:
|
16
19
|
# * provide easy to use CLASS compatible API for accessing argv
|
17
20
|
# * is platform independent
|
18
21
|
# * provide getopt_long style -- argument, which delimits parameters from arguments
|
19
|
-
# * makes parameters
|
22
|
+
# * makes parameters position independent
|
20
23
|
#
|
21
24
|
# It does NOT
|
22
25
|
# * change argv
|
@@ -173,8 +176,7 @@ module CZMQ
|
|
173
176
|
result
|
174
177
|
end
|
175
178
|
|
176
|
-
# Return current parameter name, or NULL if there are no named
|
177
|
-
# parameters.
|
179
|
+
# Return current parameter name, or NULL if there are no named parameters.
|
178
180
|
#
|
179
181
|
# @return [String]
|
180
182
|
def param_name()
|
@@ -184,49 +186,49 @@ module CZMQ
|
|
184
186
|
result
|
185
187
|
end
|
186
188
|
|
187
|
-
# Return value of named parameter
|
188
|
-
# been specified, or special value for wich zargs_param_empty ()
|
189
|
-
# returns true.
|
189
|
+
# Return value of named parameter or NULL is it has no value (or was not specified)
|
190
190
|
#
|
191
|
-
# @param
|
191
|
+
# @param name [String, #to_s, nil]
|
192
192
|
# @return [String]
|
193
|
-
def
|
193
|
+
def get(name)
|
194
194
|
raise DestroyedError unless @ptr
|
195
195
|
self_p = @ptr
|
196
|
-
result = ::CZMQ::FFI.
|
196
|
+
result = ::CZMQ::FFI.zargs_get(self_p, name)
|
197
197
|
result
|
198
198
|
end
|
199
199
|
|
200
|
-
# Return value of
|
201
|
-
# been specified, or special value for wich zargs_param_empty ()
|
202
|
-
# returns true.
|
200
|
+
# Return value of one of parameter(s) or NULL is it has no value (or was not specified)
|
203
201
|
#
|
204
|
-
# @param
|
202
|
+
# @param name [String, #to_s, nil]
|
205
203
|
# @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
|
206
204
|
# @return [String]
|
207
|
-
def
|
205
|
+
def getx(name, *args)
|
208
206
|
raise DestroyedError unless @ptr
|
209
207
|
self_p = @ptr
|
210
|
-
result = ::CZMQ::FFI.
|
208
|
+
result = ::CZMQ::FFI.zargs_getx(self_p, name, *args)
|
211
209
|
result
|
212
210
|
end
|
213
211
|
|
214
|
-
# Returns true if
|
212
|
+
# Returns true if named parameter was specified on command line
|
215
213
|
#
|
214
|
+
# @param name [String, #to_s, nil]
|
216
215
|
# @return [Boolean]
|
217
|
-
def
|
216
|
+
def has(name)
|
218
217
|
raise DestroyedError unless @ptr
|
219
218
|
self_p = @ptr
|
220
|
-
result = ::CZMQ::FFI.
|
219
|
+
result = ::CZMQ::FFI.zargs_has(self_p, name)
|
221
220
|
result
|
222
221
|
end
|
223
222
|
|
224
|
-
# Returns true if parameter
|
223
|
+
# Returns true if named parameter(s) was specified on command line
|
225
224
|
#
|
226
|
-
# @param
|
225
|
+
# @param name [String, #to_s, nil]
|
226
|
+
# @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
|
227
227
|
# @return [Boolean]
|
228
|
-
def
|
229
|
-
|
228
|
+
def hasx(name, *args)
|
229
|
+
raise DestroyedError unless @ptr
|
230
|
+
self_p = @ptr
|
231
|
+
result = ::CZMQ::FFI.zargs_hasx(self_p, name, *args)
|
230
232
|
result
|
231
233
|
end
|
232
234
|
|
@@ -205,6 +205,16 @@ module CZMQ
|
|
205
205
|
result
|
206
206
|
end
|
207
207
|
|
208
|
+
# Return the state stored in certstore
|
209
|
+
#
|
210
|
+
# @return [::FFI::Pointer]
|
211
|
+
def state()
|
212
|
+
raise DestroyedError unless @ptr
|
213
|
+
self_p = @ptr
|
214
|
+
result = ::CZMQ::FFI.zcertstore_state(self_p)
|
215
|
+
result
|
216
|
+
end
|
217
|
+
|
208
218
|
# Self test of this class
|
209
219
|
#
|
210
220
|
# @param verbose [Boolean]
|
@@ -73,6 +73,22 @@ module CZMQ
|
|
73
73
|
@finalizer = nil
|
74
74
|
end
|
75
75
|
|
76
|
+
# Create a new callback of the following type:
|
77
|
+
# Destroy an item
|
78
|
+
# typedef void (zchunk_destructor_fn) (
|
79
|
+
# void **hint);
|
80
|
+
#
|
81
|
+
# @note WARNING: If your Ruby code doesn't retain a reference to the
|
82
|
+
# FFI::Function object after passing it to a C function call,
|
83
|
+
# it may be garbage collected while C still holds the pointer,
|
84
|
+
# potentially resulting in a segmentation fault.
|
85
|
+
def self.destructor_fn
|
86
|
+
::FFI::Function.new :void, [:pointer], blocking: true do |hint|
|
87
|
+
result = yield hint
|
88
|
+
result
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
76
92
|
# Create a new chunk of the specified size. If you specify the data, it
|
77
93
|
# is copied into the chunk. If you do not specify the data, the chunk is
|
78
94
|
# allocated and left empty, and you can then add data using zchunk_append.
|
@@ -85,6 +101,19 @@ module CZMQ
|
|
85
101
|
__new ptr
|
86
102
|
end
|
87
103
|
|
104
|
+
# Create a new chunk from memory. Take ownership of the memory and calling the destructor
|
105
|
+
# on destroy.
|
106
|
+
# @param data [::FFI::Pointer, #to_ptr]
|
107
|
+
# @param size [Integer, #to_int, #to_i]
|
108
|
+
# @param destructor [::FFI::Pointer, #to_ptr]
|
109
|
+
# @param hint [::FFI::Pointer, #to_ptr]
|
110
|
+
# @return [CZMQ::Zchunk]
|
111
|
+
def self.frommem(data, size, destructor, hint)
|
112
|
+
size = Integer(size)
|
113
|
+
ptr = ::CZMQ::FFI.zchunk_frommem(data, size, destructor, hint)
|
114
|
+
__new ptr
|
115
|
+
end
|
116
|
+
|
88
117
|
# Destroy a chunk
|
89
118
|
#
|
90
119
|
# @return [void]
|
@@ -317,6 +346,18 @@ module CZMQ
|
|
317
346
|
result
|
318
347
|
end
|
319
348
|
|
349
|
+
# Transform zchunk into a zframe that can be sent in a message.
|
350
|
+
# Take ownership of the chunk.
|
351
|
+
#
|
352
|
+
# @param self_p [#__ptr_give_ref]
|
353
|
+
# @return [Zframe]
|
354
|
+
def self.packx(self_p)
|
355
|
+
self_p = self_p.__ptr_give_ref
|
356
|
+
result = ::CZMQ::FFI.zchunk_packx(self_p)
|
357
|
+
result = Zframe.__new result, true
|
358
|
+
result
|
359
|
+
end
|
360
|
+
|
320
361
|
# Transform a zframe into a zchunk.
|
321
362
|
#
|
322
363
|
# @param frame [Zframe, #__ptr]
|
@@ -131,6 +131,19 @@ module CZMQ
|
|
131
131
|
result
|
132
132
|
end
|
133
133
|
|
134
|
+
# Create copy of zconfig, caller MUST free the value
|
135
|
+
# Create copy of config, as new zconfig object. Returns a fresh zconfig_t
|
136
|
+
# object. If config is null, or memory was exhausted, returns null.
|
137
|
+
#
|
138
|
+
# @return [Zconfig]
|
139
|
+
def dup()
|
140
|
+
raise DestroyedError unless @ptr
|
141
|
+
self_p = @ptr
|
142
|
+
result = ::CZMQ::FFI.zconfig_dup(self_p)
|
143
|
+
result = Zconfig.__new result, true
|
144
|
+
result
|
145
|
+
end
|
146
|
+
|
134
147
|
# Return name of config item
|
135
148
|
#
|
136
149
|
# @return [::FFI::Pointer]
|
@@ -402,12 +415,22 @@ module CZMQ
|
|
402
415
|
result
|
403
416
|
end
|
404
417
|
|
405
|
-
# Destroy subtree (
|
418
|
+
# Destroy subtree (all children)
|
406
419
|
#
|
407
420
|
# @return [void]
|
408
|
-
def
|
421
|
+
def remove_subtree()
|
409
422
|
raise DestroyedError unless @ptr
|
410
423
|
self_p = @ptr
|
424
|
+
result = ::CZMQ::FFI.zconfig_remove_subtree(self_p)
|
425
|
+
result
|
426
|
+
end
|
427
|
+
|
428
|
+
# Destroy node and subtree (all children)
|
429
|
+
#
|
430
|
+
# @param self_p [#__ptr_give_ref]
|
431
|
+
# @return [void]
|
432
|
+
def self.remove(self_p)
|
433
|
+
self_p = self_p.__ptr_give_ref
|
411
434
|
result = ::CZMQ::FFI.zconfig_remove(self_p)
|
412
435
|
result
|
413
436
|
end
|
@@ -82,6 +82,22 @@ module CZMQ
|
|
82
82
|
@finalizer = nil
|
83
83
|
end
|
84
84
|
|
85
|
+
# Create a new callback of the following type:
|
86
|
+
# Destroy an item
|
87
|
+
# typedef void (zframe_destructor_fn) (
|
88
|
+
# void **hint);
|
89
|
+
#
|
90
|
+
# @note WARNING: If your Ruby code doesn't retain a reference to the
|
91
|
+
# FFI::Function object after passing it to a C function call,
|
92
|
+
# it may be garbage collected while C still holds the pointer,
|
93
|
+
# potentially resulting in a segmentation fault.
|
94
|
+
def self.destructor_fn
|
95
|
+
::FFI::Function.new :void, [:pointer], blocking: true do |hint|
|
96
|
+
result = yield hint
|
97
|
+
result
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
85
101
|
# Create a new frame. If size is not null, allocates the frame data
|
86
102
|
# to the specified size. If additionally, data is not null, copies
|
87
103
|
# size octets from the specified data into the frame body.
|
@@ -109,6 +125,19 @@ module CZMQ
|
|
109
125
|
__new ptr
|
110
126
|
end
|
111
127
|
|
128
|
+
# Create a new frame from memory. Take ownership of the memory and calling the destructor
|
129
|
+
# on destroy.
|
130
|
+
# @param data [::FFI::Pointer, #to_ptr]
|
131
|
+
# @param size [Integer, #to_int, #to_i]
|
132
|
+
# @param destructor [::FFI::Pointer, #to_ptr]
|
133
|
+
# @param hint [::FFI::Pointer, #to_ptr]
|
134
|
+
# @return [CZMQ::Zframe]
|
135
|
+
def self.frommem(data, size, destructor, hint)
|
136
|
+
size = Integer(size)
|
137
|
+
ptr = ::CZMQ::FFI.zframe_frommem(data, size, destructor, hint)
|
138
|
+
__new ptr
|
139
|
+
end
|
140
|
+
|
112
141
|
# Receive frame from socket, returns zframe_t object or NULL if the recv
|
113
142
|
# was interrupted. Does a blocking recv, if you want to not block then use
|
114
143
|
# zpoller or zloop.
|
@@ -322,6 +351,7 @@ module CZMQ
|
|
322
351
|
|
323
352
|
# Send message to zsys log sink (may be stdout, or system facility as
|
324
353
|
# configured by zsys_set_logstream). Prefix shows before frame, if not null.
|
354
|
+
# Long messages are truncated.
|
325
355
|
#
|
326
356
|
# @param prefix [String, #to_s, nil]
|
327
357
|
# @return [void]
|
@@ -332,6 +362,22 @@ module CZMQ
|
|
332
362
|
result
|
333
363
|
end
|
334
364
|
|
365
|
+
# Send message to zsys log sink (may be stdout, or system facility as
|
366
|
+
# configured by zsys_set_logstream). Prefix shows before frame, if not null.
|
367
|
+
# Message length is specified; no truncation unless length is zero.
|
368
|
+
# Backwards compatible with zframe_print when length is zero.
|
369
|
+
#
|
370
|
+
# @param prefix [String, #to_s, nil]
|
371
|
+
# @param length [Integer, #to_int, #to_i]
|
372
|
+
# @return [void]
|
373
|
+
def print_n(prefix, length)
|
374
|
+
raise DestroyedError unless @ptr
|
375
|
+
self_p = @ptr
|
376
|
+
length = Integer(length)
|
377
|
+
result = ::CZMQ::FFI.zframe_print_n(self_p, prefix, length)
|
378
|
+
result
|
379
|
+
end
|
380
|
+
|
335
381
|
# Probe the supplied object, and report if it looks like a zframe_t.
|
336
382
|
#
|
337
383
|
# @param self_ [::FFI::Pointer, #to_ptr]
|
@@ -0,0 +1,113 @@
|
|
1
|
+
################################################################################
|
2
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
3
|
+
# Read the zproject/README.md for information about making permanent changes. #
|
4
|
+
################################################################################
|
5
|
+
|
6
|
+
module CZMQ
|
7
|
+
module FFI
|
8
|
+
|
9
|
+
# Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
|
10
|
+
# Use zhttp_request class to create and send the request.
|
11
|
+
# Use zhttp_response class to receive the response.
|
12
|
+
# @note This class is 100% generated using zproject.
|
13
|
+
class ZhttpClient
|
14
|
+
# Raised when one tries to use an instance of {ZhttpClient} after
|
15
|
+
# the internal pointer to the native object has been nullified.
|
16
|
+
class DestroyedError < RuntimeError; end
|
17
|
+
|
18
|
+
# Boilerplate for self pointer, initializer, and finalizer
|
19
|
+
class << self
|
20
|
+
alias :__new :new
|
21
|
+
end
|
22
|
+
# Attaches the pointer _ptr_ to this instance and defines a finalizer for
|
23
|
+
# it if necessary.
|
24
|
+
# @param ptr [::FFI::Pointer]
|
25
|
+
# @param finalize [Boolean]
|
26
|
+
def initialize(ptr, finalize = true)
|
27
|
+
@ptr = ptr
|
28
|
+
if @ptr.null?
|
29
|
+
@ptr = nil # Remove null pointers so we don't have to test for them.
|
30
|
+
elsif finalize
|
31
|
+
@finalizer = self.class.create_finalizer_for @ptr
|
32
|
+
ObjectSpace.define_finalizer self, @finalizer
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# @param ptr [::FFI::Pointer]
|
36
|
+
# @return [Proc]
|
37
|
+
def self.create_finalizer_for(ptr)
|
38
|
+
Proc.new do
|
39
|
+
ptr_ptr = ::FFI::MemoryPointer.new :pointer
|
40
|
+
ptr_ptr.write_pointer ptr
|
41
|
+
::CZMQ::FFI.zhttp_client_destroy ptr_ptr
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# @return [Boolean]
|
45
|
+
def null?
|
46
|
+
!@ptr or @ptr.null?
|
47
|
+
end
|
48
|
+
# Return internal pointer
|
49
|
+
# @return [::FFI::Pointer]
|
50
|
+
def __ptr
|
51
|
+
raise DestroyedError unless @ptr
|
52
|
+
@ptr
|
53
|
+
end
|
54
|
+
# So external Libraries can just pass the Object to a FFI function which expects a :pointer
|
55
|
+
alias_method :to_ptr, :__ptr
|
56
|
+
# Nullify internal pointer and return pointer pointer.
|
57
|
+
# @note This detaches the current instance from the native object
|
58
|
+
# and thus makes it unusable.
|
59
|
+
# @return [::FFI::MemoryPointer] the pointer pointing to a pointer
|
60
|
+
# pointing to the native object
|
61
|
+
def __ptr_give_ref
|
62
|
+
raise DestroyedError unless @ptr
|
63
|
+
ptr_ptr = ::FFI::MemoryPointer.new :pointer
|
64
|
+
ptr_ptr.write_pointer @ptr
|
65
|
+
__undef_finalizer if @finalizer
|
66
|
+
@ptr = nil
|
67
|
+
ptr_ptr
|
68
|
+
end
|
69
|
+
# Undefines the finalizer for this object.
|
70
|
+
# @note Only use this if you need to and can guarantee that the native
|
71
|
+
# object will be freed by other means.
|
72
|
+
# @return [void]
|
73
|
+
def __undef_finalizer
|
74
|
+
ObjectSpace.undefine_finalizer self
|
75
|
+
@finalizer = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new http client
|
79
|
+
# @param verbose [Boolean]
|
80
|
+
# @return [CZMQ::ZhttpClient]
|
81
|
+
def self.new(verbose)
|
82
|
+
verbose = !(0==verbose||!verbose) # boolean
|
83
|
+
ptr = ::CZMQ::FFI.zhttp_client_new(verbose)
|
84
|
+
__new ptr
|
85
|
+
end
|
86
|
+
|
87
|
+
# Destroy an http client
|
88
|
+
#
|
89
|
+
# @return [void]
|
90
|
+
def destroy()
|
91
|
+
return unless @ptr
|
92
|
+
self_p = __ptr_give_ref
|
93
|
+
result = ::CZMQ::FFI.zhttp_client_destroy(self_p)
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
# Self test of this class.
|
98
|
+
#
|
99
|
+
# @param verbose [Boolean]
|
100
|
+
# @return [void]
|
101
|
+
def self.test(verbose)
|
102
|
+
verbose = !(0==verbose||!verbose) # boolean
|
103
|
+
result = ::CZMQ::FFI.zhttp_client_test(verbose)
|
104
|
+
result
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
################################################################################
|
111
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
112
|
+
# Read the zproject/README.md for information about making permanent changes. #
|
113
|
+
################################################################################
|
@@ -0,0 +1,312 @@
|
|
1
|
+
################################################################################
|
2
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
3
|
+
# Read the zproject/README.md for information about making permanent changes. #
|
4
|
+
################################################################################
|
5
|
+
|
6
|
+
module CZMQ
|
7
|
+
module FFI
|
8
|
+
|
9
|
+
# Http request that can be received from zhttp_server or sent to zhttp_client.
|
10
|
+
# Class can be reused between send & recv calls.
|
11
|
+
# Headers and Content is being destroyed after every send call.
|
12
|
+
# @note This class is 100% generated using zproject.
|
13
|
+
class ZhttpRequest
|
14
|
+
# Raised when one tries to use an instance of {ZhttpRequest} after
|
15
|
+
# the internal pointer to the native object has been nullified.
|
16
|
+
class DestroyedError < RuntimeError; end
|
17
|
+
|
18
|
+
# Boilerplate for self pointer, initializer, and finalizer
|
19
|
+
class << self
|
20
|
+
alias :__new :new
|
21
|
+
end
|
22
|
+
# Attaches the pointer _ptr_ to this instance and defines a finalizer for
|
23
|
+
# it if necessary.
|
24
|
+
# @param ptr [::FFI::Pointer]
|
25
|
+
# @param finalize [Boolean]
|
26
|
+
def initialize(ptr, finalize = true)
|
27
|
+
@ptr = ptr
|
28
|
+
if @ptr.null?
|
29
|
+
@ptr = nil # Remove null pointers so we don't have to test for them.
|
30
|
+
elsif finalize
|
31
|
+
@finalizer = self.class.create_finalizer_for @ptr
|
32
|
+
ObjectSpace.define_finalizer self, @finalizer
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# @param ptr [::FFI::Pointer]
|
36
|
+
# @return [Proc]
|
37
|
+
def self.create_finalizer_for(ptr)
|
38
|
+
Proc.new do
|
39
|
+
ptr_ptr = ::FFI::MemoryPointer.new :pointer
|
40
|
+
ptr_ptr.write_pointer ptr
|
41
|
+
::CZMQ::FFI.zhttp_request_destroy ptr_ptr
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# @return [Boolean]
|
45
|
+
def null?
|
46
|
+
!@ptr or @ptr.null?
|
47
|
+
end
|
48
|
+
# Return internal pointer
|
49
|
+
# @return [::FFI::Pointer]
|
50
|
+
def __ptr
|
51
|
+
raise DestroyedError unless @ptr
|
52
|
+
@ptr
|
53
|
+
end
|
54
|
+
# So external Libraries can just pass the Object to a FFI function which expects a :pointer
|
55
|
+
alias_method :to_ptr, :__ptr
|
56
|
+
# Nullify internal pointer and return pointer pointer.
|
57
|
+
# @note This detaches the current instance from the native object
|
58
|
+
# and thus makes it unusable.
|
59
|
+
# @return [::FFI::MemoryPointer] the pointer pointing to a pointer
|
60
|
+
# pointing to the native object
|
61
|
+
def __ptr_give_ref
|
62
|
+
raise DestroyedError unless @ptr
|
63
|
+
ptr_ptr = ::FFI::MemoryPointer.new :pointer
|
64
|
+
ptr_ptr.write_pointer @ptr
|
65
|
+
__undef_finalizer if @finalizer
|
66
|
+
@ptr = nil
|
67
|
+
ptr_ptr
|
68
|
+
end
|
69
|
+
# Undefines the finalizer for this object.
|
70
|
+
# @note Only use this if you need to and can guarantee that the native
|
71
|
+
# object will be freed by other means.
|
72
|
+
# @return [void]
|
73
|
+
def __undef_finalizer
|
74
|
+
ObjectSpace.undefine_finalizer self
|
75
|
+
@finalizer = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new http request.
|
79
|
+
# @return [CZMQ::ZhttpRequest]
|
80
|
+
def self.new()
|
81
|
+
ptr = ::CZMQ::FFI.zhttp_request_new()
|
82
|
+
__new ptr
|
83
|
+
end
|
84
|
+
|
85
|
+
# Destroy an http request.
|
86
|
+
#
|
87
|
+
# @return [void]
|
88
|
+
def destroy()
|
89
|
+
return unless @ptr
|
90
|
+
self_p = __ptr_give_ref
|
91
|
+
result = ::CZMQ::FFI.zhttp_request_destroy(self_p)
|
92
|
+
result
|
93
|
+
end
|
94
|
+
|
95
|
+
# Receive a new request from zhttp_server.
|
96
|
+
# Return the underlying connection if successful, to be used when calling zhttp_response_send.
|
97
|
+
#
|
98
|
+
# @param sock [Zsock, #__ptr]
|
99
|
+
# @return [::FFI::Pointer]
|
100
|
+
def recv(sock)
|
101
|
+
raise DestroyedError unless @ptr
|
102
|
+
self_p = @ptr
|
103
|
+
sock = sock.__ptr if sock
|
104
|
+
result = ::CZMQ::FFI.zhttp_request_recv(self_p, sock)
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
# Send a request to zhttp_client.
|
109
|
+
# Url and the request path will be concatenated.
|
110
|
+
# This behavior is useful for url rewrite and reverse proxy.
|
111
|
+
#
|
112
|
+
# Send also allow two user provided arguments which will be returned with the response.
|
113
|
+
# The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
|
114
|
+
#
|
115
|
+
# @param client [ZhttpClient, #__ptr]
|
116
|
+
# @param timeout [Integer, #to_int, #to_i]
|
117
|
+
# @param arg [::FFI::Pointer, #to_ptr]
|
118
|
+
# @param arg2 [::FFI::Pointer, #to_ptr]
|
119
|
+
# @return [Integer]
|
120
|
+
def send(client, timeout, arg, arg2)
|
121
|
+
raise DestroyedError unless @ptr
|
122
|
+
self_p = @ptr
|
123
|
+
client = client.__ptr if client
|
124
|
+
timeout = Integer(timeout)
|
125
|
+
result = ::CZMQ::FFI.zhttp_request_send(self_p, client, timeout, arg, arg2)
|
126
|
+
result
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get the request method
|
130
|
+
#
|
131
|
+
# @return [String]
|
132
|
+
def method()
|
133
|
+
raise DestroyedError unless @ptr
|
134
|
+
self_p = @ptr
|
135
|
+
result = ::CZMQ::FFI.zhttp_request_method(self_p)
|
136
|
+
result
|
137
|
+
end
|
138
|
+
|
139
|
+
# Set the request method
|
140
|
+
#
|
141
|
+
# @param method [String, #to_s, nil]
|
142
|
+
# @return [void]
|
143
|
+
def set_method(method)
|
144
|
+
raise DestroyedError unless @ptr
|
145
|
+
self_p = @ptr
|
146
|
+
result = ::CZMQ::FFI.zhttp_request_set_method(self_p, method)
|
147
|
+
result
|
148
|
+
end
|
149
|
+
|
150
|
+
# Get the request url.
|
151
|
+
# When receiving a request from http server this is only the path part of the url.
|
152
|
+
#
|
153
|
+
# @return [String]
|
154
|
+
def url()
|
155
|
+
raise DestroyedError unless @ptr
|
156
|
+
self_p = @ptr
|
157
|
+
result = ::CZMQ::FFI.zhttp_request_url(self_p)
|
158
|
+
result
|
159
|
+
end
|
160
|
+
|
161
|
+
# Set the request url
|
162
|
+
# When sending a request to http client this should be full url.
|
163
|
+
#
|
164
|
+
# @param url [String, #to_s, nil]
|
165
|
+
# @return [void]
|
166
|
+
def set_url(url)
|
167
|
+
raise DestroyedError unless @ptr
|
168
|
+
self_p = @ptr
|
169
|
+
result = ::CZMQ::FFI.zhttp_request_set_url(self_p, url)
|
170
|
+
result
|
171
|
+
end
|
172
|
+
|
173
|
+
# Get the request content type
|
174
|
+
#
|
175
|
+
# @return [String]
|
176
|
+
def content_type()
|
177
|
+
raise DestroyedError unless @ptr
|
178
|
+
self_p = @ptr
|
179
|
+
result = ::CZMQ::FFI.zhttp_request_content_type(self_p)
|
180
|
+
result
|
181
|
+
end
|
182
|
+
|
183
|
+
# Set the request content type
|
184
|
+
#
|
185
|
+
# @param content_type [String, #to_s, nil]
|
186
|
+
# @return [void]
|
187
|
+
def set_content_type(content_type)
|
188
|
+
raise DestroyedError unless @ptr
|
189
|
+
self_p = @ptr
|
190
|
+
result = ::CZMQ::FFI.zhttp_request_set_content_type(self_p, content_type)
|
191
|
+
result
|
192
|
+
end
|
193
|
+
|
194
|
+
# Get the content length of the request
|
195
|
+
#
|
196
|
+
# @return [Integer]
|
197
|
+
def content_length()
|
198
|
+
raise DestroyedError unless @ptr
|
199
|
+
self_p = @ptr
|
200
|
+
result = ::CZMQ::FFI.zhttp_request_content_length(self_p)
|
201
|
+
result
|
202
|
+
end
|
203
|
+
|
204
|
+
# Get the headers of the request
|
205
|
+
#
|
206
|
+
# @return [Zhash]
|
207
|
+
def headers()
|
208
|
+
raise DestroyedError unless @ptr
|
209
|
+
self_p = @ptr
|
210
|
+
result = ::CZMQ::FFI.zhttp_request_headers(self_p)
|
211
|
+
result = Zhash.__new result, false
|
212
|
+
result
|
213
|
+
end
|
214
|
+
|
215
|
+
# Get the content of the request.
|
216
|
+
#
|
217
|
+
# @return [String]
|
218
|
+
def content()
|
219
|
+
raise DestroyedError unless @ptr
|
220
|
+
self_p = @ptr
|
221
|
+
result = ::CZMQ::FFI.zhttp_request_content(self_p)
|
222
|
+
result
|
223
|
+
end
|
224
|
+
|
225
|
+
# Get the content of the request.
|
226
|
+
#
|
227
|
+
# @return [::FFI::AutoPointer]
|
228
|
+
def get_content()
|
229
|
+
raise DestroyedError unless @ptr
|
230
|
+
self_p = @ptr
|
231
|
+
result = ::CZMQ::FFI.zhttp_request_get_content(self_p)
|
232
|
+
result = ::FFI::AutoPointer.new(result, LibC.method(:free))
|
233
|
+
result
|
234
|
+
end
|
235
|
+
|
236
|
+
# Set the content of the request.
|
237
|
+
# Content must by dynamically allocated string.
|
238
|
+
# Takes ownership of the content.
|
239
|
+
#
|
240
|
+
# @param content [::FFI::Pointer, #to_ptr]
|
241
|
+
# @return [void]
|
242
|
+
def set_content(content)
|
243
|
+
raise DestroyedError unless @ptr
|
244
|
+
self_p = @ptr
|
245
|
+
result = ::CZMQ::FFI.zhttp_request_set_content(self_p, content)
|
246
|
+
result
|
247
|
+
end
|
248
|
+
|
249
|
+
# Set the content of the request..
|
250
|
+
# The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
|
251
|
+
#
|
252
|
+
# @param content [String, #to_s, nil]
|
253
|
+
# @return [void]
|
254
|
+
def set_content_const(content)
|
255
|
+
raise DestroyedError unless @ptr
|
256
|
+
self_p = @ptr
|
257
|
+
result = ::CZMQ::FFI.zhttp_request_set_content_const(self_p, content)
|
258
|
+
result
|
259
|
+
end
|
260
|
+
|
261
|
+
# Set the content to NULL
|
262
|
+
#
|
263
|
+
# @return [void]
|
264
|
+
def reset_content()
|
265
|
+
raise DestroyedError unless @ptr
|
266
|
+
self_p = @ptr
|
267
|
+
result = ::CZMQ::FFI.zhttp_request_reset_content(self_p)
|
268
|
+
result
|
269
|
+
end
|
270
|
+
|
271
|
+
# Match the path of the request.
|
272
|
+
# Support wildcards with '%s' symbol inside the match string.
|
273
|
+
# Matching wildcards until the next '/', '?' or '\0'.
|
274
|
+
# On successful match the variadic arguments will be filled with the matching strings.
|
275
|
+
# On successful match the method is modifying the url field and break it into substrings.
|
276
|
+
# If you need to use the url, do it before matching or take a copy.
|
277
|
+
#
|
278
|
+
# User must not free the variadic arguments as they are part of the url.
|
279
|
+
#
|
280
|
+
# To use the percent symbol, just double it, e.g "%%something".
|
281
|
+
#
|
282
|
+
# Example:
|
283
|
+
# if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
|
284
|
+
#
|
285
|
+
# @param method [String, #to_s, nil]
|
286
|
+
# @param path [String, #to_s, nil]
|
287
|
+
# @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
|
288
|
+
# @return [Boolean]
|
289
|
+
def match(method, path, *args)
|
290
|
+
raise DestroyedError unless @ptr
|
291
|
+
self_p = @ptr
|
292
|
+
result = ::CZMQ::FFI.zhttp_request_match(self_p, method, path, *args)
|
293
|
+
result
|
294
|
+
end
|
295
|
+
|
296
|
+
# Self test of this class.
|
297
|
+
#
|
298
|
+
# @param verbose [Boolean]
|
299
|
+
# @return [void]
|
300
|
+
def self.test(verbose)
|
301
|
+
verbose = !(0==verbose||!verbose) # boolean
|
302
|
+
result = ::CZMQ::FFI.zhttp_request_test(verbose)
|
303
|
+
result
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
################################################################################
|
310
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
311
|
+
# Read the zproject/README.md for information about making permanent changes. #
|
312
|
+
################################################################################
|