Patch 8.1.0818
Problem:    MS-Windows: cannot send large data with ch_sendraw().
Solution:   Split write into several WriteFile() calls. (Yasuhiro Matsumoto,
            closes #3823)
Files:      src/channel.c, src/os_win32.c, src/testdir/test_channel.vim,
            src/testdir/test_channel_pipe.py, src/vim.h


*** ../vim-8.1.0817/src/channel.c       2019-01-22 23:01:36.943693467 +0100
--- src/channel.c       2019-01-24 23:04:15.428107841 +0100
***************
*** 80,103 ****
      static int
  fd_write(sock_T fd, char *buf, size_t len)
  {
      HANDLE    h = (HANDLE)fd;
!     DWORD     nwrite;
      OVERLAPPED        ov;
  
!     // If the pipe overflows while the job does not read the data, WriteFile
!     // will block forever. This abandons the write.
!     memset(&ov, 0, sizeof(ov));
!     if (!WriteFile(h, buf, (DWORD)len, &nwrite, &ov))
      {
!       DWORD err = GetLastError();
  
!       if (err != ERROR_IO_PENDING)
!           return -1;
!       if (!GetOverlappedResult(h, &ov, &nwrite, FALSE))
!           return -1;
!       FlushFileBuffers(h);
      }
!     return (int)nwrite;
  }
  
      static void
--- 80,113 ----
      static int
  fd_write(sock_T fd, char *buf, size_t len)
  {
+     size_t    todo = len;
      HANDLE    h = (HANDLE)fd;
!     DWORD     nwrite, size, done = 0;
      OVERLAPPED        ov;
  
!     while (todo > 0)
      {
!       if (todo > MAX_NAMED_PIPE_SIZE)
!           size = MAX_NAMED_PIPE_SIZE;
!       else
!           size = todo;
!       // If the pipe overflows while the job does not read the data, WriteFile
!       // will block forever. This abandons the write.
!       memset(&ov, 0, sizeof(ov));
!       if (!WriteFile(h, buf + done, size, &nwrite, &ov))
!       {
!           DWORD err = GetLastError();
  
!           if (err != ERROR_IO_PENDING)
!               return -1;
!           if (!GetOverlappedResult(h, &ov, &nwrite, FALSE))
!               return -1;
!           FlushFileBuffers(h);
!       }
!       todo -= nwrite;
!       done += nwrite;
      }
!     return (int)done;
  }
  
      static void
*** ../vim-8.1.0817/src/os_win32.c      2019-01-24 16:38:58.272712472 +0100
--- src/os_win32.c      2019-01-24 23:00:40.025605825 +0100
***************
*** 5369,5375 ****
            name,
            PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
            PIPE_TYPE_BYTE | PIPE_NOWAIT,
!           1, 65535, 0, 0, NULL);
  
      if (handles[1] == INVALID_HANDLE_VALUE)
        return FALSE;
--- 5369,5375 ----
            name,
            PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
            PIPE_TYPE_BYTE | PIPE_NOWAIT,
!           1, MAX_NAMED_PIPE_SIZE, 0, 0, NULL);
  
      if (handles[1] == INVALID_HANDLE_VALUE)
        return FALSE;
*** ../vim-8.1.0817/src/testdir/test_channel.vim        2019-01-23 
22:33:15.356020765 +0100
--- src/testdir/test_channel.vim        2019-01-24 23:00:40.025605825 +0100
***************
*** 1980,1982 ****
--- 1980,2000 ----
    unlet! g:val
    unlet! g:job
  endfunc
+ 
+ func Test_raw_large_data()
+   try
+     let g:out = ''
+     let job = job_start(s:python . " test_channel_pipe.py",
+         \ {'mode': 'raw', 'drop': 'never', 'noblock': 1,
+       \  'callback': {ch, msg -> execute('let g:out .= msg')}})
+ 
+     let want = repeat('X', 79999) . "\n"
+     call ch_sendraw(job, want)
+     let g:Ch_job = job
+     call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))})
+     call assert_equal(want, substitute(g:out, '\r', '', 'g'))
+   finally
+     call job_stop(job)
+     unlet g:out
+   endtry
+ endfunc
*** ../vim-8.1.0817/src/testdir/test_channel_pipe.py    2017-12-09 
18:22:43.000000000 +0100
--- src/testdir/test_channel_pipe.py    2019-01-24 23:00:40.025605825 +0100
***************
*** 56,59 ****
--- 56,63 ----
          if typed.startswith("doubleerr "):
              print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr)
              sys.stderr.flush()
+         if typed.startswith("XXX"):
+             print(typed, end='')
+             sys.stderr.flush()
+             break
  
*** ../vim-8.1.0817/src/vim.h   2019-01-24 18:20:14.436543394 +0100
--- src/vim.h   2019-01-24 23:00:40.025605825 +0100
***************
*** 2467,2472 ****
--- 2467,2476 ----
  # define MAX_OPEN_CHANNELS 0
  #endif
  
+ #if defined(WIN32)
+ # define MAX_NAMED_PIPE_SIZE 65535
+ #endif
+ 
  /* Options for json_encode() and json_decode. */
  #define JSON_JS               1   /* use JS instead of JSON */
  #define JSON_NO_NONE  2   /* v:none item not allowed */
*** ../vim-8.1.0817/src/version.c       2019-01-24 22:42:14.949304772 +0100
--- src/version.c       2019-01-24 23:01:11.165389246 +0100
***************
*** 789,790 ****
--- 789,792 ----
  {   /* Add new patch number below this line */
+ /**/
+     818,
  /**/

-- 
Not too long ago, a program was something you watched on TV...

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui