Skip to content

Commit

Permalink
Add support for disconnecting pipes
Browse files Browse the repository at this point in the history
Signed-off-by: David Golub <[email protected]>
  • Loading branch information
dgolub committed Jul 24, 2023
1 parent 4f41be6 commit 325fe99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

//sys connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) = ConnectNamedPipe
//sys createNamedPipe(name string, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) [failretval==syscall.InvalidHandle] = CreateNamedPipeW
//sys disconnectNamedPipe(pipe syscall.Handle) (err error) = DisconnectNamedPipe
//sys getNamedPipeInfo(pipe syscall.Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) = GetNamedPipeInfo
//sys getNamedPipeHandleState(pipe syscall.Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) = GetNamedPipeHandleStateW
//sys localAlloc(uFlags uint32, length uint32) (ptr uintptr) = LocalAlloc
Expand All @@ -30,6 +31,11 @@ import (
//sys rtlDosPathNameToNtPathName(name *uint16, ntName *unicodeString, filePart uintptr, reserved uintptr) (status ntStatus) = ntdll.RtlDosPathNameToNtPathName_U
//sys rtlDefaultNpAcl(dacl *uintptr) (status ntStatus) = ntdll.RtlDefaultNpAcl

type PipeConn interface {
net.Conn
Disconnect() error
}

type ioStatusBlock struct {
Status, Information uintptr
}
Expand Down Expand Up @@ -80,6 +86,8 @@ type win32Pipe struct {
path string
}

var _ PipeConn = (*win32Pipe)(nil)

type win32MessageBytePipe struct {
win32Pipe
writeClosed bool
Expand All @@ -103,6 +111,10 @@ func (f *win32Pipe) SetDeadline(t time.Time) error {
return f.SetWriteDeadline(t)
}

func (f *win32Pipe) Disconnect() error {
return disconnectNamedPipe(f.win32File.handle)
}

// CloseWrite closes the write side of a message pipe in byte mode.
func (f *win32MessageBytePipe) CloseWrite() error {
if f.writeClosed {
Expand Down
9 changes: 9 additions & 0 deletions zsyscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 325fe99

Please sign in to comment.