From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#45821: 28.0.50; Add UDP support for Emacs on Windows Date: Tue, 12 Jan 2021 19:08:12 +0100 Message-ID: <87turmhvub.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25732"; mail-complaints-to="usenet@ciao.gmane.io" To: 45821@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 12 19:24:40 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzOLP-0006Zv-Mf for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 19:24:39 +0100 Original-Received: from localhost ([::1]:49678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzOLO-0005xj-OM for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 13:24:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzO6J-0002me-2x for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 13:09:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kzO6I-0006j2-Py for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 13:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kzO6I-0002fE-Jr for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 13:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Jan 2021 18:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45821 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161047490310181 (code B ref -1); Tue, 12 Jan 2021 18:09:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Jan 2021 18:08:23 +0000 Original-Received: from localhost ([127.0.0.1]:33053 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kzO5f-0002e9-6E for submit@debbugs.gnu.org; Tue, 12 Jan 2021 13:08:23 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:54772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kzO5d-0002e1-2L for submit@debbugs.gnu.org; Tue, 12 Jan 2021 13:08:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzO5c-000232-Ts for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 13:08:20 -0500 Original-Received: from quimby.gnus.org ([2a01:4f9:2b:f0f::2]:56370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzO5Z-0006SA-Ua for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 13:08:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=E4mChs0GRyoXyIa4Ko4TGtyt7Uvcze6Z17aKy775xTI=; b=AeQHjOka9+sjze3IcdWExvhGJE 2OawoBAUjDQIE0uxI3d69lMHzFoAZT/1n7zyIGFU02TitESPOtgJhp8W2IDDVcCPvlWHul4yXUkzO ux97x7huMrwaOZnFlAtr/ZqkS1sPNHw2xX/6Nqn9EWClrguvdVP70rE6DSgEvdLsLb6U=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzO5V-0000Ox-PF for bug-gnu-emacs@gnu.org; Tue, 12 Jan 2021 19:08:16 +0100 X-Now-Playing: Kevin Hewick & New Order's _From Brussels With Love (1)_: "Haystack" Received-SPF: pass client-ip=2a01:4f9:2b:f0f::2; envelope-from=larsi@gnus.org; helo=quimby.gnus.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197821 Archived-At: This patch from Robert Pluim adds that support, but needs somebody that actually uses Windows to test it. As it stands you need to arrange for WORKING_SELECT_EMULATION to be defined. diff --git i/nt/inc/ms-w32.h w/nt/inc/ms-w32.h index 1cce2c3062..ea6ba38dea 100644 --- i/nt/inc/ms-w32.h +++ w/nt/inc/ms-w32.h @@ -63,10 +63,11 @@ #define _CALLBACK_ __cdecl Look in for a timeval structure. */ #define HAVE_TIMEVAL 1 +#ifndef WORKING_SELECT_EMULATION /* Our select emulation does 1-byte read-ahead waiting for received packets, so datagrams are broken. */ #define BROKEN_DATAGRAM_SOCKETS 1 - +#endif #define MAIL_USE_SYSTEM_LOCK 1 /* Define to 1 if GCC-style __attribute__ ((__aligned__ (expr))) works. */ diff --git i/src/w32.c w/src/w32.c index 698e10e234..c0457ff00f 100644 --- i/src/w32.c +++ w/src/w32.c @@ -8798,6 +8798,45 @@ _sys_wait_accept (int fd) return cp->status; } +#ifdef WORKING_SELECT_EMULATION +int +_sys_wait_readable (int fd) +{ + HANDLE hEv; + child_process * cp; + int rc; + + if (fd < 0 || fd >= MAXDESC) + return STATUS_READ_ERROR; + + cp = fd_info[fd].cp; + + if (cp == NULL || cp->fd != fd || cp->status != STATUS_READ_READY) + return STATUS_READ_ERROR; + + cp->status = STATUS_READ_FAILED; + + hEv = pfn_WSACreateEvent (); + rc = pfn_WSAEventSelect (SOCK_HANDLE (fd), hEv, FD_READ); + if (rc != SOCKET_ERROR) + { + do + { + rc = WaitForSingleObject (hEv, 500); + Sleep (5); + } while (rc == WAIT_TIMEOUT + && cp->status != STATUS_READ_ERROR + && cp->char_avail); + pfn_WSAEventSelect (SOCK_HANDLE (fd), NULL, 0); + if (rc == WAIT_OBJECT_0) + cp->status = STATUS_READ_SUCCEEDED; + } + pfn_WSACloseEvent (hEv); + + return cp->status; +} +#endif + int _sys_wait_connect (int fd) { @@ -8923,10 +8962,16 @@ sys_read (int fd, char * buffer, unsigned int count) return -1; case STATUS_READ_SUCCEEDED: - /* consume read-ahead char */ - *buffer++ = cp->chr; - count--; - nchars++; +#ifdef WORKING_SELECT_EMULATION + /* select on sockets no longer requires a 1-byte read. */ + if (fd_info[fd].flags & FILE_SOCKET == 0) +#endif + { + /* consume read-ahead char */ + *buffer++ = cp->chr; + count--; + nchars++; + } cp->status = STATUS_READ_ACKNOWLEDGED; ResetEvent (cp->char_avail); diff --git i/src/w32.h w/src/w32.h index cf1dadf64c..cabe39fb6d 100644 --- i/src/w32.h +++ w/src/w32.h @@ -175,6 +175,9 @@ #define FILE_SERIAL 0x0800 extern int _sys_read_ahead (int fd); extern int _sys_wait_accept (int fd); +#ifdef WORKING_SELECT_EMULATION +extern int _sys_wait_readable (int fd); +#endif extern int _sys_wait_connect (int fd); extern HMODULE w32_delayed_load (Lisp_Object); diff --git i/src/w32proc.c w/src/w32proc.c index de33726905..376e49d13d 100644 --- i/src/w32proc.c +++ w/src/w32proc.c @@ -1225,7 +1225,12 @@ reader_thread (void *arg) else if (cp->fd >= 0 && (fd_info[cp->fd].flags & FILE_LISTEN) != 0) rc = _sys_wait_accept (cp->fd); else - rc = _sys_read_ahead (cp->fd); +#ifdef WORKING_SELECT_EMULATION + if (fd_info[cp->fd].flags & FILE_SOCKET) + rc = _sys_wait_readable (cp->fd); + else +#endif + rc = _sys_read_ahead (cp->fd); /* Don't bother waiting for the event if we already have been told to exit by delete_child. */ In GNU Emacs 28.0.50 (build 20, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0) of 2021-01-12 built on xo Repository revision: 78ef0a72fa57c05c4be1401b2304c106a02c257d Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12008000 System Description: Debian GNU/Linux bullseye/sid -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no