@@ -355,6 +355,15 @@ cdef class UVStream(UVBaseTransport):
355355 Py_ssize_t blen
356356 int saved_errno
357357 int fd
358+
359+ if system.PLATFORM_IS_WINDOWS:
360+ # Winloop comment: WSASend below does not work with pipes.
361+ # For pipes, using Writefile() from Windows fileapi.h would
362+ # be an option, but the corresponding files have been created
363+ # FILE_FLAG_OVERLAPPED set, but we don't want to go that way here.
364+ # We detect pipes on Windows as pseudosockets.
365+ if self ._get_socket().family == uv.AF_UNIX:
366+ return - 1
358367
359368 if (< uv.uv_stream_t* > self ._handle).write_queue_size != 0 :
360369 raise RuntimeError (
@@ -383,16 +392,17 @@ cdef class UVStream(UVBaseTransport):
383392 # uv_try_write -- less layers of code. The error
384393 # checking logic is copied from libuv.
385394 written = system.write(fd, buf, blen)
386- while written == - 1 and (
387- errno.errno == errno.EINTR or
388- (system.PLATFORM_IS_APPLE and
389- errno.errno == errno.EPROTOTYPE)):
390- # From libuv code (unix/stream.c):
391- # Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
392- # EPROTOTYPE can be returned while trying to write to a socket
393- # that is shutting down. If we retry the write, we should get
394- # the expected EPIPE instead.
395- written = system.write(fd, buf, blen)
395+ if not system.PLATFORM_IS_WINDOWS:
396+ while written == - 1 and (
397+ errno.errno == errno.EINTR or
398+ (system.PLATFORM_IS_APPLE and
399+ errno.errno == errno.EPROTOTYPE)):
400+ # From libuv code (unix/stream.c):
401+ # Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
402+ # EPROTOTYPE can be returned while trying to write to a socket
403+ # that is shutting down. If we retry the write, we should get
404+ # the expected EPIPE instead.
405+ written = system.write(fd, buf, blen)
396406 saved_errno = errno.errno
397407
398408 if used_buf:
@@ -675,6 +685,14 @@ cdef class UVStream(UVBaseTransport):
675685
676686 cpdef write(self , object buf):
677687 self ._ensure_alive()
688+
689+ if system.PLATFORM_IS_WINDOWS:
690+ # Winloop Comment: Winloop gets itself into trouble if this is
691+ # is not checked immediately, it's too costly to call the python function
692+ # bring in the flag instead to indicate closure.
693+ # SEE: https://github.com/Vizonex/Winloop/issues/84
694+ if self ._closing:
695+ raise RuntimeError (" Cannot call write() when UVStream is closing" )
678696
679697 if self ._eof:
680698 raise RuntimeError (' Cannot call write() after write_eof()' )
@@ -806,7 +824,14 @@ cdef inline bint __uv_stream_on_read_common(
806824 if sc.__read_error_close:
807825 # Used for getting notified when a pipe is closed.
808826 # See WriteUnixTransport for the explanation.
809- sc._on_eof()
827+ # Winloop comment: 0-reads on pipes used, e.g., for stdin
828+ # ("write only") give ERROR_ACCESS_DENIED, and in this case
829+ # we should keep the transport open for further writes.
830+ if (system.PLATFORM_IS_WINDOWS and nread == uv.UV_EPERM
831+ and uv.uv_is_writable(< uv.uv_stream_t* > sc._handle)):
832+ sc._stop_reading()
833+ else :
834+ sc._on_eof()
810835 return True
811836
812837 exc = convert_error(nread)
0 commit comments