mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Add fixes for :write on filestreams that come from os/open
This commit is contained in:
		| @@ -1838,6 +1838,16 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event) | ||||
|             } else | ||||
| #endif | ||||
|             { | ||||
|                 // File handles in IOCP need to specify this if they are writing to the  | ||||
|                 // ends of files, like how this is used here. | ||||
|                 // If the underlying resource doesn't support seeking | ||||
|                 // byte offsets, they will be ignored | ||||
|                 // but this otherwise writes to the end of the file in question | ||||
|                 // Right now, os/open streams aren't seekable, so this works. | ||||
|                 // for more details see the lpOverlapped parameter in | ||||
|                 // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile | ||||
|                 state->overlapped.Offset = (DWORD) 0xFFFFFFFF; | ||||
|                 state->overlapped.OffsetHigh = (DWORD) 0xFFFFFFFF; | ||||
|                 status = WriteFile(s->stream->handle, bytes, len, NULL, &state->overlapped); | ||||
|                 if (!status && (ERROR_IO_PENDING != WSAGetLastError())) { | ||||
|                     janet_cancel(s->fiber, janet_ev_lasterr()); | ||||
|   | ||||
| @@ -105,6 +105,18 @@ | ||||
|   (file/close outfile) | ||||
|   (os/rm "unique.txt")) | ||||
|  | ||||
| # Ensure that the stream created by os/open works | ||||
|  | ||||
| (assert-no-error "File writing 4.1" | ||||
|    (def outstream (os/open "unique.txt" :wct)) | ||||
|    (defer (:close outstream) | ||||
|      (:write outstream "123\n") | ||||
|      (:write outstream "456\n")) | ||||
|    # Cast to string to enable comparison | ||||
|    (assert (= "123\n456\n" (string (slurp "unique.txt"))) "File writing 4.2") | ||||
|    (os/rm "unique.txt")) | ||||
|       | ||||
|  | ||||
| # ev/gather | ||||
|  | ||||
| (assert (deep= @[1 2 3] (ev/gather 1 2 3)) "ev/gather 1") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Andrew Owen
					Andrew Owen