comparison src/event-msw.c @ 558:ed498ef2108b

[xemacs-hg @ 2001-05-23 09:59:33 by ben] xemacs.mak: call `ver' to get the exact os version and put it in the installation; suggestion from adrian. behavior-defs.el: Add scroll-in-place, jka-compr, efs, fix up some things. pop.c: Remove BROKEN_CYGWIN. etc\sample.init.el: Rewrite to be much more careful about loading features -- now it decays gracefully even in the complete absence of packages. Also avoid doing obnoxious things when loading efs. configure.in: add some support for eventually turning on file coding by default. Fix numerous places where AC_MSG_WARN had quotes around its arg, which is bad. Replace with []. Same for AC_MSG_ERROR. s\cygwin32.h, s\mingw32.h: remove support for way old beta versions of cygwin. don't put -Wno-sign-compare in the system switches; this isn't a system issue. define BROKEN_SIGIO for cygwin to get C-g support. device-msw.c: signal an error rather than crash with an unavailable network printer (from Mike Alexander). event-msw.c: cleanup headers. fix (hopefully) an error with data corruption when sending to a network connection. fileio.c: Fix evil code that attempts to handle the ~user prefix by (a) always assuming we're referencing ourselves and not even verifying the user -- hence any file with a tilde as its first char is invalid! (b) if there wasn't a slash following the filename, the pointer was set *past* the end of file and we started reading from uninitialized memory. Now we simply treat these as files, always. optionally for 21.4 (doc fix): lread.c: cambia de pas_de_lache_ici -- al minimo usa la palabra certa. frame.c: fix warnings. emacs.c, nt.c, ntproc.c, process-nt.c, realpath.c, unexnt.c: rename MAX_PATH to standard PATH_MAX. process-nt.c, realpath.c: cleanup headers. process-unix.c, sysdep.c, systime.h, syswindows.h: kill BROKEN_CYGWIN and support for way old beta versions of cygwin. sysfile.h: use _MAX_PATH (Windows) preferentially for PATH_MAX if defined. include io.h on Cygwin (we need get_osfhandle()). include sys/fcntl.h always, since we were including it in various header files anyway. unexcw.c: fix up style to conform to standard. remove duplicate definition of PERROR. buffer.c: comment change. database.c, debug.h, device-tty.c, dired-msw.c, glyphs-msw.c: header cleanups (remove places that directly include a system header file, because we have our own layer to do this more cleanly and portably); indentation fixes.
author ben
date Wed, 23 May 2001 09:59:48 +0000
parents 666d73d6ac56
children b202fbfc7dea
comparison
equal deleted inserted replaced
557:f486da5f1a3b 558:ed498ef2108b
1 /* The mswindows event_stream interface. 1 /* The mswindows event_stream interface.
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Sun Microsystems, Inc. 3 Copyright (C) 1995 Sun Microsystems, Inc.
4 Copyright (C) 1996, 2000 Ben Wing. 4 Copyright (C) 1996, 2000, 2001 Ben Wing.
5 Copyright (C) 1997 Jonathan Harris. 5 Copyright (C) 1997 Jonathan Harris.
6 6
7 This file is part of XEmacs. 7 This file is part of XEmacs.
8 8
9 XEmacs is free software; you can redistribute it and/or modify it 9 XEmacs is free software; you can redistribute it and/or modify it
47 47
48 #ifdef HAVE_DRAGNDROP 48 #ifdef HAVE_DRAGNDROP
49 # include "dragdrop.h" 49 # include "dragdrop.h"
50 #endif 50 #endif
51 51
52 #include "buffer.h"
52 #include "device.h" 53 #include "device.h"
53 #include "events.h" 54 #include "events.h"
55 #include "faces.h"
54 #include "frame.h" 56 #include "frame.h"
55 #include "buffer.h"
56 #include "faces.h"
57 #include "lstream.h" 57 #include "lstream.h"
58 #include "objects-msw.h"
58 #include "process.h" 59 #include "process.h"
59 #include "redisplay.h" 60 #include "redisplay.h"
60 #include "select.h" 61 #include "select.h"
62 #include "sysdep.h"
61 #include "window.h" 63 #include "window.h"
64
65 #include "sysfile.h"
62 #include "sysproc.h" 66 #include "sysproc.h"
67 #include "systime.h"
63 #include "syswait.h" 68 #include "syswait.h"
64 #include "systime.h"
65 #include "sysdep.h"
66 #include "objects-msw.h"
67 69
68 #ifdef HAVE_MSG_SELECT 70 #ifdef HAVE_MSG_SELECT
69 #include "sysfile.h"
70 #include "console-tty.h" 71 #include "console-tty.h"
71 #elif defined(CYGWIN) 72 #elif defined(CYGWIN)
72 typedef unsigned int SOCKET; 73 typedef unsigned int SOCKET;
73 #endif 74 #endif
74 #include <io.h>
75 #include <errno.h>
76 75
77 #if !(defined(CYGWIN) || defined(MINGW)) 76 #if !(defined(CYGWIN) || defined(MINGW))
78 # include <shlobj.h> /* For IShellLink */ 77 # include <shlobj.h> /* For IShellLink */
79 #endif 78 #endif
80 79
662 struct winsock_stream 661 struct winsock_stream
663 { 662 {
664 LPARAM user_data; /* Any user data stored in the stream object */ 663 LPARAM user_data; /* Any user data stored in the stream object */
665 SOCKET s; /* Socket handle (which is a Win32 handle) */ 664 SOCKET s; /* Socket handle (which is a Win32 handle) */
666 OVERLAPPED ov; /* Overlapped I/O structure */ 665 OVERLAPPED ov; /* Overlapped I/O structure */
667 void* buffer; /* Buffer. Allocated for input stream only */ 666 void* buffer; /* Buffer. */
668 unsigned long bufsize; /* Number of bytes last read */ 667 unsigned long bufsize; /* Number of bytes last read */
669 unsigned long bufpos; /* Position in buffer for next fetch */ 668 unsigned long bufpos; /* Position in buffer for next fetch */
670 unsigned int error_p :1; /* I/O Error seen */ 669 unsigned int error_p :1; /* I/O Error seen */
671 unsigned int eof_p :1; /* EOF Error seen */ 670 unsigned int eof_p :1; /* EOF Error seen */
672 unsigned int pending_p :1; /* There is a pending I/O operation */ 671 unsigned int pending_p :1; /* There is a pending I/O operation */
772 return -1; 771 return -1;
773 772
774 if (size == 0) 773 if (size == 0)
775 return 0; 774 return 0;
776 775
777 { 776 ResetEvent (str->ov.hEvent);
778 ResetEvent (str->ov.hEvent); 777
779 778 /* According to WriteFile docs, we must hold onto the data we pass to it
780 /* Docs indicate that 4th parameter to WriteFile can be NULL since this is 779 and not make any changes until it finishes -- which may not be until
781 * an overlapped operation. This fails on Win95 with winsock 1.x so we 780 the next time we get here, since we use asynchronous I/O. We have
782 * supply a spare address which is ignored by Win95 anyway. Sheesh. */ 781 in fact seen data loss as a result of not doing this. */
783 if (WriteFile ((HANDLE)str->s, data, size, (LPDWORD)&str->buffer, &str->ov) 782 str->buffer = xrealloc (str->buffer, size);
784 || GetLastError() == ERROR_IO_PENDING) 783 memcpy (str->buffer, data, size);
785 str->pending_p = 1; 784
786 else 785 /* Docs indicate that 4th parameter to WriteFile can be NULL since this is
787 str->error_p = 1; 786 * an overlapped operation. This fails on Win95 with winsock 1.x so we
788 } 787 * supply a spare address which is ignored by Win95 anyway. Sheesh. */
788 if (WriteFile ((HANDLE)str->s, str->buffer, size, (LPDWORD)&str->buffer,
789 &str->ov)
790 || GetLastError() == ERROR_IO_PENDING)
791 str->pending_p = 1;
792 else
793 str->error_p = 1;
789 794
790 return str->error_p ? -1 : size; 795 return str->error_p ? -1 : size;
791 } 796 }
792 797
793 static int 798 static int
802 807
803 CloseHandle ((HANDLE)str->s); 808 CloseHandle ((HANDLE)str->s);
804 if (str->pending_p) 809 if (str->pending_p)
805 WaitForSingleObject (str->ov.hEvent, INFINITE); 810 WaitForSingleObject (str->ov.hEvent, INFINITE);
806 811
807 if (lstr->flags & LSTREAM_FL_READ) 812 if (str->buffer)
808 xfree (str->buffer); 813 xfree (str->buffer);
809 814
810 CloseHandle (str->ov.hEvent); 815 CloseHandle (str->ov.hEvent);
811 return 0; 816 return 0;
812 } 817 }
823 { 828 {
824 Lisp_Object obj; 829 Lisp_Object obj;
825 Lstream *lstr = Lstream_new (lstream_winsock, mode); 830 Lstream *lstr = Lstream_new (lstream_winsock, mode);
826 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr); 831 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
827 832
833 xzero (*str);
828 str->s = s; 834 str->s = s;
829 str->blocking_p = 0;
830 str->error_p = 0;
831 str->eof_p = 0;
832 str->pending_p = 0;
833 str->user_data = param; 835 str->user_data = param;
834 836
835 xzero (str->ov);
836 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); 837 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
837 838
838 if (lstr->flags & LSTREAM_FL_READ) 839 if (lstr->flags & LSTREAM_FL_READ)
839 { 840 {
840 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE); 841 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
2956 IPersistFile* ppf; 2957 IPersistFile* ppf;
2957 2958
2958 if (psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile, 2959 if (psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
2959 &ppf) == S_OK) 2960 &ppf) == S_OK)
2960 { 2961 {
2961 WORD wsz[MAX_PATH]; 2962 WORD wsz[PATH_MAX];
2962 WIN32_FIND_DATA wfd; 2963 WIN32_FIND_DATA wfd;
2963 LPSTR resolved = (char *) xmalloc (MAX_PATH+1); 2964 LPSTR resolved = (char *) xmalloc (PATH_MAX+1);
2964 2965
2965 MultiByteToWideChar (CP_ACP,0, fname, -1, wsz, MAX_PATH); 2966 MultiByteToWideChar (CP_ACP,0, fname, -1, wsz, PATH_MAX);
2966 2967
2967 if ((ppf->lpVtbl->Load (ppf, wsz, STGM_READ) == S_OK) && 2968 if ((ppf->lpVtbl->Load (ppf, wsz, STGM_READ) == S_OK) &&
2968 (psl->lpVtbl->GetPath (psl, resolved, MAX_PATH, 2969 (psl->lpVtbl->GetPath (psl, resolved, PATH_MAX,
2969 &wfd, 0)==S_OK)) 2970 &wfd, 0)==S_OK))
2970 { 2971 {
2971 xfree (fname); 2972 xfree (fname);
2972 fname = resolved; 2973 fname = resolved;
2973 len = strlen (fname); 2974 len = strlen (fname);