Forgot to add changes in prevois commit.
[cl-zmq.git] / zeromq.lisp
blob72547e1c3ad46deb25db29ad7faa1b404a68e731
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 (defcfun* ("zmq_init" init) :pointer
90 (io-threads :int))
92 (defcfun ("zmq_term" term) :int
93 (context :pointer))
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;; 0MQ socket definition.
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 (defconstant p2p 0)
100 (defconstant pub 1)
101 (defconstant sub 2)
102 (defconstant req 3)
103 (defconstant rep 4)
104 (defconstant xreq 5)
105 (defconstant xrep 6)
106 (defconstant upstream 7)
107 (defconstant downstream 8)
109 (defconstant hwm 1)
110 (defconstant swap 3)
111 (defconstant affinity 4)
112 (defconstant identity 5)
113 (defconstant subscribe 6)
114 (defconstant unsubscribe 7)
115 (defconstant rate 8)
116 (defconstant recovery-ivl 9)
117 (defconstant mcast-loop 10)
118 (defconstant sndbuf 11)
119 (defconstant rcvbuf 12)
120 (defconstant rcvmore 13)
122 (defconstant noblock 1)
123 (defconstant sndmore 2)
125 (defcfun* ("zmq_socket" socket) :pointer
126 (context :pointer)
127 (type :int))
129 (defcfun ("zmq_close" close) :int
130 (s :pointer))
132 (defcfun* ("zmq_setsockopt" %setsockopt) :int
133 (s :pointer)
134 (option :int)
135 (optval :pointer)
136 (optvallen :long))
138 (defcfun* ("zmq_getsockopt" %getsockopt) :int
139 (s :pointer)
140 (option :int)
141 (optval :pointer)
142 (optvallen :pointer))
144 (defcfun* ("zmq_bind" %bind) :int
145 (s :pointer)
146 (addr :pointer :char))
148 (defcfun* ("zmq_connect" %connect) :int
149 (s :pointer)
150 (addr :pointer :char))
153 (defcfun* ("zmq_send" %send) :int
154 (s :pointer)
155 (msg msg)
156 :optional
157 (flags :int))
159 (defcfun* ("zmq_recv" %recv) :int
160 (s :pointer)
161 (msg msg)
162 :optional
163 (flags :int))
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 ;; I/O multiplexing.
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
169 (defconstant pollin 1)
170 (defconstant pollout 2)
171 (defconstant pollerr 4)
173 (defcstruct pollitem
174 (socket :pointer)
175 (fd :int)
176 (events :short)
177 (revents :short))
179 (defcfun ("zmq_poll" %poll) :int
180 (items :pointer)
181 (nitems :int)
182 (timeout :long))
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
185 ;; Helper functions.
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 (defcfun ("zmq_version" %version) :void
189 (major :pointer)
190 (minor :pointer)
191 (patch :pointer))
193 (defcfun ("zmq_errno" errno) :int)
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;; Devices
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 (defconstant streamer 1)
200 (defconstant forwarder 2)
201 (defconstant queue 3)
203 (defcfun* ("zmq_device" %device) :int
204 (device :int)
205 (insocket :pointer)
206 (outsocket :pointer))