rename the 'p2p' socket type to 'pair'
[cl-zmq.git] / zeromq.lisp
blob463f0765f3a22311e166b63d116e16d1bb7cc9ea
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 pair 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 pull 7)
107 (defconstant push 8)
108 (defconstant upstream pull)
109 (defconstant downstream push)
111 (defconstant hwm 1)
112 (defconstant swap 3)
113 (defconstant affinity 4)
114 (defconstant identity 5)
115 (defconstant subscribe 6)
116 (defconstant unsubscribe 7)
117 (defconstant rate 8)
118 (defconstant recovery-ivl 9)
119 (defconstant mcast-loop 10)
120 (defconstant sndbuf 11)
121 (defconstant rcvbuf 12)
122 (defconstant rcvmore 13)
124 (defconstant noblock 1)
125 (defconstant sndmore 2)
127 (defcfun* ("zmq_socket" socket) :pointer
128 (context :pointer)
129 (type :int))
131 (defcfun ("zmq_close" close) :int
132 (s :pointer))
134 (defcfun* ("zmq_setsockopt" %setsockopt) :int
135 (s :pointer)
136 (option :int)
137 (optval :pointer)
138 (optvallen :long))
140 (defcfun* ("zmq_getsockopt" %getsockopt) :int
141 (s :pointer)
142 (option :int)
143 (optval :pointer)
144 (optvallen :pointer))
146 (defcfun* ("zmq_bind" %bind) :int
147 (s :pointer)
148 (addr :pointer :char))
150 (defcfun* ("zmq_connect" %connect) :int
151 (s :pointer)
152 (addr :pointer :char))
155 (defcfun* ("zmq_send" %send) :int
156 (s :pointer)
157 (msg msg)
158 :optional
159 (flags :int))
161 (defcfun* ("zmq_recv" %recv) :int
162 (s :pointer)
163 (msg msg)
164 :optional
165 (flags :int))
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 ;; I/O multiplexing.
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
171 (defconstant pollin 1)
172 (defconstant pollout 2)
173 (defconstant pollerr 4)
175 (defcstruct pollitem
176 (socket :pointer)
177 (fd :int)
178 (events :short)
179 (revents :short))
181 (defcfun ("zmq_poll" %poll) :int
182 (items :pointer)
183 (nitems :int)
184 (timeout :long))
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; Helper functions.
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190 (defcfun ("zmq_version" %version) :void
191 (major :pointer)
192 (minor :pointer)
193 (patch :pointer))
195 (defcfun ("zmq_errno" errno) :int)
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 ;; Devices
199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
201 (defconstant streamer 1)
202 (defconstant forwarder 2)
203 (defconstant queue 3)
205 (defcfun* ("zmq_device" %device) :int
206 (device :int)
207 (insocket :pointer)
208 (outsocket :pointer))