[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs-27 d66331a: Don't build the Gnulib 'utimens' module on MinGW
From: |
Robert Pluim |
Subject: |
Re: emacs-27 d66331a: Don't build the Gnulib 'utimens' module on MinGW |
Date: |
Tue, 24 Mar 2020 18:07:13 +0100 |
>>>>> On Mon, 23 Mar 2020 17:52:52 +0200, Eli Zaretskii <address@hidden> said:
>> From: Robert Pluim <address@hidden>
>> Cc: Eli Zaretskii <address@hidden>
>> Date: Mon, 23 Mar 2020 16:26:24 +0100
>>
>> Apropos: we explicitly donʼt use the gnulib 'select' module, even
>> though it looks like on MSWindows it handles both sockets and
>> pipes. What functionality is it missing?
Eli> SIGCHLD and C-g interrupts, I guess. Maybe something else as well, I
Eli> don't remember.
In that case I should go the other direction. How about the following
to remove the 1-char readahead for sockets (which then allows us to
enable datagram sockets on MSWindows).
modified src/w32.c
@@ -8798,6 +8798,43 @@ _sys_wait_accept (int fd)
return cp->status;
}
+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;
+}
+
int
_sys_wait_connect (int fd)
{
@@ -8923,10 +8960,6 @@ sys_read (int fd, char * buffer, unsigned int count)
return -1;
case STATUS_READ_SUCCEEDED:
- /* consume read-ahead char */
- *buffer++ = cp->chr;
- count--;
- nchars++;
cp->status = STATUS_READ_ACKNOWLEDGED;
ResetEvent (cp->char_avail);
modified src/w32.h
@@ -175,6 +175,7 @@ #define FILE_SERIAL 0x0800
extern int _sys_read_ahead (int fd);
extern int _sys_wait_accept (int fd);
+extern int _sys_wait_readable (int fd);
extern int _sys_wait_connect (int fd);
extern HMODULE w32_delayed_load (Lisp_Object);
modified src/w32proc.c
@@ -1225,7 +1225,10 @@ 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);
+ if (fd_info[cp->fd].flags & FILE_SOCKET)
+ rc = _sys_wait_readable (cp->fd);
+ else
+ rc = _sys_read_ahead (cp->fd);
/* Don't bother waiting for the event if we already have been
told to exit by delete_child. */