1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
3 ;;; pkgdcl.lisp --- Package definition.
5 ;;; Copyright (C) 2006-2008, Attila Lendvai <attila.lendvai@gmail.com>
7 ;;; This code is free software; you can redistribute it and/or
8 ;;; modify it under the terms of the version 2.1 of
9 ;;; the GNU Lesser General Public License as published by
10 ;;; the Free Software Foundation, as clarified by the
11 ;;; preamble found here:
12 ;;; http://opensource.franz.com/preamble.html
14 ;;; This program is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU Lesser General
20 ;;; Public License along with this library; if not, write to the
21 ;;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;;; Boston, MA 02110-1301, USA
24 (in-package :sockets
/cc-tests
)
28 (defparameter *external-format
* (babel:ensure-external-format
'(:utf-8
:eol-style
:crlf
)))
30 (defun start-reverser-server (&key
(address +loopback
+) (port 4242) (worker-count 4)
31 (external-format *external-format
*))
32 (bind ((acceptor (make-connection-acceptor 'reverser-connection-handler
33 :worker-count worker-count
34 :external-format external-format
)))
38 (startup-acceptor acceptor
:address address
:port port
)
39 ;; TODO until epoll based multiplexing is added
40 (break "Server started, continue to shut it down")
41 ;;(sockets/cc::busy-loop-hack acceptor)
43 (shutdown-acceptor acceptor
))))
46 (defun/cc reverser-connection-handler
(connection)
48 for line
= (read-line/cc connection
)
49 until
(zerop (length line
)) do
51 (write-string (nreverse line
) connection
)
53 (force-output connection
))))
56 (defun start-reverser-client (&key
(address +loopback
+) (port 4242) (worker-count 4)
57 (external-format *external-format
*))
58 (bind ((multiplexer (make-instance 'connection-multiplexer
)))
61 (bind ((acceptor (make-connection-acceptor 'reversering-connection-handler
62 :worker-count worker-count
63 :external-format
'(:utf-8
:eol-style
:crlf
))))
67 (startup-acceptor acceptor
:address address
:port port
)
68 ;;(break "Acceptor running, continue this thread to shut it down")
70 (shutdown-acceptor acceptor
))))
74 (defun reverser-client-worker-loop (address port external-format
)
75 (bind ((socket (make-socket :connect
:active
:external-format external-format
))
79 (setf (fd-non-blocking socket
) t
)
80 (bind-address socket
(ensure-hostname address
)
83 (apply 'listen-on socket
(when backlog
84 (list :backlog backlog
)))
85 (setf (socket-of acceptor
) socket
)
86 #+nil
(loop repeat
(worker-count-of acceptor
) do
87 (spawn-worker-thread-for-acceptor acceptor
))