unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: Allow specifying services as symbols?
Date: Wed, 20 Oct 2010 07:29:37 -0500	[thread overview]
Message-ID: <87wrpdavym.fsf@lifelogs.com> (raw)
In-Reply-To: m3d3r5f5ec.fsf@hase.home

[-- Attachment #1: Type: text/plain, Size: 334 bytes --]

On Wed, 20 Oct 2010 13:52:11 +0200 Andreas Schwab <schwab@linux-m68k.org> wrote: 

AS> Why not just move the hunk down to where service is checked for being a
AS> string?

That would be smarter, yes.  In the second place it was not a simple "if
else" so I somehow didn't think to do it correctly.  See the attached
third patch.

Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: make-network-connection-with-symbol-service.patch --]
[-- Type: text/x-diff, Size: 3468 bytes --]

=== modified file 'doc/lispref/processes.texi'
--- doc/lispref/processes.texi	2010-08-25 05:23:47 +0000
+++ doc/lispref/processes.texi	2010-10-20 11:18:48 +0000
@@ -1937,9 +1937,10 @@
 @var{buffer-or-name} is @code{nil}, it means that the connection is not
 associated with any buffer.
 
-The arguments @var{host} and @var{service} specify where to connect to;
-@var{host} is the host name (a string), and @var{service} is the name of
-a defined network service (a string) or a port number (an integer).
+The arguments @var{host} and @var{service} specify where to connect
+to; @var{host} is the host name (a string), and @var{service} is the
+name of a defined network service (a string or a symbol) or a port
+number (an integer).
 @end defun
 
 @node Network Servers
@@ -2076,10 +2077,10 @@
 
 @item :service @var{service}
 @var{service} specifies a port number to connect to, or, for a server,
-the port number to listen on.  It should be a service name that
-translates to a port number, or an integer specifying the port number
-directly.  For a server, it can also be @code{t}, which means to let
-the system select an unused port number.
+the port number to listen on.  It should be a service name (a string
+or a symbol) that translates to a port number, or an integer
+specifying the port number directly.  For a server, it can also be
+@code{t}, which means to let the system select an unused port number.
 
 @item :family @var{family}
 @var{family} specifies the address (and protocol) family for

=== modified file 'src/process.c'
--- src/process.c	2010-10-08 10:14:47 +0000
+++ src/process.c	2010-10-20 12:26:46 +0000
@@ -2978,10 +2978,11 @@
 host, and only clients connecting to that address will be accepted.
 
 :service SERVICE -- SERVICE is name of the service desired, or an
-integer specifying a port number to connect to.  If SERVICE is t,
-a random port number is selected for the server.  (If Emacs was
-compiled with getaddrinfo, a port number can also be specified as a
-string, e.g. "80", as well as an integer.  This is not portable.)
+integer specifying a port number to connect to.  If SERVICE is t, a
+random port number is selected for the server.  A port number can also
+be specified as a string, e.g. "80", or a symbol whose name will be
+used, as well as an integer.  This is not necessarily portable; either
+getaddrinfo or getservbyname will be used to look up the port number.
 
 :type TYPE -- TYPE is the type of connection.  The default (nil) is a
 stream type connection, `datagram' creates a datagram type connection,
@@ -3303,7 +3304,6 @@
      Otherwise, use getservbyname to lookup the service.  */
   if (!NILP (host))
     {
-
       /* SERVICE can either be a string or int.
 	 Convert to a C string for later use by getaddrinfo.  */
       if (EQ (service, Qt))
@@ -3313,6 +3313,11 @@
 	  sprintf (portbuf, "%ld", (long) XINT (service));
 	  portstring = portbuf;
 	}
+      /* Take a symbol as the service and convert it to a string.  */
+      else if (SYMBOLP (service))
+	{
+	  service = Fsymbol_name (service);
+	}
       else
 	{
 	  CHECK_STRING (service);
@@ -3353,6 +3358,12 @@
     port = htons ((unsigned short) XINT (service));
   else
     {
+      /* Take a symbol as the service and convert it to a string.  */
+      if (SYMBOLP (service))
+	{
+	  service = Fsymbol_name (service);
+	}
+
       struct servent *svc_info;
       CHECK_STRING (service);
       svc_info = getservbyname (SDATA (service),


      reply	other threads:[~2010-10-20 12:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-19 18:07 Allow specifying services as symbols? Lars Magne Ingebrigtsen
2010-10-19 18:22 ` Eli Zaretskii
2010-10-19 19:09 ` Ted Zlatanov
2010-10-19 20:17   ` Chong Yidong
2010-10-19 21:25     ` Ted Zlatanov
2010-10-19 21:32 ` Davis Herring
2010-10-19 22:20   ` Chong Yidong
2010-10-19 23:46     ` Lars Magne Ingebrigtsen
2010-10-20 15:36       ` Stefan Monnier
2010-10-20 16:10         ` Chong Yidong
2010-10-20 16:21         ` Ted Zlatanov
2010-10-20 11:32     ` Ted Zlatanov
2010-10-20 11:52       ` Andreas Schwab
2010-10-20 12:29         ` Ted Zlatanov [this message]

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=87wrpdavym.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --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).