Fix client example.
[cl-cluster.git] / transport-zmq.lisp
bloba88f95d814eb28f486b3a7a7821331579b47ecd7
1 ;; Copyright 2010 Vitaly Mayatskikh <v.mayatskih@gmail.com>
2 ;;
3 ;; This file is a part of CL-Cluster
4 ;;
5 ;; CL-Cluster is free software: you can redistribute it and/or modify
6 ;; it under the terms of the 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 ;; CL-Cluster 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 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (in-package :cl-cluster)
20 (defclass node-zmq (node)
21 ((endpoint :initarg :endpoint :accessor node-zmq-endpoint)
22 (context :initform nil :accessor node-zmq-context)
23 (socket :initform nil :accessor node-zmq-socket)
24 (type :initform zmq:req :initarg :type :accessor node-zmq-type)
25 (message :initform nil :accessor node-zmq-message)))
27 (defmethod print-object ((object node-zmq) stream)
28 (format stream "#N<NODE:\"~a\" ENDPOINT:\"~a\">"
29 (node-name object) (node-zmq-endpoint object)))
31 (defmethod node-alive-p ((object node-zmq))
32 (not (null (node-zmq-socket object))))
34 (defmethod node-connect ((object node-zmq))
35 (with-slots (context socket endpoint type) object
36 (setf context (zmq:init 1 1 0)
37 socket (zmq:socket context type))
38 (zmq:connect socket endpoint)))
40 (defmethod node-disconnect ((object node-zmq))
41 (with-slots (context socket) object
42 (zmq:close socket)
43 (zmq:term context)
44 (setf context nil
45 socket nil)))
47 (defmethod node-send/unsafe ((object node-zmq) msg)
48 (zmq:send (node-zmq-socket object) (make-instance 'zmq:msg :data msg)))
50 (defmethod node-recv/unsafe ((object node-zmq) &optional non-blocking)
51 (let ((msg (make-instance 'zmq:msg)))
52 (zmq:recv (node-zmq-socket object) msg)
53 (read-from-string (zmq:msg-data-as-string msg))))
55 (defmethod node-flush/unsafe ((object node-zmq) &optional wait-input)
57 ; (zmq:flush (node-zmq-socket object)))