all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#45821: 28.0.50; Add UDP support for Emacs on Windows
@ 2021-01-12 18:08 Lars Ingebrigtsen
  2021-01-12 18:38 ` Eli Zaretskii
  2022-05-03 18:56 ` bug#45821: Emacs UDP support " Alex Matei
  0 siblings, 2 replies; 70+ messages in thread
From: Lars Ingebrigtsen @ 2021-01-12 18:08 UTC (permalink / raw)
  To: 45821


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 <sys/time.h> 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






^ permalink raw reply related	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2023-01-29  6:13 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-12 18:08 bug#45821: 28.0.50; Add UDP support for Emacs on Windows Lars Ingebrigtsen
2021-01-12 18:38 ` Eli Zaretskii
2021-01-13  9:17   ` Robert Pluim
2021-07-20 15:41     ` Lars Ingebrigtsen
2021-09-27 16:47       ` Robert Pluim
2021-09-27 17:45         ` Robert Pluim
2021-10-04 17:47           ` Robert Pluim
2021-10-04 17:59             ` Eli Zaretskii
2021-09-27 18:45         ` Eli Zaretskii
2021-10-11 11:56           ` Stefan Kangas
2021-10-11 12:06             ` Robert Pluim
2022-05-03 18:56 ` bug#45821: Emacs UDP support " Alex Matei
2022-05-04  7:35   ` Robert Pluim
2022-05-04 11:50     ` Alex Matei
2022-05-04 12:32       ` Robert Pluim
2022-09-11 11:26         ` bug#45821: 28.0.50; Add UDP support for Emacs " Lars Ingebrigtsen
2023-01-01 23:01         ` bug#45821: Emacs UDP support " Alex Matei
2023-01-02  0:47           ` Alex Matei
2023-01-02 10:22             ` Robert Pluim
2023-01-02 12:41               ` Eli Zaretskii
2023-01-02 13:29                 ` Robert Pluim
2023-01-02 13:38                   ` Eli Zaretskii
2023-01-02 22:56                     ` Alex Matei
2023-01-03  8:51                       ` Robert Pluim
2023-01-03 20:22                         ` Alex Matei
2023-01-04  9:32                           ` Robert Pluim
2023-01-04 10:15                             ` Alex Matei
2023-01-04 10:50                               ` Robert Pluim
2023-01-05 19:06                                 ` Alex Matei
2023-01-05 20:53                                   ` Alex Matei
2023-01-05 21:01                                     ` Alex Matei
2023-01-06  7:56                                       ` Robert Pluim
2023-01-07 11:24                                         ` Robert Pluim
2023-01-08 15:31                                           ` Alex Matei
2023-01-08 15:42                                             ` Robert Pluim
2023-01-08 15:43                                               ` Alex Matei
2023-01-08 16:00                                                 ` Alex Matei
2023-01-08 16:08                                                   ` Eli Zaretskii
2023-01-08 16:10                                                     ` Alex Matei
2023-01-10 12:41                                                       ` Alex Matei
2023-01-10 13:56                                                         ` Robert Pluim
2023-01-11 13:09                                                           ` Alex Matei
2023-01-11 13:23                                                             ` Alex Matei
2023-01-12  9:22                                                               ` Robert Pluim
2023-01-12 10:08                                                                 ` Eli Zaretskii
2023-01-12 10:14                                                                   ` Alex Matei
2023-01-12 10:24                                                                   ` Robert Pluim
2023-01-12 10:46                                                                     ` Eli Zaretskii
2023-01-12 10:57                                                                       ` Alex Matei
2023-01-12 10:59                                                                         ` Alex Matei
2023-01-12 11:03                                                                         ` Eli Zaretskii
2023-01-12 11:12                                                                           ` Alex Matei
2023-01-12 11:21                                                                             ` Robert Pluim
2023-01-12 11:23                                                                               ` Alex Matei
2023-01-12 11:18                                                                       ` Robert Pluim
2023-01-12 12:25                                                                         ` Eli Zaretskii
2023-01-12 13:28                                                                           ` Robert Pluim
2023-01-28 21:17                                                                             ` Alex Matei
2023-01-29  6:13                                                                               ` Eli Zaretskii
2023-01-02 10:10           ` Robert Pluim
2023-01-02 16:01             ` Alex Matei
2023-01-03 13:30               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-03 19:18                 ` Alex Matei
2023-01-02 12:07           ` Eli Zaretskii
2023-01-02 15:59             ` Alex Matei
2023-01-02 17:01               ` Eli Zaretskii
2023-01-02 17:57                 ` Alex Matei
2023-01-02 19:07                   ` Alex Matei
2023-01-02 19:22                     ` Eli Zaretskii
2023-01-02 19:24                       ` Alex Matei

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.