emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New patch for server sockets and datagram (UDP) support.


From: Kim F. Storm
Subject: Re: New patch for server sockets and datagram (UDP) support.
Date: 07 Mar 2002 11:56:25 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.50

I wrote:

> The following patch adds server socket support via open-network-stream.
> If the HOST is nil, a server socket for SERVICE is opened in listening
> state.
> 
I forgot to say, that the code is working nicely, but the patch is
still "work in progress" to let you know how this is progressing and
get your comments on the direction it is taking.


> I have removed the NON-BLOCKING argument, and instead added a new TYPE
> argument, which specifies the type of connection (blocking connect,
> non-blocking connect, or datagram), and may optionally specify the
> address family (inet or local [aka. unix]).

Actually, I would like to get rid of this extra TYPE argument
all together by modifying the HOST and SERVICE arguments in a 
backwards compatible way (when calling open-network-stream):

When the HOST and SERVICE are specified as "simple" arguments (strings
or integer port number), a TCP/IP connection is created using a
blocking connect.

To get a non-blocking TCP connect, or a datagram socket, the SERVICE
argument is a cons (TYPE . SERVICE), where TYPE is t for a non-blocking
connect, and `datagram' for a datagram socket.

Likewise, to use another address/protocol family than IP, the HOST
argument is a cons (FAMILY . HOST), where FAMILY is `local' for
a local (aka UNIX) socket.


Also, I think that HOST should be t to get a server socket rather
than nil.  This is because, for a local (UNIX) socket, there is no
hostname, so the hostname would logically be nil for a client.


However, there is one problem with this approach:

The value returned from `process-contact' for a network stream is
specified to be (HOST SERVICE) -- which my patch modifies to 
(HOST SERVICE TYPE FILTER SENTINEL).

The only use I've found for process-contact is in the clone-process
function where it is obviously assumed to return the parameters
originally given to open-network-stream (thus the change).

Now, if I want to get rid of TYPE by modifing the possible arguments
for HOST and SERVICE, this would obviously have to be reflected in
the value returned by process-contact as well.

So if code currently exists which expects (car (process-contact p)) or
(cadr (process-contact p)) to return the hostname or service, that
code will fail after the change.  But I haven't found any such code
though -- do you know of any code using process-contact?

My suggestion is to change `process-contact' to do the following:

For a network conntecton, the value is a list (HOST SERVICE FILTER SENTINEL)
with the same format as the corresponding arguments to `open-network-stream'.

The current doc string says:
For a net connection, the value is a cons cell of the form (HOST SERVICE).

Below you can see the difference between using the TYPE argument
and encoding the information in the HOST and SERVICE args (and
using HOST=t for a server socket).

> 
> To open a TCP server socket for "telnet", where client
> processes have no buffer, do
> 
>  (open-network-stream "telnetd" nil nil "telnet" nil 
>         telnetd-filter telnetd-sentinel)

 (open-network-stream "telnetd" nil t "telnet"
        telnetd-filter telnetd-sentinel)

> 
> To open a UDP (datagram) server socket for "dns", do
> 
>  (open-network-stream "dns" nil nil "dns" 'datagram
>         dns-filter dns-sentinel)

 (open-network-stream "dns" nil t '(datagram . "dns")
        dns-filter dns-sentinel)
> 
> To open a LOCAL (UNIX) server socket for "/tmp/xyz", where
> client processes do have a buffer, do
> 
>  (open-network-stream "xyz" "XYZ" nil "/tmp/xyz" '(local)
>         xyz-filter xyz-sentinel)

 (open-network-stream "xyz" "XYZ" '(local . t) "/tmp/xyz"
        xyz-filter xyz-sentinel)


To connect to each of these services, specify the hostname (or nil for
a local socket) instead of t in the third argument (and modify other
parameters according to the desired use), e.g.

 ;; non-blocking connect, use buffer, no filter
 (open-network-stream "telnet" "TELNET" "hostname" '(t . "telnet")
        nil telnet-client-sentinel)

 ;; datagram "connect", no buffer, use filter
 (open-network-stream "dns" nil "hostname" '(datagram . "dns")
        dns-filter dns-sentinel)

 ;; local socket, non-blocking connect, use buffer, no filter
 (open-network-stream "xyz" "XYZ" '(local) '(t . "/tmp/xyz")
        nil xyz-sentinel)


What do you think?

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]