orthecreedence / cl-async

Asynchronous IO library for Common Lisp.
MIT License
275 stars 40 forks source link

can I accepted client socket in another event loop? #180

Open ljj038 opened 4 years ago

ljj038 commented 4 years ago
(syntax:use-syntax :interpol)

(defun master-worker-server ()
  (let ((server (as:tcp-server "127.0.0.1"
                               8000
                               (lambda (client-socket data)
                                 (as:write-socket-data client-socket
                                                       #?"HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8\r\n\r\n<h1>works!</h1>\r\n"
                                                       :write-cb (lambda (client-socket)
                                                                   (as:close-socket client-socket))))
                               :connect-cb (lambda (socket)
                                             (format t "connetion established~%")))))
    (as:signal-handler as:+sigint+
                       (lambda (sig)
                         (declare (ignorable sig))
                         (as:exit-event-loop)))
    server))

Can I prepare several event loop to listen and accept client socket, like nginx do.

I dont know how to replace the default read-cb and connect-cb.

I think if we can do this, maybe the server's performance will be much better than only one event loop