-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzeromq.lisp
273 lines (221 loc) · 6.95 KB
/
zeromq.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
;; Copyright (c) 2009, 2010 Vitaly Mayatskikh <[email protected]>
;;
;; This file is part of CL-ZMQ.
;;
;; Vitaly Mayatskikh grants you the rights to distribute
;; and use this software as governed by the terms
;; of the Lisp Lesser GNU Public License
;; (http://opensource.franz.com/preamble.html),
;; known as the LLGPL.
(in-package :zeromq)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 0MQ errors.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconstant +hausnumero+ 156384712)
;; Native 0MQ error codes.
(defconstant +emthread+ (+ +hausnumero+ 50))
(defconstant +efsm+ (+ +hausnumero+ 51))
(defconstant +enocompatproto+ (+ +hausnumero+ 52))
;; DEPRECATED
(defconstant hausnumero 156384712)
(defconstant emthread (+ hausnumero 50))
(defconstant efsm (+ hausnumero 51))
(defconstant enocompatproto (+ hausnumero 52))
(defcfun ("zmq_strerror" %strerror) :pointer
(errnum :int))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 0MQ message definition.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconstant +max-vsm-size+ 30)
;; Message types. These integers may be stored in 'content' member of the
;; message instead of regular pointer to the data.
(defconstant +delimiter+ 31)
(defconstant +vsm+ 32)
;; Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag
;; (it has no equivalent in the wire format), however, making it a flag
;; allows us to pack the stucture tigher and thus improve performance.
(defconstant +msg-more+ 1)
(defconstant +msg-shared+ 128)
;; DEPRECATED
(defconstant max-vsm-size 30)
(defconstant delimiter 31)
(defconstant vsm 32)
(defconstant msg-more 1)
(defconstant msg-shared 128)
(defcstruct (msg)
(content :pointer)
(shared :uchar)
(vsm-size :uchar)
(vsm-data :uchar :count 30)) ;; FIXME max-vsm-size
(defcfun ("zmq_msg_init" msg-init) :int
(msg msg))
(defcfun* ("zmq_msg_init_size" %msg-init-size) :int
(msg msg)
(size :long))
(defcallback zmq-free :void ((ptr :pointer) (hint :pointer))
(declare (ignorable hint))
(foreign-free ptr))
(defcfun ("zmq_msg_init_data" msg-init-data) :int
(msg msg)
(data :pointer)
(size :long)
(ffn :pointer) ; zmq_free_fn
(hint :pointer))
(defcfun* ("zmq_msg_close" %msg-close) :int
(msg msg))
(defcfun ("zmq_msg_move" %msg-move) :int
(dest msg)
(src msg))
(defcfun ("zmq_msg_copy" %msg-copy) :int
(dest msg)
(src msg))
(defcfun ("zmq_msg_data" %msg-data) :pointer
(msg msg))
(defcfun ("zmq_msg_size" %msg-size) :int
(msg msg))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 0MQ infrastructure (a.k.a. context) initialisation & termination.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcfun* ("zmq_init" init) :pointer
(io-threads :int))
(defcfun ("zmq_term" term) :int
(context :pointer))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 0MQ socket definitions (version 2.1).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; socket types.
(defconstant +pair+ 0)
(defconstant +pub+ 1)
(defconstant +sub+ 2)
(defconstant +req+ 3)
(defconstant +rep+ 4)
(defconstant +dealer+ 5)
(defconstant +router+ 6)
(defconstant +pull+ 7)
(defconstant +push+ 8)
(defconstant +xreq+ +dealer+)
(defconstant +xrep+ +router+)
(defconstant +upstream+ +pull+)
(defconstant +downstream+ +push+)
;; socket options.
(defconstant +hwm+ 1)
(defconstant +swap+ 3)
(defconstant +affinity+ 4)
(defconstant +identity+ 5)
(defconstant +subscribe+ 6)
(defconstant +unsubscribe+ 7)
(defconstant +rate+ 8)
(defconstant +recovery-ivl+ 9)
(defconstant +mcast-loop+ 10)
(defconstant +sndbuf+ 11)
(defconstant +rcvbuf+ 12)
(defconstant +rcvmore+ 13)
(defconstant +fd+ 14)
(defconstant +events+ 15)
(defconstant +type+ 16)
(defconstant +linger+ 17)
(defconstant +reconnect-ivl+ 18)
(defconstant +backlog+ 19)
(defconstant +recovery-ivl-msec+ 20) ;; opt. recovery time, reconcile in 3.x
(defconstant +reconnect-ivl-max+ 21)
;; send/recv options
(defconstant +noblock+ 1)
(defconstant +sndmore+ 2)
;; DEPRECATED (version 2.0 only)
(defconstant pair 0)
(defconstant pub 1)
(defconstant sub 2)
(defconstant req 3)
(defconstant rep 4)
(defconstant xreq 5)
(defconstant xrep 6)
(defconstant pull 7)
(defconstant push 8)
(defconstant upstream pull)
(defconstant downstream push)
(defconstant hwm 1)
(defconstant swap 3)
(defconstant affinity 4)
(defconstant identity 5)
(defconstant subscribe 6)
(defconstant unsubscribe 7)
(defconstant rate 8)
(defconstant recovery-ivl 9)
(defconstant mcast-loop 10)
(defconstant sndbuf 11)
(defconstant rcvbuf 12)
(defconstant rcvmore 13)
(defconstant noblock 1)
(defconstant sndmore 2)
(defcfun* ("zmq_socket" socket) :pointer
(context :pointer)
(type :int))
(defcfun ("zmq_close" close) :int
(s :pointer))
(defcfun* ("zmq_setsockopt" %setsockopt) :int
(s :pointer)
(option :int)
(optval :pointer)
(optvallen :long))
(defcfun* ("zmq_getsockopt" %getsockopt) :int
(s :pointer)
(option :int)
(optval :pointer)
(optvallen :pointer))
(defcfun* ("zmq_bind" %bind) :int
(s :pointer)
(addr :pointer :char))
(defcfun* ("zmq_connect" %connect) :int
(s :pointer)
(addr :pointer :char))
(defcfun* ("zmq_send" %send) :int
(s :pointer)
(msg msg)
:optional
(flags :int))
(defcfun* ("zmq_recv" %recv) :int
(s :pointer)
(msg msg)
:optional
(flags :int))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; I/O multiplexing.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconstant +pollin+ 1)
(defconstant +pollout+ 2)
(defconstant +pollerr+ 4)
;; DEPRECATED
(defconstant pollin 1)
(defconstant pollout 2)
(defconstant pollerr 4)
(defcstruct pollitem
(socket :pointer)
(fd :int)
(events :short)
(revents :short))
(defcfun ("zmq_poll" %poll) :int
(items :pointer)
(nitems :int)
(timeout :long))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcfun ("zmq_version" %version) :void
(major :pointer)
(minor :pointer)
(patch :pointer))
(defcfun ("zmq_errno" errno) :int)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Devices
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconstant +streamer+ 1)
(defconstant +forwarder+ 2)
(defconstant +queue+ 3)
;; DEPRECATED
(defconstant streamer 1)
(defconstant forwarder 2)
(defconstant queue 3)
(defcfun* ("zmq_device" %device) :int
(device :int)
(insocket :pointer)
(outsocket :pointer))