czmq-ffi-gen 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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]
@@ -86,7 +86,7 @@ module CZMQ
86
86
  __new ptr
87
87
  end
88
88
 
89
- # Create new temporary file for writing via tmpfile. File is automaticaly
89
+ # Create new temporary file for writing via tmpfile. File is automatically
90
90
  # deleted on destroy
91
91
  # @return [CZMQ::Zfile]
92
92
  def self.tmp()
@@ -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.
@@ -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
+ ################################################################################