From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kyotaro HORIGUCHI Newsgroups: gmane.emacs.devel Subject: Re: make-network-process(:nowait t) on MS-Windows Date: Wed, 30 Nov 2005 17:43:10 +0900 (JST) Message-ID: <20051130.174310.56260920.horiguti@horiguti.meadowy.org> References: <20051125.002640.103856392.horiguti@horiguti.meadowy.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1133362222 29695 80.91.229.2 (30 Nov 2005 14:50:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 30 Nov 2005 14:50:22 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 30 15:50:11 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EhPtM-0001sH-1v for ged-emacs-devel@m.gmane.org; Wed, 30 Nov 2005 12:12:52 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EhPo5-0006KG-TE for ged-emacs-devel@m.gmane.org; Wed, 30 Nov 2005 06:07:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EhNZO-0006od-Ra for emacs-devel@gnu.org; Wed, 30 Nov 2005 03:44:07 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EhNZF-0006nt-T7 for emacs-devel@gnu.org; Wed, 30 Nov 2005 03:43:59 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EhNZC-0006nf-Gk for emacs-devel@gnu.org; Wed, 30 Nov 2005 03:43:55 -0500 Original-Received: from [202.224.39.198] (helo=mail.asahi-net.or.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EhNZB-0000F8-U0 for emacs-devel@gnu.org; Wed, 30 Nov 2005 03:43:54 -0500 Original-Received: from localhost (g052188.ppp.asahi-net.or.jp [211.132.52.188]) by mail.asahi-net.or.jp (Postfix) with ESMTP id A59751C580; Wed, 30 Nov 2005 17:43:16 +0900 (JST) Original-To: emacs-devel@gnu.org In-Reply-To: <20051125.002640.103856392.horiguti@horiguti.meadowy.org> User-Agent: Mew version 4.2.54 on Emacs 22.0 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.00-dev =?iso-2022-jp?B?KBskQjVGGyhCKQ==?= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:46809 Archived-At: me> make-network-process with parameter `:nowait t' returns nil me> instead of process when evaluating the sample lisp code below on me> MS-Windows. It seems to have worked once, but does not now. me> me> The following patch make this work again. The errors occurrs after make-network-process returned cannot be caught with the previous patch. Because select() of Winsock returns the failure of the connect with efds, not wfds. Concerning only this issue, and using select(), the simplest way to make this work as expected is to merge efds into wfds returned by Winsock select(). -- Kyotaro HORIGUCHI Index: w32proc.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/w32proc.c,v retrieving revision 1.65 diff -u -2 -r1.65 w32proc.c --- w32proc.c 7 Aug 2005 12:33:18 -0000 1.65 +++ w32proc.c 29 Nov 2005 04:13:45 -0000 @@ -1056,5 +1056,5 @@ SELECT_TYPE orfds; DWORD timeout_ms, start_time; - int i, nh, nc, nr; + int i, nh, nc, nr, nw; DWORD active; child_process *cp, *cps[MAX_CHILDREN]; @@ -1072,5 +1072,5 @@ /* Otherwise, we only handle rfds, so fail otherwise. */ - if (rfds == NULL || wfds != NULL || efds != NULL) + if ((rfds == NULL && wfds == NULL) || efds != NULL) { errno = EINVAL; @@ -1081,4 +1081,5 @@ FD_ZERO (rfds); nr = 0; + nw = 0; /* Always wait on interrupt_handle, to detect C-g (quit). */ @@ -1185,4 +1186,25 @@ } + if (wfds) + { + int i; + SELECT_TYPE efds = *wfds; + struct timeval tm = {0, 0}; + + nw = sys_select_socket (nfds, NULL, wfds, &efds, &tm); + + /* merge retuend efds and wfds */ + for (i = 0 ; i < nfds ; i++) + { + if (FD_ISSET (i, &efds)) + FD_SET (i, wfds); + } + + /* Assume this socket is waiting for connection of + non-blocking socket. */ + if (nw < 0) + return nw; + } + count_children: /* Add handles of child processes. */ @@ -1326,4 +1348,5 @@ /* If no input has arrived and timeout hasn't expired, wait again. */ + nr += nw; if (nr == 0) { Index: w32.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/w32.c,v retrieving revision 1.97 diff -u -2 -r1.97 w32.c --- w32.c 12 Sep 2005 10:27:02 -0000 1.97 +++ w32.c 29 Nov 2005 04:13:46 -0000 @@ -101,4 +101,9 @@ #include "systime.h" +typedef struct { + unsigned int fd_count; + SOCKET fd_array[FD_SETSIZE]; +} pfn_fd_set; + typedef HRESULT (WINAPI * ShGetFolderPath_fn) (IN HWND, IN int, IN HANDLE, IN DWORD, OUT char *); @@ -2696,4 +2701,5 @@ int (PASCAL *pfn_bind) (SOCKET s, const struct sockaddr *addr, int namelen); int (PASCAL *pfn_connect) (SOCKET s, const struct sockaddr *addr, int namelen); +int (PASCAL *pfn_select) (int nfds, pfn_fd_set *readfds, pfn_fd_set *writefds, pfn_fd_set *excepfds, const struct timeval FAR *timeout); int (PASCAL *pfn_ioctlsocket) (SOCKET s, long cmd, u_long *argp); int (PASCAL *pfn_recv) (SOCKET s, char * buf, int len, int flags); @@ -2778,4 +2784,5 @@ LOAD_PROC( bind ); LOAD_PROC( connect ); + LOAD_PROC( select ); LOAD_PROC( ioctlsocket ); LOAD_PROC( recv ); @@ -2852,4 +2859,5 @@ case WSAENAMETOOLONG: h_errno = ENAMETOOLONG; break; case WSAENOTEMPTY: h_errno = ENOTEMPTY; break; + case WSAEWOULDBLOCK: h_errno = EINPROGRESS; break; } errno = h_errno; @@ -3136,4 +3144,69 @@ h_errno = ENOTSOCK; return SOCKET_ERROR; +} + +int +sys_select_socket (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + int i, j, k, rc, cfds; + pfn_fd_set *fds[3]; + fd_set *efds[3]; + + if (winsock_lib == NULL) + { + h_errno = ENOTSOCK; + return SOCKET_ERROR; + } + + check_errno (); + + cfds = 0; + efds[0] = readfds; + efds[1] = writefds; + efds[2] = exceptfds; + + for (i = 0 ; i < 3 ; i++) + { + fds[i] = NULL; + if (efds[i]) + { + fds[i] = (pfn_fd_set*)alloca (sizeof (pfn_fd_set)); + fds[i]->fd_count = 0; + for (j = 0 ; j < nfds ; j++) + if (FD_ISSET (j, efds[i])) + { + if (! (fd_info[j].flags & FILE_SOCKET)) + { + h_errno = ENOTSOCK; + return SOCKET_ERROR; + } + + fds[i]->fd_array[fds[i]->fd_count++] = SOCK_HANDLE (j); + cfds++; + } + FD_ZERO (efds[i]); + } + } + + if (cfds == 0) + return 0; + + rc = pfn_select (nfds, fds[0], fds[1], fds[2], timeout); + + if (rc > 0) + for (i = 0 ; i < 3 ; i++) + if (fds[i]) + for (j = 0 ; j < fds[i]->fd_count ; j++) + { + for (k = 0 ; + k < nfds && fds[i]->fd_array [j] != SOCK_HANDLE (k) ; + k++); + if (k < nfds) + FD_SET (k, efds[i]); + } + + if (rc == SOCKET_ERROR) + set_errno (); + return rc; }