rabbitmq 0.2.5 → 1.0.0.pre.pre

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.
@@ -2,21 +2,37 @@
2
2
  require 'socket'
3
3
 
4
4
  module RabbitMQ
5
- class Connection
5
+ class Client
6
6
 
7
+ # Raised when an operation is performed on an alread-destroyed {Client}.
7
8
  class DestroyedError < RuntimeError; end
8
9
 
9
- class Transport
10
-
10
+ # Represents a connection to a single RabbitMQ server.
11
+ # Used internally by the {Client} class.
12
+ # @api private
13
+ class Connection
11
14
  attr_reader :ptr
15
+ attr_reader :options
12
16
 
13
- def initialize(connnection)
17
+ def initialize(*args)
14
18
  @ptr = FFI.amqp_new_connection
15
19
  @frame = FFI::Frame.new
16
- @connection = connnection
17
20
 
18
21
  create_socket!
19
22
 
23
+ info = Util.connection_info(*args)
24
+ @options = {
25
+ ssl: (info.fetch(:ssl) ? true : false),
26
+ host: info.fetch(:host).to_s,
27
+ port: Integer(info.fetch(:port)),
28
+ user: info.fetch(:user).to_s,
29
+ password: info.fetch(:password).to_s,
30
+ vhost: info.fetch(:vhost).to_s,
31
+ max_channels: Integer(info.fetch(:max_channels, FFI::CHANNEL_MAX_ID)),
32
+ max_frame_size: Integer(info.fetch(:max_frame_size, 131072)),
33
+ heartbeat_interval: 0, # not fully implemented in librabbitmq
34
+ }
35
+
20
36
  @finalizer = self.class.create_finalizer_for(@ptr)
21
37
  ObjectSpace.define_finalizer(self, @finalizer)
22
38
  end
@@ -42,6 +58,11 @@ module RabbitMQ
42
58
  @ptr
43
59
  end
44
60
 
61
+ def start
62
+ connect_socket!
63
+ login!
64
+ end
65
+
45
66
  def close
46
67
  raise DestroyedError unless @ptr
47
68
  FFI.amqp_connection_close(@ptr, 200)
@@ -56,11 +77,11 @@ module RabbitMQ
56
77
 
57
78
  def connect_socket!
58
79
  raise DestroyedError unless @ptr
59
- raise NotImplementedError if @connection.ssl?
80
+ raise NotImplementedError if @options[:ssl]
60
81
 
61
82
  create_socket!
62
83
  Util.error_check :"opening a socket",
63
- FFI.amqp_socket_open(@socket, @connection.host, @connection.port)
84
+ FFI.amqp_socket_open(@socket, @options[:host], @options[:port])
64
85
 
65
86
  @ruby_socket = Socket.for_fd(FFI.amqp_get_sockfd(@ptr))
66
87
  @ruby_socket.autoclose = false
@@ -69,10 +90,10 @@ module RabbitMQ
69
90
  def login!
70
91
  raise DestroyedError unless @ptr
71
92
 
72
- res = FFI.amqp_login(@ptr, @connection.vhost,
73
- @connection.max_channels, @connection.max_frame_size,
74
- @connection.heartbeat_interval, :plain,
75
- :string, @connection.user, :string, @connection.password)
93
+ res = FFI.amqp_login(@ptr, @options[:vhost],
94
+ @options[:max_channels], @options[:max_frame_size],
95
+ @options[:heartbeat_interval], :plain,
96
+ :string, @options[:user], :string, @options[:password])
76
97
 
77
98
  case res[:reply_type]
78
99
  when :library_exception; Util.error_check :"logging in", res[:library_error]
data/lib/rabbitmq/ffi.rb CHANGED
@@ -3,6 +3,11 @@ require 'ffi'
3
3
 
4
4
 
5
5
  module RabbitMQ
6
+
7
+ # Bindings and wrappers for the native functions and structures exposed by
8
+ # the librabbitmq C library. This module is for internal use only so that
9
+ # all dependencies on the implementation of the C library are abstracted.
10
+ # @api private
6
11
  module FFI
7
12
  extend ::FFI::Library
8
13
 
@@ -12,493 +17,491 @@ module RabbitMQ
12
17
  ffi_lib \
13
18
  File.expand_path("../../ext/rabbitmq/#{libfile}", File.dirname(__FILE__))
14
19
 
15
- begin # TODO: remove begin/end block
16
- opts = {
17
- blocking: true # only necessary on MRI to deal with the GIL.
18
- }
19
-
20
- attach_function :free, [:pointer], :void, **opts
21
- attach_function :malloc, [:size_t], :pointer, **opts
22
-
23
- attach_function :amqp_version_number, [], :uint32, **opts
24
- attach_function :amqp_version, [], :string, **opts
25
-
26
- Status = enum ::FFI::TypeDefs[:int], [
27
- :ok, 0x0,
28
- :no_memory, -0x0001,
29
- :bad_amqp_data, -0x0002,
30
- :unknown_class, -0x0003,
31
- :unknown_method, -0x0004,
32
- :hostname_resolution_failed, -0x0005,
33
- :incompatible_amqp_version, -0x0006,
34
- :connection_closed, -0x0007,
35
- :bad_url, -0x0008,
36
- :socket_error, -0x0009,
37
- :invalid_parameter, -0x000A,
38
- :table_too_big, -0x000B,
39
- :wrong_method, -0x000C,
40
- :timeout, -0x000D,
41
- :timer_failure, -0x000E,
42
- :heartbeat_timeout, -0x000F,
43
- :unexpected_state, -0x0010,
44
- :unexpected_socket_closed, -0x0011,
45
- :unexpected_socket_inuse, -0x0012,
46
- :tcp_error, -0x0100,
47
- :tcp_socketlib_init_error, -0x0101,
48
- :ssl_error, -0x0200,
49
- :ssl_hostname_verify_failed, -0x0201,
50
- :ssl_peer_verify_failed, -0x0202,
51
- :ssl_connection_failed, -0x0203,
52
- ]
53
-
54
- DeliveryMode = enum ::FFI::TypeDefs[:uint8], [
55
- :nonpersistent, 1,
56
- :persistent, 2,
57
- ]
58
-
59
- class Timeval < ::FFI::Struct
60
- layout :tv_sec, :time_t,
61
- :tv_usec, :suseconds_t
62
- end
63
-
64
- class Boolean
65
- extend ::FFI::DataConverter
66
- native_type ::FFI::TypeDefs[:int]
67
- def self.to_native val, ctx; val ? 1 : 0; end
68
- def self.from_native val, ctx; val != 0; end
69
- end
70
-
71
- MethodNumber = enum ::FFI::TypeDefs[:uint32], [
72
- :connection_start, 0x000A000A, # 10, 10; 655370
73
- :connection_start_ok, 0x000A000B, # 10, 11; 655371
74
- :connection_secure, 0x000A0014, # 10, 20; 655380
75
- :connection_secure_ok, 0x000A0015, # 10, 21; 655381
76
- :connection_tune, 0x000A001E, # 10, 30; 655390
77
- :connection_tune_ok, 0x000A001F, # 10, 31; 655391
78
- :connection_open, 0x000A0028, # 10, 40; 655400
79
- :connection_open_ok, 0x000A0029, # 10, 41; 655401
80
- :connection_close, 0x000A0032, # 10, 50; 655410
81
- :connection_close_ok, 0x000A0033, # 10, 51; 655411
82
- :connection_blocked, 0x000A003C, # 10, 60; 655420
83
- :connection_unblocked, 0x000A003D, # 10, 61; 655421
84
- :channel_open, 0x0014000A, # 20, 10; 1310730
85
- :channel_open_ok, 0x0014000B, # 20, 11; 1310731
86
- :channel_flow, 0x00140014, # 20, 20; 1310740
87
- :channel_flow_ok, 0x00140015, # 20, 21; 1310741
88
- :channel_close, 0x00140028, # 20, 40; 1310760
89
- :channel_close_ok, 0x00140029, # 20, 41; 1310761
90
- :access_request, 0x001E000A, # 30, 10; 1966090
91
- :access_request_ok, 0x001E000B, # 30, 11; 1966091
92
- :exchange_declare, 0x0028000A, # 40, 10; 2621450
93
- :exchange_declare_ok, 0x0028000B, # 40, 11; 2621451
94
- :exchange_delete, 0x00280014, # 40, 20; 2621460
95
- :exchange_delete_ok, 0x00280015, # 40, 21; 2621461
96
- :exchange_bind, 0x0028001E, # 40, 30; 2621470
97
- :exchange_bind_ok, 0x0028001F, # 40, 31; 2621471
98
- :exchange_unbind, 0x00280028, # 40, 40; 2621480
99
- :exchange_unbind_ok, 0x00280033, # 40, 51; 2621491
100
- :queue_declare, 0x0032000A, # 50, 10; 3276810
101
- :queue_declare_ok, 0x0032000B, # 50, 11; 3276811
102
- :queue_bind, 0x00320014, # 50, 20; 3276820
103
- :queue_bind_ok, 0x00320015, # 50, 21; 3276821
104
- :queue_purge, 0x0032001E, # 50, 30; 3276830
105
- :queue_purge_ok, 0x0032001F, # 50, 31; 3276831
106
- :queue_delete, 0x00320028, # 50, 40; 3276840
107
- :queue_delete_ok, 0x00320029, # 50, 41; 3276841
108
- :queue_unbind, 0x00320032, # 50, 50; 3276850
109
- :queue_unbind_ok, 0x00320033, # 50, 51; 3276851
110
- :basic_qos, 0x003C000A, # 60, 10; 3932170
111
- :basic_qos_ok, 0x003C000B, # 60, 11; 3932171
112
- :basic_consume, 0x003C0014, # 60, 20; 3932180
113
- :basic_consume_ok, 0x003C0015, # 60, 21; 3932181
114
- :basic_cancel, 0x003C001E, # 60, 30; 3932190
115
- :basic_cancel_ok, 0x003C001F, # 60, 31; 3932191
116
- :basic_publish, 0x003C0028, # 60, 40; 3932200
117
- :basic_return, 0x003C0032, # 60, 50; 3932210
118
- :basic_deliver, 0x003C003C, # 60, 60; 3932220
119
- :basic_get, 0x003C0046, # 60, 70; 3932230
120
- :basic_get_ok, 0x003C0047, # 60, 71; 3932231
121
- :basic_get_empty, 0x003C0048, # 60, 72; 3932232
122
- :basic_ack, 0x003C0050, # 60, 80; 3932240
123
- :basic_reject, 0x003C005A, # 60, 90; 3932250
124
- :basic_recover_async, 0x003C0064, # 60, 100; 3932260
125
- :basic_recover, 0x003C006E, # 60, 110; 3932270
126
- :basic_recover_ok, 0x003C006F, # 60, 111; 3932271
127
- :basic_nack, 0x003C0078, # 60, 120; 3932280
128
- :tx_select, 0x005A000A, # 90, 10; 5898250
129
- :tx_select_ok, 0x005A000B, # 90, 11; 5898251
130
- :tx_commit, 0x005A0014, # 90, 20; 5898260
131
- :tx_commit_ok, 0x005A0015, # 90, 21; 5898261
132
- :tx_rollback, 0x005A001E, # 90, 30; 5898270
133
- :tx_rollback_ok, 0x005A001F, # 90, 31; 5898271
134
- :confirm_select, 0x0055000A, # 85, 10; 5570570
135
- :confirm_select_ok, 0x0055000B, # 85, 11; 5570571
136
- ]
137
-
138
- Flags = :uint32
139
-
140
- Channel = ::FFI::TypeDefs[:uint16]
141
- CHANNEL_MAX_ID = 2 ** (Channel.size * 8) - 1
142
-
143
- class Bytes < ::FFI::Struct
144
- layout :len, :size_t,
145
- :bytes, :pointer
146
- end
147
-
148
- class Decimal < ::FFI::Struct
149
- layout :decimals, :uint8,
150
- :value, :uint32
151
- end
152
-
153
- class Table < ::FFI::Struct
154
- layout :num_entries, :int,
155
- :entries, :pointer
156
- end
157
-
158
- class Array < ::FFI::Struct
159
- layout :num_entries, :int,
160
- :entries, :pointer
161
- end
162
-
163
- FieldValueKind = enum ::FFI::TypeDefs[:uint8], [
164
- :boolean, 't'.ord,
165
- :i8, 'b'.ord,
166
- :u8, 'B'.ord,
167
- :i16, 's'.ord,
168
- :u16, 'u'.ord,
169
- :i32, 'I'.ord,
170
- :u32, 'i'.ord,
171
- :i64, 'l'.ord,
172
- :u64, 'L'.ord,
173
- :f32, 'f'.ord,
174
- :f64, 'd'.ord,
175
- :decimal, 'D'.ord,
176
- :utf8, 'S'.ord,
177
- :array, 'A'.ord,
178
- :timestamp, 'T'.ord,
179
- :table, 'F'.ord,
180
- :void, 'V'.ord,
181
- :bytes, 'x'.ord,
182
- ]
183
-
184
- class FieldValueValue < ::FFI::Union
185
- layout :boolean, Boolean,
186
- :i8, :int8,
187
- :u8, :uint8,
188
- :i16, :int16,
189
- :u16, :uint16,
190
- :i32, :int32,
191
- :u32, :uint32,
192
- :i64, :int64,
193
- :u64, :uint64,
194
- :f32, :float,
195
- :f64, :double,
196
- :decimal, Decimal,
197
- :bytes, Bytes,
198
- :table, Table,
199
- :array, Array
200
- end
201
-
202
- class FieldValue < ::FFI::Struct
203
- layout :kind, FieldValueKind,
204
- :value, FieldValueValue
205
- end
206
-
207
- class TableEntry < ::FFI::Struct
208
- layout :key, Bytes,
209
- :value, FieldValue
210
- end
211
-
212
- class PoolBlocklist < ::FFI::Struct
213
- layout :num_blocks, :int,
214
- :blocklist, :pointer
215
- end
216
-
217
- class Pool < ::FFI::Struct
218
- layout :pagesize, :size_t,
219
- :pages, PoolBlocklist,
220
- :large_blocks, PoolBlocklist,
221
- :next_pages, :int,
222
- :alloc_block, :pointer,
223
- :alloc_used, :size_t
224
- end
225
-
226
- class Method < ::FFI::Struct
227
- layout :id, MethodNumber,
228
- :decoded, :pointer
229
- end
230
-
231
- FrameType = enum ::FFI::TypeDefs[:uint8], [
232
- :method, 1,
233
- :header, 2,
234
- :body, 3,
235
- :heartbeat, 8,
236
- ]
237
-
238
- class FramePayloadProperties < ::FFI::Struct
239
- layout :class_id, :uint16,
240
- :body_size, :uint64,
241
- :decoded, :pointer,
242
- :raw, Bytes
243
- end
244
-
245
- class FramePayloadProtocolHeader < ::FFI::Struct
246
- layout :transport_high, :uint8,
247
- :transport_low, :uint8,
248
- :protocol_version_major, :uint8,
249
- :protocol_version_minor, :uint8
250
- end
251
-
252
- class FramePayload < ::FFI::Union
253
- layout :method, Method,
254
- :properties, FramePayloadProperties,
255
- :body_fragment, Bytes,
256
- :protocol_header, FramePayloadProtocolHeader
257
- end
258
-
259
- class Frame < ::FFI::Struct
260
- layout :frame_type, FrameType,
261
- :channel, Channel,
262
- :payload, FramePayload
263
- end
264
-
265
- ResponseType = enum [
266
- :none, 0,
267
- :normal,
268
- :library_exception,
269
- :server_exception,
270
- ]
271
-
272
- class RpcReply < ::FFI::Struct
273
- layout :reply_type, ResponseType,
274
- :reply, Method,
275
- :library_error, Status
276
- end
277
-
278
- SaslMethod = enum [
279
- :plain, 0,
280
- ]
281
-
282
- ConnectionState = :pointer
283
-
284
- attach_function :amqp_constant_name, [:int], :string, **opts
285
- attach_function :amqp_constant_is_hard_error, [:int], Boolean, **opts
286
-
287
- attach_function :amqp_method_name, [MethodNumber], :string, **opts
288
- attach_function :amqp_method_has_content, [MethodNumber], Boolean, **opts
289
- attach_function :amqp_decode_method, [MethodNumber, Pool.ptr, Bytes.val, :pointer], Status, **opts
290
- attach_function :amqp_decode_properties, [:uint16, Pool.ptr, Bytes.val, :pointer], Status, **opts
291
- attach_function :amqp_encode_method, [MethodNumber, :pointer, Bytes.val], Status, **opts
292
- attach_function :amqp_encode_properties, [:uint16, :pointer, Bytes.val], Status, **opts
293
-
294
- require_relative 'ffi/gen'
295
-
296
- class ConnectionProperties < ::FFI::Struct
297
- layout :flags, Flags,
298
- :dummy, :char
299
- end
20
+ opts = {
21
+ blocking: true # only necessary on MRI to deal with the GIL.
22
+ }
23
+
24
+ attach_function :free, [:pointer], :void, **opts
25
+ attach_function :malloc, [:size_t], :pointer, **opts
26
+
27
+ attach_function :amqp_version_number, [], :uint32, **opts
28
+ attach_function :amqp_version, [], :string, **opts
29
+
30
+ Status = enum ::FFI::TypeDefs[:int], [
31
+ :ok, 0x0,
32
+ :no_memory, -0x0001,
33
+ :bad_amqp_data, -0x0002,
34
+ :unknown_class, -0x0003,
35
+ :unknown_method, -0x0004,
36
+ :hostname_resolution_failed, -0x0005,
37
+ :incompatible_amqp_version, -0x0006,
38
+ :connection_closed, -0x0007,
39
+ :bad_url, -0x0008,
40
+ :socket_error, -0x0009,
41
+ :invalid_parameter, -0x000A,
42
+ :table_too_big, -0x000B,
43
+ :wrong_method, -0x000C,
44
+ :timeout, -0x000D,
45
+ :timer_failure, -0x000E,
46
+ :heartbeat_timeout, -0x000F,
47
+ :unexpected_state, -0x0010,
48
+ :unexpected_socket_closed, -0x0011,
49
+ :unexpected_socket_inuse, -0x0012,
50
+ :tcp_error, -0x0100,
51
+ :tcp_socketlib_init_error, -0x0101,
52
+ :ssl_error, -0x0200,
53
+ :ssl_hostname_verify_failed, -0x0201,
54
+ :ssl_peer_verify_failed, -0x0202,
55
+ :ssl_connection_failed, -0x0203,
56
+ ]
57
+
58
+ DeliveryMode = enum ::FFI::TypeDefs[:uint8], [
59
+ :nonpersistent, 1,
60
+ :persistent, 2,
61
+ ]
62
+
63
+ class Timeval < ::FFI::Struct
64
+ layout :tv_sec, :time_t,
65
+ :tv_usec, :suseconds_t
66
+ end
67
+
68
+ class Boolean
69
+ extend ::FFI::DataConverter
70
+ native_type ::FFI::TypeDefs[:int]
71
+ def self.to_native val, ctx; val ? 1 : 0; end
72
+ def self.from_native val, ctx; val != 0; end
73
+ end
74
+
75
+ MethodNumber = enum ::FFI::TypeDefs[:uint32], [
76
+ :connection_start, 0x000A000A, # 10, 10; 655370
77
+ :connection_start_ok, 0x000A000B, # 10, 11; 655371
78
+ :connection_secure, 0x000A0014, # 10, 20; 655380
79
+ :connection_secure_ok, 0x000A0015, # 10, 21; 655381
80
+ :connection_tune, 0x000A001E, # 10, 30; 655390
81
+ :connection_tune_ok, 0x000A001F, # 10, 31; 655391
82
+ :connection_open, 0x000A0028, # 10, 40; 655400
83
+ :connection_open_ok, 0x000A0029, # 10, 41; 655401
84
+ :connection_close, 0x000A0032, # 10, 50; 655410
85
+ :connection_close_ok, 0x000A0033, # 10, 51; 655411
86
+ :connection_blocked, 0x000A003C, # 10, 60; 655420
87
+ :connection_unblocked, 0x000A003D, # 10, 61; 655421
88
+ :channel_open, 0x0014000A, # 20, 10; 1310730
89
+ :channel_open_ok, 0x0014000B, # 20, 11; 1310731
90
+ :channel_flow, 0x00140014, # 20, 20; 1310740
91
+ :channel_flow_ok, 0x00140015, # 20, 21; 1310741
92
+ :channel_close, 0x00140028, # 20, 40; 1310760
93
+ :channel_close_ok, 0x00140029, # 20, 41; 1310761
94
+ :access_request, 0x001E000A, # 30, 10; 1966090
95
+ :access_request_ok, 0x001E000B, # 30, 11; 1966091
96
+ :exchange_declare, 0x0028000A, # 40, 10; 2621450
97
+ :exchange_declare_ok, 0x0028000B, # 40, 11; 2621451
98
+ :exchange_delete, 0x00280014, # 40, 20; 2621460
99
+ :exchange_delete_ok, 0x00280015, # 40, 21; 2621461
100
+ :exchange_bind, 0x0028001E, # 40, 30; 2621470
101
+ :exchange_bind_ok, 0x0028001F, # 40, 31; 2621471
102
+ :exchange_unbind, 0x00280028, # 40, 40; 2621480
103
+ :exchange_unbind_ok, 0x00280033, # 40, 51; 2621491
104
+ :queue_declare, 0x0032000A, # 50, 10; 3276810
105
+ :queue_declare_ok, 0x0032000B, # 50, 11; 3276811
106
+ :queue_bind, 0x00320014, # 50, 20; 3276820
107
+ :queue_bind_ok, 0x00320015, # 50, 21; 3276821
108
+ :queue_purge, 0x0032001E, # 50, 30; 3276830
109
+ :queue_purge_ok, 0x0032001F, # 50, 31; 3276831
110
+ :queue_delete, 0x00320028, # 50, 40; 3276840
111
+ :queue_delete_ok, 0x00320029, # 50, 41; 3276841
112
+ :queue_unbind, 0x00320032, # 50, 50; 3276850
113
+ :queue_unbind_ok, 0x00320033, # 50, 51; 3276851
114
+ :basic_qos, 0x003C000A, # 60, 10; 3932170
115
+ :basic_qos_ok, 0x003C000B, # 60, 11; 3932171
116
+ :basic_consume, 0x003C0014, # 60, 20; 3932180
117
+ :basic_consume_ok, 0x003C0015, # 60, 21; 3932181
118
+ :basic_cancel, 0x003C001E, # 60, 30; 3932190
119
+ :basic_cancel_ok, 0x003C001F, # 60, 31; 3932191
120
+ :basic_publish, 0x003C0028, # 60, 40; 3932200
121
+ :basic_return, 0x003C0032, # 60, 50; 3932210
122
+ :basic_deliver, 0x003C003C, # 60, 60; 3932220
123
+ :basic_get, 0x003C0046, # 60, 70; 3932230
124
+ :basic_get_ok, 0x003C0047, # 60, 71; 3932231
125
+ :basic_get_empty, 0x003C0048, # 60, 72; 3932232
126
+ :basic_ack, 0x003C0050, # 60, 80; 3932240
127
+ :basic_reject, 0x003C005A, # 60, 90; 3932250
128
+ :basic_recover_async, 0x003C0064, # 60, 100; 3932260
129
+ :basic_recover, 0x003C006E, # 60, 110; 3932270
130
+ :basic_recover_ok, 0x003C006F, # 60, 111; 3932271
131
+ :basic_nack, 0x003C0078, # 60, 120; 3932280
132
+ :tx_select, 0x005A000A, # 90, 10; 5898250
133
+ :tx_select_ok, 0x005A000B, # 90, 11; 5898251
134
+ :tx_commit, 0x005A0014, # 90, 20; 5898260
135
+ :tx_commit_ok, 0x005A0015, # 90, 21; 5898261
136
+ :tx_rollback, 0x005A001E, # 90, 30; 5898270
137
+ :tx_rollback_ok, 0x005A001F, # 90, 31; 5898271
138
+ :confirm_select, 0x0055000A, # 85, 10; 5570570
139
+ :confirm_select_ok, 0x0055000B, # 85, 11; 5570571
140
+ ]
141
+
142
+ Flags = :uint32
143
+
144
+ Channel = ::FFI::TypeDefs[:uint16]
145
+ CHANNEL_MAX_ID = 2 ** (Channel.size * 8) - 1
146
+
147
+ class Bytes < ::FFI::Struct
148
+ layout :len, :size_t,
149
+ :bytes, :pointer
150
+ end
151
+
152
+ class Decimal < ::FFI::Struct
153
+ layout :decimals, :uint8,
154
+ :value, :uint32
155
+ end
156
+
157
+ class Table < ::FFI::Struct
158
+ layout :num_entries, :int,
159
+ :entries, :pointer
160
+ end
161
+
162
+ class Array < ::FFI::Struct
163
+ layout :num_entries, :int,
164
+ :entries, :pointer
165
+ end
166
+
167
+ FieldValueKind = enum ::FFI::TypeDefs[:uint8], [
168
+ :boolean, 't'.ord,
169
+ :i8, 'b'.ord,
170
+ :u8, 'B'.ord,
171
+ :i16, 's'.ord,
172
+ :u16, 'u'.ord,
173
+ :i32, 'I'.ord,
174
+ :u32, 'i'.ord,
175
+ :i64, 'l'.ord,
176
+ :u64, 'L'.ord,
177
+ :f32, 'f'.ord,
178
+ :f64, 'd'.ord,
179
+ :decimal, 'D'.ord,
180
+ :utf8, 'S'.ord,
181
+ :array, 'A'.ord,
182
+ :timestamp, 'T'.ord,
183
+ :table, 'F'.ord,
184
+ :void, 'V'.ord,
185
+ :bytes, 'x'.ord,
186
+ ]
187
+
188
+ class FieldValueValue < ::FFI::Union
189
+ layout :boolean, Boolean,
190
+ :i8, :int8,
191
+ :u8, :uint8,
192
+ :i16, :int16,
193
+ :u16, :uint16,
194
+ :i32, :int32,
195
+ :u32, :uint32,
196
+ :i64, :int64,
197
+ :u64, :uint64,
198
+ :f32, :float,
199
+ :f64, :double,
200
+ :decimal, Decimal,
201
+ :bytes, Bytes,
202
+ :table, Table,
203
+ :array, Array
204
+ end
205
+
206
+ class FieldValue < ::FFI::Struct
207
+ layout :kind, FieldValueKind,
208
+ :value, FieldValueValue
209
+ end
210
+
211
+ class TableEntry < ::FFI::Struct
212
+ layout :key, Bytes,
213
+ :value, FieldValue
214
+ end
215
+
216
+ class PoolBlocklist < ::FFI::Struct
217
+ layout :num_blocks, :int,
218
+ :blocklist, :pointer
219
+ end
220
+
221
+ class Pool < ::FFI::Struct
222
+ layout :pagesize, :size_t,
223
+ :pages, PoolBlocklist,
224
+ :large_blocks, PoolBlocklist,
225
+ :next_pages, :int,
226
+ :alloc_block, :pointer,
227
+ :alloc_used, :size_t
228
+ end
229
+
230
+ class Method < ::FFI::Struct
231
+ layout :id, MethodNumber,
232
+ :decoded, :pointer
233
+ end
234
+
235
+ FrameType = enum ::FFI::TypeDefs[:uint8], [
236
+ :method, 1,
237
+ :header, 2,
238
+ :body, 3,
239
+ :heartbeat, 8,
240
+ ]
241
+
242
+ class FramePayloadProperties < ::FFI::Struct
243
+ layout :class_id, :uint16,
244
+ :body_size, :uint64,
245
+ :decoded, :pointer,
246
+ :raw, Bytes
247
+ end
248
+
249
+ class FramePayloadProtocolHeader < ::FFI::Struct
250
+ layout :transport_high, :uint8,
251
+ :transport_low, :uint8,
252
+ :protocol_version_major, :uint8,
253
+ :protocol_version_minor, :uint8
254
+ end
255
+
256
+ class FramePayload < ::FFI::Union
257
+ layout :method, Method,
258
+ :properties, FramePayloadProperties,
259
+ :body_fragment, Bytes,
260
+ :protocol_header, FramePayloadProtocolHeader
261
+ end
262
+
263
+ class Frame < ::FFI::Struct
264
+ layout :frame_type, FrameType,
265
+ :channel, Channel,
266
+ :payload, FramePayload
267
+ end
268
+
269
+ ResponseType = enum [
270
+ :none, 0,
271
+ :normal,
272
+ :library_exception,
273
+ :server_exception,
274
+ ]
275
+
276
+ class RpcReply < ::FFI::Struct
277
+ layout :reply_type, ResponseType,
278
+ :reply, Method,
279
+ :library_error, Status
280
+ end
281
+
282
+ SaslMethod = enum [
283
+ :plain, 0,
284
+ ]
285
+
286
+ ConnectionState = :pointer
287
+
288
+ attach_function :amqp_constant_name, [:int], :string, **opts
289
+ attach_function :amqp_constant_is_hard_error, [:int], Boolean, **opts
290
+
291
+ attach_function :amqp_method_name, [MethodNumber], :string, **opts
292
+ attach_function :amqp_method_has_content, [MethodNumber], Boolean, **opts
293
+ attach_function :amqp_decode_method, [MethodNumber, Pool.ptr, Bytes.val, :pointer], Status, **opts
294
+ attach_function :amqp_decode_properties, [:uint16, Pool.ptr, Bytes.val, :pointer], Status, **opts
295
+ attach_function :amqp_encode_method, [MethodNumber, :pointer, Bytes.val], Status, **opts
296
+ attach_function :amqp_encode_properties, [:uint16, :pointer, Bytes.val], Status, **opts
297
+
298
+ require_relative 'ffi/gen'
299
+
300
+ class ConnectionProperties < ::FFI::Struct
301
+ layout :flags, Flags,
302
+ :dummy, :char
303
+ end
300
304
 
301
- class ChannelProperties < ::FFI::Struct
302
- layout :flags, Flags,
303
- :dummy, :char
304
- end
305
+ class ChannelProperties < ::FFI::Struct
306
+ layout :flags, Flags,
307
+ :dummy, :char
308
+ end
305
309
 
306
- class AccessProperties < ::FFI::Struct
307
- layout :flags, Flags,
308
- :dummy, :char
309
- end
310
+ class AccessProperties < ::FFI::Struct
311
+ layout :flags, Flags,
312
+ :dummy, :char
313
+ end
310
314
 
311
- class ExchangeProperties < ::FFI::Struct
312
- layout :flags, Flags,
313
- :dummy, :char
314
- end
315
+ class ExchangeProperties < ::FFI::Struct
316
+ layout :flags, Flags,
317
+ :dummy, :char
318
+ end
315
319
 
316
- class QueueProperties < ::FFI::Struct
317
- layout :flags, Flags,
318
- :dummy, :char
319
- end
320
-
321
- class TxProperties < ::FFI::Struct
322
- layout :flags, Flags,
323
- :dummy, :char
324
- end
325
-
326
- class ExchangeProperties < ::FFI::Struct
327
- layout :flags, Flags,
328
- :dummy, :char
329
- end
330
-
331
- class BasicProperties < ::FFI::Struct
332
- layout :_flags, Flags,
333
- :content_type, Bytes,
334
- :content_encoding, Bytes,
335
- :headers, Table,
336
- :delivery_mode, DeliveryMode,
337
- :priority, :uint8,
338
- :correlation_id, Bytes,
339
- :reply_to, Bytes,
340
- :expiration, Bytes,
341
- :message_id, Bytes,
342
- :timestamp, :uint64,
343
- :type, Bytes,
344
- :user_id, Bytes,
345
- :app_id, Bytes,
346
- :cluster_id, Bytes
347
-
348
- FLAGS = {
349
- content_type: (1 << 15),
350
- content_encoding: (1 << 14),
351
- headers: (1 << 13),
352
- delivery_mode: (1 << 12),
353
- priority: (1 << 11),
354
- correlation_id: (1 << 10),
355
- reply_to: (1 << 9),
356
- expiration: (1 << 8),
357
- message_id: (1 << 7),
358
- timestamp: (1 << 6),
359
- type: (1 << 5),
360
- user_id: (1 << 4),
361
- app_id: (1 << 3),
362
- cluster_id: (1 << 2),
363
- }
364
- end
365
-
366
- attach_function :amqp_channel_open, [ConnectionState, Channel], ChannelOpenOk.ptr, **opts
367
- attach_function :amqp_channel_flow, [ConnectionState, Channel, Boolean], ChannelFlowOk.ptr, **opts
368
- attach_function :amqp_exchange_declare, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Table.val], ExchangeDeclareOk.ptr, **opts
369
- attach_function :amqp_exchange_delete, [ConnectionState, Channel, Bytes.val, Boolean], ExchangeDeleteOk.ptr, **opts
370
- attach_function :amqp_exchange_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeBindOk.ptr, **opts
371
- attach_function :amqp_exchange_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeUnbindOk.ptr, **opts
372
- attach_function :amqp_queue_declare, [ConnectionState, Channel, Bytes.val, Boolean, Boolean, Boolean, Boolean, Table.val], QueueDeclareOk.ptr, **opts
373
- attach_function :amqp_queue_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueBindOk.ptr, **opts
374
- attach_function :amqp_queue_purge, [ConnectionState, Channel, Bytes.val], QueuePurgeOk.ptr, **opts
375
- attach_function :amqp_queue_delete, [ConnectionState, Channel, Bytes.val, Boolean, Boolean], QueueDeleteOk.ptr, **opts
376
- attach_function :amqp_queue_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueUnbindOk.ptr, **opts
377
- attach_function :amqp_basic_qos, [ConnectionState, Channel, :uint32, :uint16, Boolean], BasicQosOk.ptr, **opts
378
- attach_function :amqp_basic_consume, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Boolean, Table.val], BasicConsumeOk.ptr, **opts
379
- attach_function :amqp_basic_cancel, [ConnectionState, Channel, Bytes.val], BasicCancelOk.ptr, **opts
380
- attach_function :amqp_basic_recover, [ConnectionState, Channel, Boolean], BasicRecoverOk.ptr, **opts
381
- attach_function :amqp_tx_select, [ConnectionState, Channel], TxSelect.ptr, **opts
382
- attach_function :amqp_tx_commit, [ConnectionState, Channel], TxCommit.ptr, **opts
383
- attach_function :amqp_tx_rollback, [ConnectionState, Channel], TxRollback.ptr, **opts
384
- attach_function :amqp_confirm_select, [ConnectionState, Channel], ConfirmSelect.ptr, **opts
385
-
386
- attach_function :init_amqp_pool, [Pool.ptr, :size_t], :void, **opts
387
- attach_function :recycle_amqp_pool, [Pool.ptr], :void, **opts
388
- attach_function :empty_amqp_pool, [Pool.ptr], :void, **opts
389
- attach_function :amqp_pool_alloc, [Pool.ptr, :size_t], :pointer, **opts
390
- attach_function :amqp_pool_alloc_bytes, [Pool.ptr, :size_t, Bytes.ptr], :void, **opts
391
-
392
- attach_function :amqp_cstring_bytes, [:string], Bytes.val, **opts
393
- attach_function :amqp_bytes_malloc_dup, [Bytes.val], Bytes.val, **opts
394
- attach_function :amqp_bytes_malloc, [:size_t], Bytes.val, **opts
395
- attach_function :amqp_bytes_free, [Bytes.val], :void, **opts
396
-
397
- attach_function :amqp_new_connection, [], ConnectionState, **opts
398
- attach_function :amqp_get_sockfd, [ConnectionState], :int, **opts
399
- attach_function :amqp_set_sockfd, [ConnectionState, :int], :void, **opts
400
- attach_function :amqp_tune_connection, [ConnectionState, :int, :int, :int], Status, **opts
401
- attach_function :amqp_get_channel_max, [ConnectionState], :int, **opts
402
- attach_function :amqp_get_frame_max, [ConnectionState], :int, **opts
403
- attach_function :amqp_get_heartbeat, [ConnectionState], :int, **opts
404
- attach_function :amqp_destroy_connection, [ConnectionState], Status, **opts
405
-
406
- attach_function :amqp_handle_input, [ConnectionState, Bytes.val, Frame.ptr], Status, **opts
407
- attach_function :amqp_release_buffers_ok, [ConnectionState], Boolean, **opts
408
- attach_function :amqp_release_buffers, [ConnectionState], :void, **opts
409
- attach_function :amqp_maybe_release_buffers, [ConnectionState], :void, **opts
410
- attach_function :amqp_maybe_release_buffers_on_channel, [ConnectionState, Channel], :void, **opts
411
- attach_function :amqp_send_frame, [ConnectionState, Frame.ptr], Status, **opts
412
-
413
- attach_function :amqp_table_entry_cmp, [:pointer, :pointer], :int, **opts
414
-
415
- attach_function :amqp_open_socket, [:string, :int], Status, **opts
416
-
417
- attach_function :amqp_send_header, [ConnectionState], Status, **opts
418
- attach_function :amqp_frames_enqueued, [ConnectionState], Boolean, **opts
419
- attach_function :amqp_simple_wait_frame, [ConnectionState, Frame.ptr], Status, **opts
420
- attach_function :amqp_simple_wait_frame_noblock, [ConnectionState, Frame.ptr, Timeval.ptr], Status, **opts
421
- attach_function :amqp_simple_wait_method, [ConnectionState, Channel, MethodNumber, Method.ptr], Status, **opts
422
- attach_function :amqp_send_method, [ConnectionState, Channel, MethodNumber, :pointer], Status, **opts
423
-
424
- attach_function :amqp_simple_rpc, [ConnectionState, Channel, MethodNumber, :pointer, :pointer], RpcReply.val, **opts
425
- attach_function :amqp_simple_rpc_decoded, [ConnectionState, Channel, MethodNumber, MethodNumber, :pointer], :pointer, **opts
426
- attach_function :amqp_get_rpc_reply, [ConnectionState], RpcReply.val, **opts
427
- attach_function :amqp_login, [ConnectionState, :string, :int, :int, :int, SaslMethod, :varargs], RpcReply.val, **opts
428
- attach_function :amqp_login_with_properties, [ConnectionState, :string, :int, :int, :int, Table.ptr, SaslMethod, :varargs], RpcReply.val, **opts
429
- attach_function :amqp_channel_close, [ConnectionState, Channel, :int], RpcReply.val, **opts
430
- attach_function :amqp_connection_close, [ConnectionState, :int], RpcReply.val, **opts
431
-
432
- attach_function :amqp_basic_publish, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, BasicProperties.ptr, Bytes.val], Status, **opts
433
-
434
- attach_function :amqp_basic_get, [ConnectionState, Channel, Bytes.val, Boolean], Status, **opts
435
- attach_function :amqp_basic_ack, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
436
- attach_function :amqp_basic_reject, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
437
- attach_function :amqp_basic_nack, [ConnectionState, Channel, :uint64, Boolean, Boolean], Status, **opts
438
-
439
- attach_function :amqp_data_in_buffer, [ConnectionState], Boolean, **opts
440
-
441
- attach_function :amqp_error_string, [:int], :string, **opts
442
- attach_function :amqp_error_string2, [:int], :string, **opts
443
-
444
- attach_function :amqp_decode_table, [Bytes.val, Pool.ptr, Table.ptr, :pointer], Status, **opts
445
- attach_function :amqp_encode_table, [Bytes.val, Table.ptr, :pointer], Status, **opts
446
- attach_function :amqp_table_clone, [Table.ptr, Table.ptr, Pool.ptr], Status, **opts
447
-
448
- class Message < ::FFI::Struct
449
- layout :properties, BasicProperties,
450
- :body, Bytes,
451
- :pool, Pool
452
- end
453
-
454
- attach_function :amqp_read_message, [ConnectionState, Channel, Message.ptr, :int], RpcReply.val, **opts
455
- attach_function :amqp_destroy_message, [Message.ptr], :void, **opts
456
-
457
- class Envelope < ::FFI::Struct
458
- layout :channel, Channel,
459
- :consumer_tag, Bytes,
460
- :delivery_tag, :uint64,
461
- :redelivered, Boolean,
462
- :exchange, Bytes,
463
- :routing_key, Bytes,
464
- :message, Message
465
- end
466
-
467
- attach_function :amqp_consume_message, [ConnectionState, Envelope.ptr, Timeval.ptr, :int], RpcReply.val, **opts
468
- attach_function :amqp_destroy_envelope, [Envelope.ptr], :void, **opts
469
-
470
- class ConnectionInfo < ::FFI::Struct
471
- layout :user, :string,
472
- :password, :string,
473
- :host, :string,
474
- :vhost, :string,
475
- :port, :int,
476
- :ssl, Boolean
477
- end
478
-
479
- attach_function :amqp_default_connection_info, [ConnectionInfo.ptr], :void, **opts
480
- attach_function :amqp_parse_url, [:pointer, ConnectionInfo.ptr], Status, **opts
481
- attach_function :amqp_socket_open, [:pointer, :string, :int], Status, **opts
482
- attach_function :amqp_socket_open_noblock, [:pointer, :string, :int, Timeval.ptr], Status, **opts
483
- attach_function :amqp_socket_get_sockfd, [:pointer], :int, **opts
484
- attach_function :amqp_get_socket, [ConnectionState], :pointer, **opts
485
- attach_function :amqp_get_server_properties, [ConnectionState], Table, **opts
486
-
487
- attach_function :amqp_tcp_socket_new, [ConnectionState], :pointer, **opts
488
- attach_function :amqp_tcp_socket_set_sockfd, [:pointer, :int], :void, **opts
489
-
490
- begin # SSL support is optional
491
- attach_function :amqp_ssl_socket_new, [ConnectionState], :pointer, **opts
492
- attach_function :amqp_ssl_socket_set_cacert, [:pointer, :string], Status, **opts
493
- attach_function :amqp_ssl_socket_set_key, [:pointer, :string, :string], Status, **opts
494
- attach_function :amqp_ssl_socket_set_key_buffer, [:pointer, :string, :pointer, :size_t], Status, **opts
495
- attach_function :amqp_ssl_socket_set_verify, [:pointer, Boolean], :void, **opts
496
- attach_function :amqp_set_initialize_ssl_library, [Boolean], :void, **opts
497
- @has_ssl = true
498
- rescue LoadError
499
- @has_ssl = false
500
- end
501
- def self.has_ssl?; @has_ssl; end
320
+ class QueueProperties < ::FFI::Struct
321
+ layout :flags, Flags,
322
+ :dummy, :char
323
+ end
324
+
325
+ class TxProperties < ::FFI::Struct
326
+ layout :flags, Flags,
327
+ :dummy, :char
328
+ end
329
+
330
+ class ExchangeProperties < ::FFI::Struct
331
+ layout :flags, Flags,
332
+ :dummy, :char
333
+ end
334
+
335
+ class BasicProperties < ::FFI::Struct
336
+ layout :_flags, Flags,
337
+ :content_type, Bytes,
338
+ :content_encoding, Bytes,
339
+ :headers, Table,
340
+ :delivery_mode, DeliveryMode,
341
+ :priority, :uint8,
342
+ :correlation_id, Bytes,
343
+ :reply_to, Bytes,
344
+ :expiration, Bytes,
345
+ :message_id, Bytes,
346
+ :timestamp, :uint64,
347
+ :type, Bytes,
348
+ :user_id, Bytes,
349
+ :app_id, Bytes,
350
+ :cluster_id, Bytes
351
+
352
+ FLAGS = {
353
+ content_type: (1 << 15),
354
+ content_encoding: (1 << 14),
355
+ headers: (1 << 13),
356
+ delivery_mode: (1 << 12),
357
+ priority: (1 << 11),
358
+ correlation_id: (1 << 10),
359
+ reply_to: (1 << 9),
360
+ expiration: (1 << 8),
361
+ message_id: (1 << 7),
362
+ timestamp: (1 << 6),
363
+ type: (1 << 5),
364
+ user_id: (1 << 4),
365
+ app_id: (1 << 3),
366
+ cluster_id: (1 << 2),
367
+ }
368
+ end
369
+
370
+ attach_function :amqp_channel_open, [ConnectionState, Channel], ChannelOpenOk.ptr, **opts
371
+ attach_function :amqp_channel_flow, [ConnectionState, Channel, Boolean], ChannelFlowOk.ptr, **opts
372
+ attach_function :amqp_exchange_declare, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Table.val], ExchangeDeclareOk.ptr, **opts
373
+ attach_function :amqp_exchange_delete, [ConnectionState, Channel, Bytes.val, Boolean], ExchangeDeleteOk.ptr, **opts
374
+ attach_function :amqp_exchange_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeBindOk.ptr, **opts
375
+ attach_function :amqp_exchange_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], ExchangeUnbindOk.ptr, **opts
376
+ attach_function :amqp_queue_declare, [ConnectionState, Channel, Bytes.val, Boolean, Boolean, Boolean, Boolean, Table.val], QueueDeclareOk.ptr, **opts
377
+ attach_function :amqp_queue_bind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueBindOk.ptr, **opts
378
+ attach_function :amqp_queue_purge, [ConnectionState, Channel, Bytes.val], QueuePurgeOk.ptr, **opts
379
+ attach_function :amqp_queue_delete, [ConnectionState, Channel, Bytes.val, Boolean, Boolean], QueueDeleteOk.ptr, **opts
380
+ attach_function :amqp_queue_unbind, [ConnectionState, Channel, Bytes.val, Bytes.val, Bytes.val, Table.val], QueueUnbindOk.ptr, **opts
381
+ attach_function :amqp_basic_qos, [ConnectionState, Channel, :uint32, :uint16, Boolean], BasicQosOk.ptr, **opts
382
+ attach_function :amqp_basic_consume, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, Boolean, Table.val], BasicConsumeOk.ptr, **opts
383
+ attach_function :amqp_basic_cancel, [ConnectionState, Channel, Bytes.val], BasicCancelOk.ptr, **opts
384
+ attach_function :amqp_basic_recover, [ConnectionState, Channel, Boolean], BasicRecoverOk.ptr, **opts
385
+ attach_function :amqp_tx_select, [ConnectionState, Channel], TxSelect.ptr, **opts
386
+ attach_function :amqp_tx_commit, [ConnectionState, Channel], TxCommit.ptr, **opts
387
+ attach_function :amqp_tx_rollback, [ConnectionState, Channel], TxRollback.ptr, **opts
388
+ attach_function :amqp_confirm_select, [ConnectionState, Channel], ConfirmSelect.ptr, **opts
389
+
390
+ attach_function :init_amqp_pool, [Pool.ptr, :size_t], :void, **opts
391
+ attach_function :recycle_amqp_pool, [Pool.ptr], :void, **opts
392
+ attach_function :empty_amqp_pool, [Pool.ptr], :void, **opts
393
+ attach_function :amqp_pool_alloc, [Pool.ptr, :size_t], :pointer, **opts
394
+ attach_function :amqp_pool_alloc_bytes, [Pool.ptr, :size_t, Bytes.ptr], :void, **opts
395
+
396
+ attach_function :amqp_cstring_bytes, [:string], Bytes.val, **opts
397
+ attach_function :amqp_bytes_malloc_dup, [Bytes.val], Bytes.val, **opts
398
+ attach_function :amqp_bytes_malloc, [:size_t], Bytes.val, **opts
399
+ attach_function :amqp_bytes_free, [Bytes.val], :void, **opts
400
+
401
+ attach_function :amqp_new_connection, [], ConnectionState, **opts
402
+ attach_function :amqp_get_sockfd, [ConnectionState], :int, **opts
403
+ attach_function :amqp_set_sockfd, [ConnectionState, :int], :void, **opts
404
+ attach_function :amqp_tune_connection, [ConnectionState, :int, :int, :int], Status, **opts
405
+ attach_function :amqp_get_channel_max, [ConnectionState], :int, **opts
406
+ attach_function :amqp_get_frame_max, [ConnectionState], :int, **opts
407
+ attach_function :amqp_get_heartbeat, [ConnectionState], :int, **opts
408
+ attach_function :amqp_destroy_connection, [ConnectionState], Status, **opts
409
+
410
+ attach_function :amqp_handle_input, [ConnectionState, Bytes.val, Frame.ptr], Status, **opts
411
+ attach_function :amqp_release_buffers_ok, [ConnectionState], Boolean, **opts
412
+ attach_function :amqp_release_buffers, [ConnectionState], :void, **opts
413
+ attach_function :amqp_maybe_release_buffers, [ConnectionState], :void, **opts
414
+ attach_function :amqp_maybe_release_buffers_on_channel, [ConnectionState, Channel], :void, **opts
415
+ attach_function :amqp_send_frame, [ConnectionState, Frame.ptr], Status, **opts
416
+
417
+ attach_function :amqp_table_entry_cmp, [:pointer, :pointer], :int, **opts
418
+
419
+ attach_function :amqp_open_socket, [:string, :int], Status, **opts
420
+
421
+ attach_function :amqp_send_header, [ConnectionState], Status, **opts
422
+ attach_function :amqp_frames_enqueued, [ConnectionState], Boolean, **opts
423
+ attach_function :amqp_simple_wait_frame, [ConnectionState, Frame.ptr], Status, **opts
424
+ attach_function :amqp_simple_wait_frame_noblock, [ConnectionState, Frame.ptr, Timeval.ptr], Status, **opts
425
+ attach_function :amqp_simple_wait_method, [ConnectionState, Channel, MethodNumber, Method.ptr], Status, **opts
426
+ attach_function :amqp_send_method, [ConnectionState, Channel, MethodNumber, :pointer], Status, **opts
427
+
428
+ attach_function :amqp_simple_rpc, [ConnectionState, Channel, MethodNumber, :pointer, :pointer], RpcReply.val, **opts
429
+ attach_function :amqp_simple_rpc_decoded, [ConnectionState, Channel, MethodNumber, MethodNumber, :pointer], :pointer, **opts
430
+ attach_function :amqp_get_rpc_reply, [ConnectionState], RpcReply.val, **opts
431
+ attach_function :amqp_login, [ConnectionState, :string, :int, :int, :int, SaslMethod, :varargs], RpcReply.val, **opts
432
+ attach_function :amqp_login_with_properties, [ConnectionState, :string, :int, :int, :int, Table.ptr, SaslMethod, :varargs], RpcReply.val, **opts
433
+ attach_function :amqp_channel_close, [ConnectionState, Channel, :int], RpcReply.val, **opts
434
+ attach_function :amqp_connection_close, [ConnectionState, :int], RpcReply.val, **opts
435
+
436
+ attach_function :amqp_basic_publish, [ConnectionState, Channel, Bytes.val, Bytes.val, Boolean, Boolean, BasicProperties.ptr, Bytes.val], Status, **opts
437
+
438
+ attach_function :amqp_basic_get, [ConnectionState, Channel, Bytes.val, Boolean], Status, **opts
439
+ attach_function :amqp_basic_ack, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
440
+ attach_function :amqp_basic_reject, [ConnectionState, Channel, :uint64, Boolean], Status, **opts
441
+ attach_function :amqp_basic_nack, [ConnectionState, Channel, :uint64, Boolean, Boolean], Status, **opts
442
+
443
+ attach_function :amqp_data_in_buffer, [ConnectionState], Boolean, **opts
444
+
445
+ attach_function :amqp_error_string, [:int], :string, **opts
446
+ attach_function :amqp_error_string2, [:int], :string, **opts
447
+
448
+ attach_function :amqp_decode_table, [Bytes.val, Pool.ptr, Table.ptr, :pointer], Status, **opts
449
+ attach_function :amqp_encode_table, [Bytes.val, Table.ptr, :pointer], Status, **opts
450
+ attach_function :amqp_table_clone, [Table.ptr, Table.ptr, Pool.ptr], Status, **opts
451
+
452
+ class Message < ::FFI::Struct
453
+ layout :properties, BasicProperties,
454
+ :body, Bytes,
455
+ :pool, Pool
456
+ end
457
+
458
+ attach_function :amqp_read_message, [ConnectionState, Channel, Message.ptr, :int], RpcReply.val, **opts
459
+ attach_function :amqp_destroy_message, [Message.ptr], :void, **opts
460
+
461
+ class Envelope < ::FFI::Struct
462
+ layout :channel, Channel,
463
+ :consumer_tag, Bytes,
464
+ :delivery_tag, :uint64,
465
+ :redelivered, Boolean,
466
+ :exchange, Bytes,
467
+ :routing_key, Bytes,
468
+ :message, Message
469
+ end
470
+
471
+ attach_function :amqp_consume_message, [ConnectionState, Envelope.ptr, Timeval.ptr, :int], RpcReply.val, **opts
472
+ attach_function :amqp_destroy_envelope, [Envelope.ptr], :void, **opts
473
+
474
+ class ConnectionInfo < ::FFI::Struct
475
+ layout :user, :string,
476
+ :password, :string,
477
+ :host, :string,
478
+ :vhost, :string,
479
+ :port, :int,
480
+ :ssl, Boolean
481
+ end
482
+
483
+ attach_function :amqp_default_connection_info, [ConnectionInfo.ptr], :void, **opts
484
+ attach_function :amqp_parse_url, [:pointer, ConnectionInfo.ptr], Status, **opts
485
+ attach_function :amqp_socket_open, [:pointer, :string, :int], Status, **opts
486
+ attach_function :amqp_socket_open_noblock, [:pointer, :string, :int, Timeval.ptr], Status, **opts
487
+ attach_function :amqp_socket_get_sockfd, [:pointer], :int, **opts
488
+ attach_function :amqp_get_socket, [ConnectionState], :pointer, **opts
489
+ attach_function :amqp_get_server_properties, [ConnectionState], Table, **opts
490
+
491
+ attach_function :amqp_tcp_socket_new, [ConnectionState], :pointer, **opts
492
+ attach_function :amqp_tcp_socket_set_sockfd, [:pointer, :int], :void, **opts
493
+
494
+ begin # SSL support is optional
495
+ attach_function :amqp_ssl_socket_new, [ConnectionState], :pointer, **opts
496
+ attach_function :amqp_ssl_socket_set_cacert, [:pointer, :string], Status, **opts
497
+ attach_function :amqp_ssl_socket_set_key, [:pointer, :string, :string], Status, **opts
498
+ attach_function :amqp_ssl_socket_set_key_buffer, [:pointer, :string, :pointer, :size_t], Status, **opts
499
+ attach_function :amqp_ssl_socket_set_verify, [:pointer, Boolean], :void, **opts
500
+ attach_function :amqp_set_initialize_ssl_library, [Boolean], :void, **opts
501
+ @has_ssl = true
502
+ rescue LoadError
503
+ @has_ssl = false
502
504
  end
505
+ def self.has_ssl?; @has_ssl; end
503
506
  end
504
507
  end