defcfun*: don't place &optional in function definition if there's no
[cl-zmq.git] / zeromq.lisp
blob6230c74eca1e890ce8e82063607726fe49f772e0
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; 0MQ errors.
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 (defconstant hausnumero 156384712)
26 ;; On Windows platform some of the standard POSIX errnos are not defined.
27 ;; #ifndef ENOTSUP
28 ;; #define ENOTSUP (ZMQ_HAUSNUMERO + 1)
29 ;; #endif
30 ;; #ifndef EPROTONOSUPPORT
31 ;; #define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2)
32 ;; #endif
33 ;; #ifndef ENOBUFS
34 ;; #define ENOBUFS (ZMQ_HAUSNUMERO + 3)
35 ;; #endif
36 ;; #ifndef ENETDOWN
37 ;; #define ENETDOWN (ZMQ_HAUSNUMERO + 4)
38 ;; #endif
39 ;; #ifndef EADDRINUSE
40 ;; #define EADDRINUSE (ZMQ_HAUSNUMERO + 5)
41 ;; #endif
42 ;; #ifndef EADDRNOTAVAIL
43 ;; #define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6)
44 ;; #endif
46 ;; Native 0MQ error codes.
47 (defconstant emthread (+ hausnumero 50))
48 (defconstant efsm (+ hausnumero 51))
49 (defconstant enocompatproto (+ hausnumero 52))
51 (defcfun ("zmq_strerror" %strerror) :pointer
52 (errnum :int))
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;; 0MQ message definition.
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 (defconstant max-vsm-size 30)
60 ;; Message types. These integers may be stored in 'content' member of the
61 ;; message instead of regular pointer to the data.
62 (defconstant delimiter 31)
63 (defconstant vsm 32)
65 (defcstruct (msg)
66 (content :pointer)
67 (shared :uchar)
68 (vsm-size :uchar)
69 (vsm-data :uchar :count 30)) ;; FIXME max-vsm-size
71 (defcfun ("zmq_msg_init" msg-init) :int
72 (msg msg))
74 (defcfun* ("zmq_msg_init_size" %msg-init-size) :int
75 (msg msg)
76 (size :long))
78 (defcallback zmq-free :void ((ptr :pointer) (hint :pointer))
79 (declare (ignorable hint))
80 (foreign-free ptr))
82 (defcfun ("zmq_msg_init_data" msg-init-data) :int
83 (msg msg)
84 (data :pointer)
85 (size :long)
86 (ffn :pointer) ; zmq_free_fn
87 (hint :pointer))
89 (defcfun* ("zmq_msg_close" %msg-close) :int
90 (msg msg))
92 (defcfun ("zmq_msg_move" %msg-move) :int
93 (dest msg)
94 (src msg))
96 (defcfun ("zmq_msg_copy" %msg-copy) :int
97 (dest msg)
98 (src msg))
100 (defcfun ("zmq_msg_data" %msg-data) :pointer
101 (msg msg))
103 (defcfun ("zmq_msg_size" %msg-size) :int
104 (msg msg))
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;; 0MQ infrastructure (a.k.a. context) initialisation & termination.
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 (defconstant poll 1)
112 (defcfun* ("zmq_init" init) :pointer
113 (app-threads :int)
114 (io-threads :int)
115 (flags :int))
117 (defcfun ("zmq_term" term) :int
118 (context :pointer))
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 ;; 0MQ socket definition.
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 ;; Creating a 0MQ socket.
125 ;; **********************
127 (defconstant p2p 0)
128 (defconstant pub 1)
129 (defconstant sub 2)
130 (defconstant req 3)
131 (defconstant rep 4)
132 (defconstant xreq 5)
133 (defconstant xrep 6)
134 (defconstant upstream 7)
135 (defconstant downstream 8)
137 (defcfun* ("zmq_socket" socket) :pointer
138 (context :pointer)
139 (type :int))
141 ;; Destroying the socket.
142 ;; **********************
144 (defcfun ("zmq_close" close) :int
145 (s :pointer))
147 ;; Manipulating socket options.
148 ;; ****************************
150 ;; Available socket options, their types and default values.
152 (defconstant hwm 1)
153 (defconstant lwm 2)
154 (defconstant swap 3)
155 (defconstant affinity 4)
156 (defconstant identity 5)
157 (defconstant subscribe 6)
158 (defconstant unsubscribe 7)
159 (defconstant rate 8)
160 (defconstant recovery-ivl 9)
161 (defconstant mcast-loop 10)
162 (defconstant sndbuf 11)
163 (defconstant rcvbuf 12)
165 (defcfun* ("zmq_setsockopt" %setsockopt) :int
166 (s :pointer)
167 (option :int)
168 (optval :pointer)
169 (optvallen :long))
171 ;; Creating connections.
172 ;; *********************
174 ;; Addresses are composed of the name of the protocol to use followed by ://
175 ;; and a protocol-specific address. Available protocols:
177 ;; tcp - the address is composed of IP address and port delimited by colon
178 ;; sign (:). The IP address can be a hostname (with 'connect') or
179 ;; a network interface name (with 'bind'). Examples "tcp://eth0:5555",
180 ;; "tcp://192.168.0.1:20000", "tcp://hq.mycompany.com:80".
182 ;; pgm & udp - both protocols have same address format. It's network interface
183 ;; to use, semicolon (;), multicast group IP address, colon (:) and
184 ;; port. Examples: "pgm://eth2;224.0.0.1:8000",
185 ;; "udp://192.168.0.111;224.1.1.1:5555".
187 (defcfun* ("zmq_bind" %bind) :int
188 (s :pointer)
189 (addr :pointer :char))
191 (defcfun* ("zmq_connect" %connect) :int
192 (s :pointer)
193 (addr :pointer :char))
195 ;; Sending and receiving messages.
196 ;; *******************************
198 (defconstant noblock 1)
200 (defconstant noflush 2)
202 (defcfun* ("zmq_send" %send) :int
203 (s :pointer)
204 (msg msg)
205 :optional
206 (flags :int))
208 (defcfun* ("zmq_flush" flush) :int
209 (s :pointer))
211 (defcfun* ("zmq_recv" %recv) :int
212 (s :pointer)
213 (msg msg)
214 :optional
215 (flags :int))
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218 ;; I/O multiplexing.
219 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
221 (defconstant pollin 1)
222 (defconstant pollout 2)
223 (defconstant pollerr 4)
225 (defcstruct pollitem
226 (socket :pointer)
227 (fd :int)
228 (events :short)
229 (revents :short))
231 (defcfun ("zmq_poll" %poll) :int
232 (items :pointer)
233 (nitems :int)
234 (timeout :long))
236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
237 ;; Helper functions.
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
240 ;; Helper functions used by perf tests so that they don't have to care
241 ;; about minutiae of time-related functions on different OS platforms.
243 (defcfun ("zmq_stopwatch_start" stopwatch-start) :pointer)
245 (defcfun ("zmq_stopwatch_stop" stopwatch-stop) :ulong
246 (watch :pointer))
248 (defcfun ("zmq_sleep" sleep) :void
249 (seconds :int))
251 (defcfun ("zmq_version" %version) :void
252 (major :pointer)
253 (minor :pointer)
254 (patch :pointer))
256 (defcfun ("zmq_errno" errno) :int)