/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

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