PageRenderTime 13ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/zmq/library/zmq_socket.e

http://github.com/tybor/Liberty
Specman e | 506 lines | 78 code | 24 blank | 404 comment | 3 complexity | 37aa4d07fdbf44c684285bd8f0d5ccfb MD5 | raw file
  1deferred class ZMQ_SOCKET
  2   -- A ØMQ socket
  3
  4inherit
  5   WRAPPER
  6      redefine
  7         from_external_pointer
  8      end
  9   EIFFEL_OWNED
 10      redefine
 11         dispose
 12      end
 13
 14insert
 15   ZMQ_EXTERNALS
 16   ZMQ_STATUS
 17
 18feature {ANY}
 19   from_external_pointer (a_pointer: POINTER)
 20      do
 21         handle:=a_pointer
 22      end
 23
 24   is_equal (another: like Current): BOOLEAN
 25      do
 26         Result:=handle=another.handle
 27      end
 28
 29   copy (another: like Current)
 30      do
 31         not_yet_implemented
 32      end
 33
 34feature {} -- Disposing
 35   dispose
 36      do
 37         handle_return_value (zmq_close (handle))
 38      end
 39
 40feature {ANY} -- Binding
 41   bind (an_address: ABSTRACT_STRING)
 42      -- Bind Current socket to a particular transport.
 43
 44--            The zmq_bind() function shall create an endpoint for accepting connections and bind it to the socket referenced by the socket
 45--       argument.
 46--
 47--       The endpoint argument is a string consisting of two parts as follows: transport://address. The transport part specifies the
 48--       underlying transport protocol to use. The meaning of the address part is specific to the underlying transport protocol
 49--       selected.
 50--
 51--       The following transports are defined:
 52--
 53--       inproc
 54--           local in-process (inter-thread) communication transport, see zmq_inproc(7)
 55--
 56--       ipc
 57--           local inter-process communication transport, see zmq_ipc(7)
 58--
 59--       tcp
 60--           unicast transport using TCP, see zmq_tcp(7)
 61--
 62--       pgm, epgm
 63--           reliable multicast transport using PGM, see zmq_pgm(7)
 64--
 65--       With the exception of ZMQ_PAIR sockets, a single socket may be connected to multiple endpoints using zmq_connect(), while
 66--       simultaneously accepting incoming connections from multiple endpoints bound to the socket using zmq_bind(). Refer to
 67--       zmq_socket(3) for a description of the exact semantics involved when connecting or binding a socket to multiple endpoints.
 68--
 69   require an_address/=Void
 70   do
 71      is_successful := zmq_bind(handle,an_address.to_external)=0
 72      if is_unsuccessful then throw(zmq_exception) end
 73   end
 74
 75   connect (an_address: ABSTRACT_STRING)
 76      -- Connect Current socket to the endpoint specified by `an_address'.
 77
 78      -- `an_address' consists of two parts as follows: transport://address.
 79      -- The transport part specifies the underlying transport protocol to
 80      -- use. The meaning of the address part is specific to the underlying
 81      -- transport protocolselected.
 82
 83      -- The following transports are defined:
 84      --
 85      -- * inproc: local in-process (inter-thread) communication transport, see zmq_inproc(7) manpage
 86      --
 87      -- * ipc:    local inter-process communication transport, see zmq_ipc(7) manpage
 88      --
 89      -- * tcp:    unicast transport using TCP, see zmq_tcp(7) manpage.
 90      --
 91      -- * pgm, epgm: reliable multicast transport using PGM, see zmq_pgm(7)
 92
 93      -- With the exception of ZMQ_PAIR sockets, a single socket may be
 94      -- connected to multiple endpoints using `connect', while
 95      -- simultaneously accepting incoming connections from multiple
 96      -- endpoints bound to the socket using `bind'. See each effective heirs
 97      -- of ZMQ_SOCKET and creation procedures in ZMQ_CONTEXT for a
 98      -- description of the exact semantics involved when connecting or
 99      -- binding a socket to multiple endpoints.
100
101      -- Note: The connection will not be performed immediately but as needed
102      -- by 0MQ. Thus a successful invocation of `connect' does not indicate
103      -- that a physical connection was or can actually be established.
104   require an_address/=Void
105   do
106      is_successful := zmq_connect(handle,an_address.to_external)=0
107      if is_unsuccessful then throw(zmq_exception) end
108   end
109
110feature {ANY} -- Options
111   type: INTEGER_32
112      -- The type of Current socket. It is specified at creation time and cannot be modified afterwards.
113
114      --       Option value type    int
115      --       Option value unit    N/A
116      --       Default value       N/A
117      --       Applicable socket types    all
118
119      local res, result_size: INTEGER
120      do
121         result_size := Result.object_size
122         is_successful := zmq_getsockopt(handle, zmq_type, $Result, $result_size)=0
123         if is_unsuccessful then throw(zmq_exception) end
124      end
125
126   --   ZMQ_RCVMORE: More message parts to follow
127   --       The ZMQ_RCVMORE option shall return a boolean value indicating if the multi-part message currently being read from the
128   --       specified socket has more message parts to follow. If there are no message parts to follow or if the message currently being
129   --       read is not a multi-part message a value of zero shall be returned. Otherwise, a value of 1 shall be returned.
130   --
131   --       Refer to zmq_send(3) and zmq_recv(3) for a detailed description of sending/receiving multi-part messages.
132   --       Option value type    int64_t
133   --       Option value unit    boolean
134   --       Default value       N/A
135   --       Applicable socket types    all
136   --
137   --   ZMQ_HWM: Retrieve high water mark
138   --       The ZMQ_HWM option shall retrieve the high water mark for the specified socket. The high water mark is a hard limit on the
139   --       maximum number of outstanding messages 0MQ shall queue in memory for any single peer that the specified socket
140   --       communicating with.
141   --
142   --       If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, 0MQ shall take
143   --       appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3)
144   --       for details on the exact action taken for each socket type.
145   --
146   --       The default ZMQ_HWM value of zero means "no limit".
147   --
148   --       Option value type    uint64_t
149   --
150   --       Option value unit    messages
151   --
152   --       Default value       0
153   --
154   --       Applicable socket types    all
155   --
156   --   ZMQ_SWAP: Retrieve disk offload size
157   --       The ZMQ_SWAP option shall retrieve the disk offload (swap) size for the specified socket. A socket which has ZMQ_SWAP set to a
158   --       non-zero value may exceed its high water mark; in this case outstanding messages shall be offloaded to storage on disk rather
159   --       than held in memory.
160   --
161   --       The value of ZMQ_SWAP defines the maximum size of the swap space in bytes.
162   --       Option value type    int64_t
163   --
164   --       Option value unit    bytes
165   --
166   --       Default value       0
167   --
168   --       Applicable socket types    all
169   --
170   --   ZMQ_AFFINITY: Retrieve I/O thread affinity
171   --       The ZMQ_AFFINITY option shall retrieve the I/O thread affinity for newly created connections on the specified socket.
172   --
173   --       Affinity determines which threads from the 0MQ I/O thread pool associated with the socket’s context shall handle newly created
174   --       connections. A value of zero specifies no affinity, meaning that work shall be distributed fairly among all 0MQ I/O threads in
175   --       the thread pool. For non-zero values, the lowest bit corresponds to thread 1, second lowest bit to thread 2 and so on. For
176   --       example, a value of 3 specifies that subsequent connections on socket shall be handled exclusively by I/O threads 1 and 2.
177   --
178   --       See also zmq_init(3) for details on allocating the number of I/O threads for a specific context.
179   --
180   --       Option value type    uint64_t
181   --
182   --       Option value unit    N/A (bitmap)
183   --
184   --       Default value       0
185   --
186   --       Applicable socket types    N/A
187   --
188   --   ZMQ_IDENTITY: Retrieve socket identity
189   --       The ZMQ_IDENTITY option shall retrieve the identity of the specified socket. Socket identity determines if existing 0MQ
190   --       infrastructure (message queues, forwarding devices) shall be identified with a specific application and persist across
191   --       multiple runs of the application.
192   --
193   --       If the socket has no identity, each run of an application is completely separate from other runs. However, with identity set
194   --       the socket shall re-use any existing 0MQ infrastructure configured by the previous run(s). Thus the application may receive
195   --       messages that were sent in the meantime, message queue limits shall be shared with previous run(s) and so on.
196   --
197   --       Identity can be at least one byte and at most 255 bytes long. Identities starting with binary zero are reserved for use by 0MQ
198   --       infrastructure.
199   --
200   --       Option value type    binary data
201   --
202   --       Option value unit    N/A
203   --
204   --       Default value       NULL
205   --
206   --       Applicable socket types    all
207   --
208   --   ZMQ_RATE: Retrieve multicast data rate
209   --       The ZMQ_RATE option shall retrieve the maximum send or receive data rate for multicast transports using the specified socket.
210   --
211   --       Option value type    int64_t
212   --
213   --       Option value unit    kilobits per second
214   --
215   --       Default value       100
216   --
217   --       Applicable socket types    all, when using multicast transports
218   --
219   --   ZMQ_RECOVERY_IVL: Get multicast recovery interval
220   --       The ZMQ_RECOVERY_IVL option shall retrieve the recovery interval for multicast transports using the specified socket. The
221   --       recovery interval determines the maximum time in seconds that a receiver can be absent from a multicast group before
222   --       unrecoverable data loss will occur.
223   --
224   --       Option value type    int64_t
225   --
226   --       Option value unit    seconds
227   --
228   --       Default value       10
229   --
230   --       Applicable socket types    all, when using multicast transports
231   --
232   --
233   --   ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds
234   --       The ZMQ_RECOVERY_IVL’_MSEC option shall retrieve the recovery interval, in milliseconds, for multicast transports using the
235   --       specified 'socket. The recovery interval determines the maximum time in seconds that a receiver can be absent from a multicast
236   --       group before unrecoverable data loss will occur.
237   --
238   --       For backward compatibility, the default value of ZMQ_RECOVERY_IVL_MSEC is -1 indicating that the recovery interval should be
239   --       obtained from the ZMQ_RECOVERY_IVL option. However, if the ZMQ_RECOVERY_IVL_MSEC value is not zero, then it will take
240   --       precedence, and be used.
241   --
242   --
243   --       Option value type    int64_t
244   --
245   --       Option value unit    milliseconds
246   --
247   --       Default value       -1
248   --
249   --       Applicable socket types    all, when using multicast transports
250   --
251   --
252   --   ZMQ_MCAST_LOOP: Control multicast loop-back
253   --       The ZMQ_MCAST_LOOP option controls whether data sent via multicast transports can also be received by the sending host via
254   --       loop-back. A value of zero indicates that the loop-back functionality is disabled, while the default value of 1 indicates that
255   --       the loop-back functionality is enabled. Leaving multicast loop-back enabled when it is not required can have a negative impact
256   --       on performance. Where possible, disable ZMQ_MCAST_LOOP in production environments.
257   --
258   --
259   --       Option value type    int64_t
260   --
261   --       Option value unit    boolean
262   --
263   --       Default value       1
264   --
265   --       Applicable socket types    all, when using multicast transports
266   --
267   --
268   --   ZMQ_SNDBUF: Retrieve kernel transmit buffer size
269   --       The ZMQ_SNDBUF option shall retrieve the underlying kernel transmit buffer size for the specified socket. A value of zero
270   --       means that the OS default is in effect. For details refer to your operating system documentation for the SO_SNDBUF socket
271   --       option.
272   --
273   --
274   --       Option value type    uint64_t
275   --
276   --
277   --       Option value unit    bytes
278   --
279   --       Default value       0
280   --
281   --       Applicable socket types    all
282   --
283   --
284   --   ZMQ_RCVBUF: Retrieve kernel receive buffer size
285   --       The ZMQ_RCVBUF option shall retrieve the underlying kernel receive buffer size for the specified socket. A value of zero means
286   --       that the OS default is in effect. For details refer to your operating system documentation for the SO_RCVBUF socket option.
287   --
288   --
289   --       Option value type    uint64_t
290   --
291   --       Option value unit    bytes
292   --
293   --       Default value       0
294   --
295   --       Applicable socket types    all
296   --
297   --
298   --   ZMQ_LINGER: Retrieve linger period for socket shutdown
299   --       The ZMQ_LINGER option shall retrieve the linger period for the specified socket. The linger period determines how long pending
300   --       messages which have yet to be sent to a peer shall linger in memory after a socket is closed with zmq_close(3), and further
301   --       affects the termination of the socket’s context with zmq_term(3). The following outlines the different behaviours:
302   --
303   --       ·   The default value of -1 specifies an infinite linger period. Pending messages shall not be discarded after a call to
304   --      zmq_close(); attempting to terminate the socket’s context with zmq_term() shall block until all pending messages have been
305   --      sent to a peer.
306   --
307   --       ·   The value of 0 specifies no linger period. Pending messages shall be discarded immediately when the socket is closed with
308   --      zmq_close().
309   --
310   --       ·   Positive values specify an upper bound for the linger period in milliseconds. Pending messages shall not be discarded
311   --      after a call to zmq_close(); attempting to terminate the socket’s context with zmq_term() shall block until either all
312   --      pending messages have been sent to a peer, or the linger period expires, after which any pending messages shall be
313   --      discarded.
314   --
315   --      Option value type        int
316   --      Option value unit        milliseconds
317   --      Default value        -1 (infinite)
318   --      Applicable socket types   all
319   --
320   --
321   --   ZMQ_RECONNECT_IVL: Retrieve reconnection interval
322   --       The ZMQ_RECONNECT_IVL option shall retrieve the initial reconnection interval for the specified socket. The reconnection
323   --       interval is the period 0MQ shall wait between attempts to reconnect disconnected peers when using connection-oriented
324   --       transports.
325   --
326   --      Note
327   --      The reconnection interval may be randomized by 0MQ to prevent reconnection storms in topologies with a large number of
328   --      peers per socket.
329   --
330   --
331   --       Option value type    int
332   --
333   --       Option value unit    milliseconds
334   --
335   --       Default value       100
336   --
337   --       Applicable socket types    all, only for connection-oriented transports
338   --
339   --
340   --   ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval
341   --       The ZMQ_RECONNECT_IVL_MAX option shall retrieve the maximum reconnection interval for the specified socket. This is the
342   --       maximum period 0MQ shall wait between attempts to reconnect. On each reconnect attempt, the previous interval shall be doubled
343   --       untill ZMQ_RECONNECT_IVL_MAX is reached. This allows for exponential backoff strategy. Default value means no exponential
344   --       backoff is performed and reconnect interval calculations are only based on ZMQ_RECONNECT_IVL.
345   --
346   --      Note
347   --      Values less than ZMQ_RECONNECT_IVL will be ignored.
348   --
349   --
350   --       Option value type    int
351   --
352   --       Option value unit    milliseconds
353   --
354   --       Default value       0 (only use ZMQ_RECONNECT_IVL)
355   --
356   --       Applicable socket types    all, only for connection-oriented transport
357   --
358   --
359   --   ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections
360   --       The ZMQ_BACKLOG option shall retrieve the maximum length of the queue of outstanding peer connections for the specified
361   --       socket; this only applies to connection-oriented transports. For details refer to your operating system documentation for the
362   --       listen function.
363   --
364   --
365   --       Option value type    int
366   --
367   --       Option value unit    connections
368   --
369   --       Default value       100
370   --
371   --       Applicable socket types    all, only for connection-oriented transports
372   --
373   --
374   --   ZMQ_FD: Retrieve file descriptor associated with the socket
375   --       The ZMQ_FD option shall retrieve the file descriptor associated with the specified socket. The returned file descriptor can be
376   --       used to integrate the socket into an existing event loop; the 0MQ library shall signal any pending events on the socket in an
377   --       edge-triggered fashion by making the file descriptor become ready for reading.
378   --
379   --      Note
380   --      The ability to read from the returned file descriptor does not necessarily indicate that messages are available to be read
381   --      from, or can be written to, the underlying socket; applications must retrieve the actual event state with a subsequent
382   --      retrieval of the ZMQ_EVENTS option.
383   --
384   --      Caution
385   --      The returned file descriptor is intended for use with a poll or similar system call only. Applications must never attempt
386   --      to read or write data to it directly, neither should they try to close it.
387   --
388   --
389   --       Option value type    int on POSIX systems, SOCKET on Windows
390   --
391   --       Option value unit    N/A
392   --
393   --       Default value       N/A
394   --
395   --       Applicable socket types    all
396   --
397   --
398   --   ZMQ_EVENTS: Retrieve socket event state
399   --       The ZMQ_EVENTS option shall retrieve the event state for the specified socket. The returned value is a bit mask constructed by
400   --       OR’ing a combination of the following event flags:
401   --
402   --       ZMQ_POLLIN
403   --      Indicates that at least one message may be received from the specified socket without blocking.
404   --
405   --       ZMQ_POLLOUT
406   --      Indicates that at least one message may be sent to the specified socket without blocking.
407   --
408   --       The combination of a file descriptor returned by the ZMQ_FD option being ready for reading but no actual events returned by a
409   --       subsequent retrieval of the ZMQ_EVENTS option is valid; applications should simply ignore this case and restart their polling
410   --       operation/event loop.
411   --
412   --
413   --       Option value type    uint32_t
414   --
415   --       Option value unit    N/A (flags)
416   --
417   --       Default value       N/A
418   --
419   --       Applicable socket types    all
420   --
421   --
422   --RETURN VALUE
423   --       The zmq_getsockopt() function shall return zero if successful. Otherwise it shall return -1 and set errno to one of the values
424   --       defined below.
425   --
426   --ERRORS
427   --       EINVAL
428   --      The requested option option_name is unknown, or the requested option_len or option_value is invalid, or the size of the
429   --      buffer pointed to by option_value, as specified by option_len, is insufficient for storing the option value.
430   --
431   --       ETERM
432   --      The 0MQ context associated with the specified socket was terminated.
433   --
434   --       ENOTSOCK
435   --      The provided socket was invalid.
436   --
437   --       EINTR
438   --      The operation was interrupted by delivery of a signal.
439   --
440
441
442feature {} -- Constants
443   zmq_noblock: INTEGER_32
444      external "plug_in"
445      alias "{
446         location: "externals/generated"
447         module_name: "plugin"
448         feature_name: "ZMQ_NOBLOCK"
449      }"
450      end
451
452   zmq_sndmore: INTEGER_32
453      external "plug_in"
454      alias "{
455         location: "externals/generated"
456         module_name: "plugin"
457         feature_name: "ZMQ_SNDMORE"
458      }"
459      end
460   zmq_type: INTEGER_32
461      external "plug_in"
462      alias "{
463         location: "externals/generated"
464         module_name: "plugin"
465         feature_name: "ZMQ_TYPE"
466      }"
467      end
468      --   ZMQ_RCVMORE: More message parts to follow
469      --   ZMQ_HWM: Retrieve high water mark
470      --   ZMQ_SWAP: Retrieve disk offload size
471      --   ZMQ_AFFINITY: Retrieve I/O thread affinity
472      --   ZMQ_IDENTITY: Retrieve socket identity
473      --   ZMQ_RATE: Retrieve multicast data rate
474      --   ZMQ_RECOVERY_IVL: Get multicast recovery interval
475      --   ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds
476      --   ZMQ_MCAST_LOOP: Control multicast loop-back
477      --   ZMQ_SNDBUF: Retrieve kernel transmit buffer size
478      --   ZMQ_RCVBUF: Retrieve kernel receive buffer size
479      --   ZMQ_LINGER: Retrieve linger period for socket shutdown
480      --   ZMQ_RECONNECT_IVL: Retrieve reconnection interval
481      --   ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval
482      --   ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections
483      --   ZMQ_FD: Retrieve file descriptor associated with the socket
484      --   ZMQ_EVENTS: Retrieve socket event state
485      --       ZMQ_POLLIN
486      --       ZMQ_POLLOUT
487
488end -- class ZMQ_SOCKET
489
490-- Zero MQ Liberty Wrappers
491
492-- Copyright (C) 2010-2017: Paolo Redaelli
493
494-- This library is free software; you can redistribute it and/or
495-- modify it under the terms of the GNU Lesser General Public
496-- License as published by the Free Software Foundation; either
497-- version 3 of the License, or (at your option) any later version.
498--
499-- This library is distributed in the hope that it will be useful,
500-- but WITHOUT ANY WARRANTY; without even the implied warranty of
501-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
502-- Lesser General Public License for more details.
503--
504-- You should have received a copy of the GNU Lesser General Public
505-- License along with this library; if not, write to the Free Software
506-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA