From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: Allow specifying services as symbols? Date: Wed, 20 Oct 2010 06:32:34 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87fww1je0d.fsf@lifelogs.com> References: <49549.130.55.132.18.1287523965.squirrel@webmail.lanl.gov> <8739s19648.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1287575064 1639 80.91.229.12 (20 Oct 2010 11:44:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 20 Oct 2010 11:44:24 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 20 13:44:23 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P8X5f-0002mS-BR for ged-emacs-devel@m.gmane.org; Wed, 20 Oct 2010 13:44:19 +0200 Original-Received: from localhost ([127.0.0.1]:47869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8X5e-0006VC-Mq for ged-emacs-devel@m.gmane.org; Wed, 20 Oct 2010 07:44:18 -0400 Original-Received: from [140.186.70.92] (port=54265 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8X3e-0005Ig-0O for emacs-devel@gnu.org; Wed, 20 Oct 2010 07:42:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8WuV-0004ea-Jq for emacs-devel@gnu.org; Wed, 20 Oct 2010 07:32:49 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:40618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8WuV-0004eL-8U for emacs-devel@gnu.org; Wed, 20 Oct 2010 07:32:47 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1P8WuT-0008Ki-GY for emacs-devel@gnu.org; Wed, 20 Oct 2010 13:32:45 +0200 Original-Received: from c-24-14-16-248.hsd1.il.comcast.net ([24.14.16.248]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Oct 2010 13:32:45 +0200 Original-Received: from tzz by c-24-14-16-248.hsd1.il.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Oct 2010 13:32:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 124 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-24-14-16-248.hsd1.il.comcast.net X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:zg5DVj2NvmvERxpvuE3d2js6POc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:131874 Archived-At: --=-=-= Content-Type: text/plain On Tue, 19 Oct 2010 18:20:55 -0400 Chong Yidong wrote: CY> "Davis Herring" writes: >>> ! :service SERVICE -- SERVICE is name of the service desired (a string >>> ! or a symbol) 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. "http", as well as an integer. This is >>> ! not portable.) >> >> As more of a philosophical objection than anything, t is a symbol. CY> Hmm, good catch. So's nil. OK, I will exclude t and nil. That was a problem with the patch (t was converted to "t" and nil to "nil"). Thanks for catching that! Revised version attached. CY> So let's back up for a moment, here. Lars, could you provide an example CY> that shows why it's convenient to allow symbols to name services? The issue came up as a customization user-side problem and I suggested allowing symbols. Using symbols is consistent with many other Emacs facilities (too many to list) that use symbols to enumerate a small set of choices. It makes customization simpler and less error-prone for software that uses `make-network-process'. It doesn't really cost anything. The only downside is that if in the future we decide to add options to the :service parameter besides t and nil, they won't be easy to retrofit. It's really not a big deal though, so if you're concerned about the downside I listed or any others, let's kill the idea. Ted --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=make-network-connection-with-symbol-service.patch === 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 11:20:53 +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,6 +3304,11 @@ Otherwise, use getservbyname to lookup the service. */ if (!NILP (host)) { + /* Take a symbol as the service and convert it to a string. */ + if (!NILP (service) && !EQ (service, Qt) && SYMBOLP (service)) + { + service = Fsymbol_name (service); + } /* SERVICE can either be a string or int. Convert to a C string for later use by getaddrinfo. */ @@ -3347,6 +3353,12 @@ /* We end up here if getaddrinfo is not defined, or in case no hostname has been specified (e.g. for a local server process). */ + /* Take a symbol as the service and convert it to a string. */ + if (!NILP (service) && !EQ (service, Qt) && SYMBOLP (service)) + { + service = Fsymbol_name (service); + } + if (EQ (service, Qt)) port = 0; else if (INTEGERP (service)) --=-=-=--