unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: Feature suggestion: server sockets
Date: 18 Feb 2002 16:10:45 +0100	[thread overview]
Message-ID: <5xadu6rfka.fsf@kfs2.cua.dk> (raw)
In-Reply-To: <200202162352.AAA23847@xaital.online-marketwatch.com>

In gnu.emacs.bug, helmut@xaital.km4u.net (Helmut Eller) wrote:

> Dear Emacs Developers,
> 
> Emacs has currently no support for server sockets.  Server sockets
> (sometimes called passive sockets) would be useful for packages like
> emacserver, gnuserv, or EmacsHttpd.  Such "server like" packages are
> currently somewhat hard to write, because they must use an external
> program that opens the server socket and forwards the input to Emacs.
> With the patch below, Emacs would be able to open server sockets
> itself.

This sounds like a useful addition to me.

I am currently working on a different aspect of network support
(optionally making open-network-stream non-blocking), and I have
modified open-network-stream to take two optional arguments:
        FILTER and SENTINEL
to set the process filter and sentinel as part of opening the
network stream (to avoid race conditions).  The SENTINEL is
called when the connect completes (either in success or failure).

I suspect that your proposal for open-server-socket could similarly
have the FILTER and SENTINEL functions as arguments.  Then I don't see
any need for your accept-connection function as SENTINEL could be
called when a new connection is accepted, and the FILTER could be used
as a normal filter (processing received data) for the connection.

If you don't want to accept more connections on the server-socket,
it should be closed in the sentinel.

> 
> I propose the following Lisp level interface to server sockets:
> 
> Server sockets, like network connections, are represented as
> processes.  The only purpose of a "server socket process" is to handle
> incoming connections.  Server socket processes work asynchronous: the
> process waits for an incoming connection and passes the connection to
> the filter function.  The new connection is treated afterwards exactly
> like a connection created with `open-network-stream'.  Two new
> primitives are needed for server sockets:
> 
>   - Function: open-server-socket NAME PORT -> PROCESS
> 
>     This function opens a TCP server socket on the given port and
>     returns a process object.  NAME is the name for the process.
> 
> Incoming connections are accepted one at a time with the second new
> primitive: accept-connection.  accept-connection allows the server
> socket process to accept the next connection.  accept-connection is
> non-blocking and returns nil.
> 
>   - Function: accept-connection PROCESS NAME -> nil 
> 
>     PROCESS is a server socket process.  NAME is the name for the
>     incoming connection that will be passed to the process filter.
> 
> Server sockets can be closed with delete-process.  The process-status
> of a server socket process is either `listen' or `closed'.  The
> process-buffer slot is unused for server sockets.  
> 
> I hope the following example helps to clarify a bit; it implements an
> echo server:
> 
>   (defun server-socket-filter (server-socket client-socket)
>     (set-process-filter client-socket #'send-string)
>     (accept-connection server-socket "client-socket")) 
>     
>   (defun start-echo-server ()
>     (let ((server-socket (open-server-socket "server-socket" 7)))
>       (set-process-filter server-socket #'server-socket-filter)
>       (accept-connection server-socket "client-socket")))
> 
> We open a server socket on port 7; install a filter function and allow
> the process to accept the next connection.  When the next request
> arrives, Emacs will create a network stream with name "client-socket"
> and pass it along with the server socket to server-socket-filter.  In
> server-socket-filter we set #'send-string as filter function (to
> perform the actual echoing) and accept the the next connection (to
> handle multiple connections in parallel).
> 
> Note that filter functions are called only when Emacs is idle or
> waiting for something.
> 
> 
> The patch affects the files process.c and process.h (a comment).  I
> have tested it only on my GNU/Linux box.
> 
> Let me know if you decide to integrate the patch in the standard
> Emacs.
> 

In that case, I guess papers are needed.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk


_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel


       reply	other threads:[~2002-02-18 15:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200202162352.AAA23847@xaital.online-marketwatch.com>
2002-02-18 15:10 ` Kim F. Storm [this message]
2002-02-18 18:26   ` Feature suggestion: server sockets Helmut Eller
2002-02-19  6:36 ` Richard Stallman
2002-02-19 21:33   ` Helmut Eller
2002-02-20 22:13     ` Richard Stallman
2002-02-20 22:33       ` Helmut Eller
2002-02-20 22:13     ` Richard Stallman
2002-02-20 23:53       ` Helmut Eller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5xadu6rfka.fsf@kfs2.cua.dk \
    --to=storm@cua.dk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).