Get rid of LWM, it is computed automatically now.
[cl-zmq.git] / zeromq.lisp
blob8eb94534bdcee788e5f1050ff4821fef0fd0969e
1 ;; Copyright (c) 2009, 2010 Vitaly Mayatskikh <v.mayatskih@gmail.com>
2 ;;
3 ;; This file is part of CL-ZMQ.
4 ;;
5 ;; Vitaly Mayatskikh grants you the rights to distribute
6 ;; and use this software as governed by the terms
7 ;; of the Lisp Lesser GNU Public License
8 ;; (http://opensource.franz.com/preamble.html),
9 ;; known as the LLGPL.
11 (in-package :zeromq)
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 ;; 0MQ errors.
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 (defconstant hausnumero 156384712)
19 ;; Native 0MQ error codes.
20 (defconstant emthread (+ hausnumero 50))
21 (defconstant efsm (+ hausnumero 51))
22 (defconstant enocompatproto (+ hausnumero 52))
24 (defcfun ("zmq_strerror" %strerror) :pointer
25 (errnum :int))
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; 0MQ message definition.
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 (defconstant max-vsm-size 30)
33 ;; Message types. These integers may be stored in 'content' member of the
34 ;; message instead of regular pointer to the data.
35 (defconstant delimiter 31)
36 (defconstant vsm 32)
38 ;; Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag
39 ;; (it has no equivalent in the wire format), however, making it a flag
40 ;; allows us to pack the stucture tigher and thus improve performance.
41 (defconstant msg-more 1)
42 (defconstant msg-shared 128)
44 (defcstruct (msg)
45 (content :pointer)
46 (shared :uchar)
47 (vsm-size :uchar)
48 (vsm-data :uchar :count 30)) ;; FIXME max-vsm-size
50 (defcfun ("zmq_msg_init" msg-init) :int
51 (msg msg))
53 (defcfun* ("zmq_msg_init_size" %msg-init-size) :int
54 (msg msg)
55 (size :long))
57 (defcallback zmq-free :void ((ptr :pointer) (hint :pointer))
58 (declare (ignorable hint))
59 (foreign-free ptr))
61 (defcfun ("zmq_msg_init_data" msg-init-data) :int
62 (msg msg)
63 (data :pointer)
64 (size :long)
65 (ffn :pointer) ; zmq_free_fn
66 (hint :pointer))
68 (defcfun* ("zmq_msg_close" %msg-close) :int
69 (msg msg))
71 (defcfun ("zmq_msg_move" %msg-move) :int
72 (dest msg)
73 (src msg))
75 (defcfun ("zmq_msg_copy" %msg-copy) :int
76 (dest msg)
77 (src msg))
79 (defcfun ("zmq_msg_data" %msg-data) :pointer
80 (msg msg))
82 (defcfun ("zmq_msg_size" %msg-size) :int
83 (msg msg))
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 ;; 0MQ infrastructure (a.k.a. context) initialisation & termination.
87 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 (defconstant poll 1)
91 (defcfun* ("zmq_init" init) :pointer
92 (app-threads :int)
93 (io-threads :int)
94 (flags :int))
96 (defcfun ("zmq_term" term) :int
97 (context :pointer))
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 ;; 0MQ socket definition.
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 (defconstant p2p 0)
104 (defconstant pub 1)
105 (defconstant sub 2)
106 (defconstant req 3)
107 (defconstant rep 4)
108 (defconstant xreq 5)
109 (defconstant xrep 6)
110 (defconstant upstream 7)
111 (defconstant downstream 8)
113 (defconstant hwm 1)
114 (defconstant swap 3)
115 (defconstant affinity 4)
116 (defconstant identity 5)
117 (defconstant subscribe 6)
118 (defconstant unsubscribe 7)
119 (defconstant rate 8)
120 (defconstant recovery-ivl 9)
121 (defconstant mcast-loop 10)
122 (defconstant sndbuf 11)
123 (defconstant rcvbuf 12)
124 (defconstant rcvmore 13)
126 (defconstant noblock 1)
127 (defconstant sndmore 2)
129 (defcfun* ("zmq_socket" socket) :pointer
130 (context :pointer)
131 (type :int))
133 (defcfun ("zmq_close" close) :int
134 (s :pointer))
136 (defcfun* ("zmq_setsockopt" %setsockopt) :int
137 (s :pointer)
138 (option :int)
139 (optval :pointer)
140 (optvallen :long))
142 (defcfun* ("zmq_getsockopt" %getsockopt) :int
143 (s :pointer)
144 (option :int)
145 (optval :pointer)
146 (optvallen :pointer))
148 (defcfun* ("zmq_bind" %bind) :int
149 (s :pointer)
150 (addr :pointer :char))
152 (defcfun* ("zmq_connect" %connect) :int
153 (s :pointer)
154 (addr :pointer :char))
157 (defcfun* ("zmq_send" %send) :int
158 (s :pointer)
159 (msg msg)
160 :optional
161 (flags :int))
163 (defcfun* ("zmq_recv" %recv) :int
164 (s :pointer)
165 (msg msg)
166 :optional
167 (flags :int))
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 ;; I/O multiplexing.
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 (defconstant pollin 1)
174 (defconstant pollout 2)
175 (defconstant pollerr 4)
177 (defcstruct pollitem
178 (socket :pointer)
179 (fd :int)
180 (events :short)
181 (revents :short))
183 (defcfun ("zmq_poll" %poll) :int
184 (items :pointer)
185 (nitems :int)
186 (timeout :long))
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 ;; Helper functions.
190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 (defcfun ("zmq_stopwatch_start" stopwatch-start) :pointer)
194 (defcfun ("zmq_stopwatch_stop" stopwatch-stop) :ulong
195 (watch :pointer))
197 (defcfun ("zmq_sleep" sleep) :void
198 (seconds :int))
200 (defcfun ("zmq_version" %version) :void
201 (major :pointer)
202 (minor :pointer)
203 (patch :pointer))
205 (defcfun ("zmq_errno" errno) :int)
207 (defcfun* ("zmq_device" %device) :int
208 (device :int)
209 (insocket :pointer)
210 (outsocket :pointer))