From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: ai_flags in calls to getaddrinfo, broader call for reproducibility check Date: Mon, 11 Jan 2021 21:12:44 +0100 Message-ID: <87y2gz2pxf.fsf@gmail.com> References: <83sg7mggls.fsf@gnu.org> <83czymc8nq.fsf@gnu.org> <74b7a0a9-0eb3-7944-19d2-f72424ee72d7@dasyatidae.com> <83eeirfqbo.fsf@gnu.org> <87o8hvscfi.fsf@gmail.com> <8335z7fmnz.fsf@gnu.org> <87ft374axc.fsf@gmail.com> <5cb6a0ac-9fe9-bfc2-5642-3423bd043238@dasyatidae.com> <8735z748p1.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10153"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Robin Tarsiger , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jan 11 21:13:59 2021 Return-path: Envelope-to: ged-emacs-devel@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 1kz3Zf-0002UG-2x for ged-emacs-devel@m.gmane-mx.org; Mon, 11 Jan 2021 21:13:59 +0100 Original-Received: from localhost ([::1]:57258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kz3Ze-0001Op-3T for ged-emacs-devel@m.gmane-mx.org; Mon, 11 Jan 2021 15:13:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kz3Ya-0000x4-Ir for emacs-devel@gnu.org; Mon, 11 Jan 2021 15:12:52 -0500 Original-Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:35179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kz3YX-0007uB-Ns; Mon, 11 Jan 2021 15:12:52 -0500 Original-Received: by mail-wr1-x42a.google.com with SMTP id r3so93688wrt.2; Mon, 11 Jan 2021 12:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-transfer-encoding; bh=Yo2iDuncCUCuZWO6GMPSXPSq6neXO96dfpH8qNA5aZ8=; b=nRpf1oYsMAhOPOa6LSWBKxMWMX9zG1Zi/fampUEBE65YNZRFZNXU2cTNiRZX22XWyQ uVBSItZZempiYyn25cmUFCBdfcrzozsGHneFNUl1BiH5oypdCculDN9wpxET7v/eoc6o BwjfRFsO3x9dkrvgippLxdlFhNy+3/B/S7dlX2ArD4hs0MW+11jIofU/J31rS/S8cbEg evE2OS2IxG6WmEBj8jluDFIIATC0tQx8eeB6Ri+feLM0yD1lQviMzFm9WNm9k3bA99FH QKddQ6ex+Wt4YSfU+hNey/ztFAAYhTwfozPWzDraVnDAtl8etiNCSGEkOXHd4yJWVSWF gApw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=Yo2iDuncCUCuZWO6GMPSXPSq6neXO96dfpH8qNA5aZ8=; b=qG4lS3mlP24w11aop+Q1fjjT+xMFzZ1PV99cnQPcRB869Wl8ClTeTDGRT6c9e9Tt9C esUr6clpM+bvGKQn5tOdc8DKavWzl8Ag3+m1UXtEZH20Ki1TQP8RQxocdIjnvHT8CLrM 4TOqSfOHRFaPrF+y+mQzY5+OgJ0+FzDHnyoFR8Kdq2sxxfOlgk//4rV1EyhSt6BahGXM Sfs7cGVUAGvLS6w9dMcVv/TThueQqKCU1CWtXoyR7Em7PdqPwuTNekT+vnGeJ4PKWwkb 6x8ZXYwXAXAcmqYzCSVT82cgKSxLLztViLTU6GBwuXuGP52iutczCjoGcHWBkN5vqWbJ BZ7A== X-Gm-Message-State: AOAM532ffZ6wobRqDunSnv73QdulgUhUntTCl6DW/TeOq3q7+AYllkKB iGT00l1X8rNSfoAP8rMIAokS+LwDF+GKPQ== X-Google-Smtp-Source: ABdhPJyQTSfIVxb9oDEyDJ38k8wWE7iuu0vZxIG6ziM4weEYLI47PisSL4uSBeWa/MCr0jVtPQvXNg== X-Received: by 2002:a5d:6443:: with SMTP id d3mr746434wrw.422.1610395967039; Mon, 11 Jan 2021 12:12:47 -0800 (PST) Original-Received: from rltb ([2a01:e34:ecfc:a861:69b6:6aaf:dbd3:8964]) by smtp.gmail.com with ESMTPSA id j7sm512996wmb.40.2021.01.11.12.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 12:12:45 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Mon, 11 Jan 2021 14:28:28 -0500") Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=rpluim@gmail.com; helo=mail-wr1-x42a.google.com 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, FREEMAIL_FROM=0.001, 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: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:262931 Archived-At: Stefan Monnier writes: >> Because the select implementation on windows does a one-byte readahead >> to see if data is available, which breaks UDP. I had a patch at one >> point to fix this, but I remember Eli not being very enthusiastic >> about it. I=CA=BCve attached what I think is the right version below (my >> windows box died, so I can't be sure) > > How 'bout installing it but make it conditional on some config var? > And maybe set that config var if/when a UDP socket is requested? I guess that=CA=BCs possible. I=CA=BCve now found the actual patch. If Eli thinks it=CA=BCs worth persuing, I can make it conditional, unless someone wants to spare me the trouble of setting up a working Windows dev environment :-). 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 =20 +#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 =20 /* 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; } =20 +#ifdef WORKING_SELECT_EMULATION +int +_sys_wait_readable (int fd) +{ + HANDLE hEv; + child_process * cp; + int rc; + + if (fd < 0 || fd >=3D MAXDESC) + return STATUS_READ_ERROR; + + cp =3D fd_info[fd].cp; + + if (cp =3D=3D NULL || cp->fd !=3D fd || cp->status !=3D STATUS_READ_READ= Y) + return STATUS_READ_ERROR; + + cp->status =3D STATUS_READ_FAILED; + + hEv =3D pfn_WSACreateEvent (); + rc =3D pfn_WSAEventSelect (SOCK_HANDLE (fd), hEv, FD_READ); + if (rc !=3D SOCKET_ERROR) + { + do + { + rc =3D WaitForSingleObject (hEv, 500); + Sleep (5); + } while (rc =3D=3D WAIT_TIMEOUT + && cp->status !=3D STATUS_READ_ERROR + && cp->char_avail); + pfn_WSAEventSelect (SOCK_HANDLE (fd), NULL, 0); + if (rc =3D=3D WAIT_OBJECT_0) + cp->status =3D 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; =20 case STATUS_READ_SUCCEEDED: - /* consume read-ahead char */ - *buffer++ =3D 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 =3D=3D 0) +#endif + { + /* consume read-ahead char */ + *buffer++ =3D cp->chr; + count--; + nchars++; + } cp->status =3D STATUS_READ_ACKNOWLEDGED; ResetEvent (cp->char_avail); =20 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 =20 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); =20 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 >=3D 0 && (fd_info[cp->fd].flags & FILE_LISTEN) !=3D= 0) rc =3D _sys_wait_accept (cp->fd); else - rc =3D _sys_read_ahead (cp->fd); +#ifdef WORKING_SELECT_EMULATION + if (fd_info[cp->fd].flags & FILE_SOCKET) + rc =3D _sys_wait_readable (cp->fd); + else +#endif + rc =3D _sys_read_ahead (cp->fd); =20 /* Don't bother waiting for the event if we already have been told to exit by delete_child. */