Rollback commit 9636f4ef1bbedad61e80dd621b800f4bf5a8c30e
[cl-zmq.git] / zeromq.lisp
blobc3c5b2b51436c4cd5d95c361fc2acc11ac1477ce
1 ;; Copyright (c) 2009, 2010 Vitaly Mayatskikh <v.mayatskih@gmail.com>
2 ;;
3 ;; This file is part of 0MQ.
4 ;;
5 ;; 0MQ is free software; you can redistribute it and/or modify it under
6 ;; the terms of the Lesser GNU General Public License as published by
7 ;; the Free Software Foundation; either version 3 of the License, or
8 ;; (at your option) any later version.
9 ;;
10 ;; 0MQ is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; Lesser GNU General Public License for more details.
15 ;; You should have received a copy of the Lesser GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (in-package :zeromq)
20 (defcvar "errno" :int)
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;; 0MQ errors.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (defconstant hausnumero 156384712)
28 ;; On Windows platform some of the standard POSIX errnos are not defined.
29 ;; #ifndef ENOTSUP
30 ;; #define ENOTSUP (ZMQ_HAUSNUMERO + 1)
31 ;; #endif
32 ;; #ifndef EPROTONOSUPPORT
33 ;; #define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2)
34 ;; #endif
35 ;; #ifndef ENOBUFS
36 ;; #define ENOBUFS (ZMQ_HAUSNUMERO + 3)
37 ;; #endif
38 ;; #ifndef ENETDOWN
39 ;; #define ENETDOWN (ZMQ_HAUSNUMERO + 4)
40 ;; #endif
41 ;; #ifndef EADDRINUSE
42 ;; #define EADDRINUSE (ZMQ_HAUSNUMERO + 5)
43 ;; #endif
44 ;; #ifndef EADDRNOTAVAIL
45 ;; #define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6)
46 ;; #endif
48 ;; Native 0MQ error codes.
49 (defconstant emthread (+ hausnumero 50))
50 (defconstant efsm (+ hausnumero 51))
51 (defconstant enocompatproto (+ hausnumero 52))
53 (defcfun ("zmq_strerror" %strerror) :pointer
54 (errnum :int))
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 ;; 0MQ message definition.
58 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 (defconstant max-vsm-size 30)
62 ;; Message types. These integers may be stored in 'content' member of the
63 ;; message instead of regular pointer to the data.
64 (defconstant delimiter 31)
65 (defconstant vsm 32)
67 (defcstruct (msg)
68 (content :pointer)
69 (shared :uchar)
70 (vsm-size :uchar)
71 (vsm-data :uchar :count 30)) ;; FIXME max-vsm-size
73 (defcfun ("zmq_msg_init" msg-init) :int
74 (msg msg))
76 (defcfun* ("zmq_msg_init_size" %msg-init-size) :int
77 (msg msg)
78 (size :long))
80 (defcallback zmq-free :void ((ptr :pointer) (hint :pointer))
81 (declare (ignorable hint))
82 (foreign-free ptr))
84 (defcfun ("zmq_msg_init_data" msg-init-data) :int
85 (msg msg)
86 (data :pointer)
87 (size :long)
88 (ffn :pointer) ; zmq_free_fn
89 (hint :pointer))
91 (defcfun* ("zmq_msg_close" %msg-close) :int
92 (msg msg))
94 (defcfun ("zmq_msg_move" %msg-move) :int
95 (dest msg)
96 (src msg))
98 (defcfun ("zmq_msg_copy" %msg-copy) :int
99 (dest msg)
100 (src msg))
102 (defcfun ("zmq_msg_data" %msg-data) :pointer
103 (msg msg))
105 (defcfun ("zmq_msg_size" %msg-size) :int
106 (msg msg))
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 ;; 0MQ infrastructure (a.k.a. context) initialisation & termination.
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 (defconstant poll 1)
114 (defcfun* ("zmq_init" init) :pointer
115 (app-threads :int)
116 (io-threads :int)
117 (flags :int))
119 (defcfun ("zmq_term" term) :int
120 (context :pointer))
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 ;; 0MQ socket definition.
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 ;; Creating a 0MQ socket.
127 ;; **********************
129 (defconstant p2p 0)
130 (defconstant pub 1)
131 (defconstant sub 2)
132 (defconstant req 3)
133 (defconstant rep 4)
134 (defconstant xreq 5)
135 (defconstant xrep 6)
136 (defconstant upstream 7)
137 (defconstant downstream 8)
139 (defcfun* ("zmq_socket" socket) :pointer
140 (context :pointer)
141 (type :int))
143 ;; Destroying the socket.
144 ;; **********************
146 (defcfun ("zmq_close" close) :int
147 (s :pointer))
149 ;; Manipulating socket options.
150 ;; ****************************
152 ;; Available socket options, their types and default values.
154 (defconstant hwm 1)
155 (defconstant lwm 2)
156 (defconstant swap 3)
157 (defconstant affinity 4)
158 (defconstant identity 5)
159 (defconstant subscribe 6)
160 (defconstant unsubscribe 7)
161 (defconstant rate 8)
162 (defconstant recovery-ivl 9)
163 (defconstant mcast-loop 10)
164 (defconstant sndbuf 11)
165 (defconstant rcvbuf 12)
167 (defcfun* ("zmq_setsockopt" %setsockopt) :int
168 (s :pointer)
169 (option :int)
170 (optval :pointer)
171 (optvallen :long))
173 ;; Creating connections.
174 ;; *********************
176 ;; Addresses are composed of the name of the protocol to use followed by ://
177 ;; and a protocol-specific address. Available protocols:
179 ;; tcp - the address is composed of IP address and port delimited by colon
180 ;; sign (:). The IP address can be a hostname (with 'connect') or
181 ;; a network interface name (with 'bind'). Examples "tcp://eth0:5555",
182 ;; "tcp://192.168.0.1:20000", "tcp://hq.mycompany.com:80".
184 ;; pgm & udp - both protocols have same address format. It's network interface
185 ;; to use, semicolon (;), multicast group IP address, colon (:) and
186 ;; port. Examples: "pgm://eth2;224.0.0.1:8000",
187 ;; "udp://192.168.0.111;224.1.1.1:5555".
189 (defcfun* ("zmq_bind" %bind) :int
190 (s :pointer)
191 (addr :pointer :char))
193 (defcfun* ("zmq_connect" %connect) :int
194 (s :pointer)
195 (addr :pointer :char))
197 ;; Sending and receiving messages.
198 ;; *******************************
200 (defconstant noblock 1)
202 (defconstant noflush 2)
204 (defcfun* ("zmq_send" %send) :int
205 (s :pointer)
206 (msg msg)
207 :optional
208 (flags :int))
210 (defcfun* ("zmq_flush" flush) :int
211 (s :pointer))
213 (defcfun* ("zmq_recv" %recv) :int
214 (s :pointer)
215 (msg msg)
216 :optional
217 (flags :int))
219 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 ;; I/O multiplexing.
221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
223 (defconstant pollin 1)
224 (defconstant pollout 2)
225 (defconstant pollerr 4)
227 (defcstruct pollitem
228 (socket :pointer)
229 (fd :int)
230 (events :short)
231 (revents :short))
233 (defcfun ("zmq_poll" %poll) :int
234 (items :pointer)
235 (nitems :int)
236 (timeout :long))
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
239 ;; Helper functions.
240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
242 ;; Helper functions used by perf tests so that they don't have to care
243 ;; about minutiae of time-related functions on different OS platforms.
245 (defcfun ("zmq_stopwatch_start" stopwatch-start) :pointer)
247 (defcfun ("zmq_stopwatch_stop" stopwatch-stop) :ulong
248 (watch :pointer))
250 (defcfun ("zmq_sleep" sleep) :void
251 (seconds :int))
253 (defcfun ("zmq_version" %version) :void
254 (major :pointer)
255 (minor :pointer)
256 (patch :pointer))