From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.devel Subject: Re: Using file descriptors in Emacs Date: Sat, 10 Sep 2016 10:28:44 -0400 Message-ID: <87twdn25ib.fsf@earth.catern.com> References: <1465262706-5229-1-git-send-email-sbaugh@catern.com> <87twfevqu7.fsf@earth.catern.com> <87pood5fee.fsf@earth.catern.com> <834m5p83yy.fsf@gnu.org> <877fal56zh.fsf@earth.catern.com> <83d1kcaowk.fsf@gnu.org> <8737l86glg.fsf@earth.catern.com> <837fakan8b.fsf@gnu.org> <87r38s4xmv.fsf@earth.catern.com> <83oa3w8byt.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1473517800 17896 195.159.176.226 (10 Sep 2016 14:30:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2016 14:30:00 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 10 16:29:56 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bijHy-0003Nc-Ie for ged-emacs-devel@m.gmane.org; Sat, 10 Sep 2016 16:29:50 +0200 Original-Received: from localhost ([::1]:34692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bijHw-0008T3-Lu for ged-emacs-devel@m.gmane.org; Sat, 10 Sep 2016 10:29:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bijHL-0008Sw-Uf for emacs-devel@gnu.org; Sat, 10 Sep 2016 10:29:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bijHH-0002Nm-Nh for emacs-devel@gnu.org; Sat, 10 Sep 2016 10:29:10 -0400 Original-Received: from [195.159.176.226] (port=58713 helo=blaine.gmane.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bijHH-0002MT-H1 for emacs-devel@gnu.org; Sat, 10 Sep 2016 10:29:07 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bijH1-0005Gd-9P for emacs-devel@gnu.org; Sat, 10 Sep 2016 16:28:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 65 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:KBtwyTTyu0DjMFOfG/Chlr3TD7Y= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207354 Archived-At: Eli Zaretskii writes: >> From: sbaugh@catern.com >> Date: Fri, 09 Sep 2016 16:38:16 -0400 >> >> >> Not as far as I know - what in my patches suggests that I need a pipe? >> > >> > A pipe is a set of 2 file descriptors between 2 programs, one of the >> > descriptors is used for reading by one program and writing by the >> > other, the other descriptor used similarly in the opposite direction. >> > Isn't that what you set up? >> > >> > If not, then I must be missing something, so please describe the data >> > flow between emacsclient, emacs server, and the external program. >> >> There is not necessarily any external program. Even emacsclient can exit >> just fine once the file descriptors are passed in and a process object >> created from them. >> >> Once a process object P is created, the data flow is as follows: >> >> When emacs writes to P, emacs is directly writing to the file descriptor >> that emacsclient had as its stdout. It is literally calling "write" on >> the file descriptor that was/is emacsclient's stdout. >> >> When emacs reads from P, emacs is directly reading from the file >> descriptor that emacsclient had as its stdin. It is literally calling >> "read" on the file descriptor that was/is emacsclient's stdin. > > Emacs doesn't normally read or write from/to file descriptors. The > only features that do such things are communications with > subprocesses, which could be either local subprocesses (in which case > Emacs talks to them via a pipe) or remote processes (in which case we > use network or serial connections). One other kind of feature that > uses file descriptors is external data sources, such as D-Bus and > inotify, which are a kind of local process (the OS kernel or some > other daemon) that doesn't need to be run by Emacs, only communicated > with. > > As we already have a framework for all of the above, what other kinds > of descriptors, which don't fit into the framework, would we like to > have? > >> For example I would like to bring eshell up to par with other Unix >> shells, and the ability to manipulate file descriptors directly is >> pretty much required for that. > > Please elaborate: how are file descriptors required for that? A shell > needs to pass file descriptors to the subprocesses it invokes, which > AFAIK we already do in the primitives that invoke subprocesses. What > else is needed, and how does the feature you propose fit into that? Two features that I would like to add to eshell (or some shell in Emacs) that I believe will require the ability to directly manipulate file descriptors: - Piping data to and from processes without that data round-tripping through Emacs, which is necessary if I want to write a pipeline processing any significant amount of data (which I frequently do in even casual shell use) - Redirecting higher file descriptors than 0/1/2 (that is, when creating a process, before forking, use dup2 to rearrange what file descriptors are in what slots) Of the two, the first is more important, but I think the second is also necessary.