mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
Revert "windows: support nil done parameter in ReadFile and WriteFile"
This reverts CL 559375. Reason for revert: introduced a different regression (golang/go#65378). Fixes golang/go#65378. Updates golang/go#65365. Change-Id: Ie2a602415913b04b9d9b65fee5c6a54c0267b35e Cq-Include-Trybots: luci.golang.try:x_sys-gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/sys/+/559502 Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
628365db92
commit
511ec846b6
@@ -1275,58 +1275,3 @@ uintptr_t beep(void) {
|
||||
t.Fatal("LoadLibraryEx unexpectedly found beep.dll")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadWriteFileOverlapped(t *testing.T) {
|
||||
name := filepath.Join(t.TempDir(), "test.txt")
|
||||
fd, err := windows.CreateFile(windows.StringToUTF16Ptr(name), windows.GENERIC_READ|windows.GENERIC_WRITE, 0, nil, windows.CREATE_NEW, windows.FILE_FLAG_OVERLAPPED, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer windows.CloseHandle(fd)
|
||||
|
||||
content := []byte("hello")
|
||||
// Test that we can write to a file using overlapped I/O.
|
||||
var ow windows.Overlapped
|
||||
ow.HEvent, err = windows.CreateEvent(nil, 0, 0, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer windows.CloseHandle(ow.HEvent)
|
||||
if err := windows.WriteFile(fd, content, nil, &ow); err != nil && err != windows.ERROR_IO_PENDING {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := windows.WaitForSingleObject(ow.HEvent, windows.INFINITE); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var n uint32
|
||||
if err := windows.GetOverlappedResult(fd, &ow, &n, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != uint32(len(content)) {
|
||||
t.Fatalf("got %d bytes written; want %d", n, len(content))
|
||||
}
|
||||
|
||||
// Test that we can read from a file using overlapped I/O.
|
||||
var or windows.Overlapped
|
||||
or.HEvent, err = windows.CreateEvent(nil, 0, 0, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer windows.CloseHandle(ow.HEvent)
|
||||
buf := make([]byte, len(content))
|
||||
if err := windows.ReadFile(fd, buf, nil, &or); err != nil && err != windows.ERROR_IO_PENDING {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := windows.WaitForSingleObject(or.HEvent, windows.INFINITE); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := windows.GetOverlappedResult(fd, &or, &n, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(buf) != string(content) {
|
||||
t.Fatalf("got %q; want %q", buf, content)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user