Skip to content

Commit

Permalink
Expose windows Fd
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxuncc committed Mar 22, 2019
1 parent f6122f5 commit 64b9c37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
water.test
.idea
14 changes: 9 additions & 5 deletions syscalls_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ func newOverlapped() (*syscall.Overlapped, error) {
return &overlapped, nil
}

type wfile struct {
type File struct {
fd syscall.Handle
rl sync.Mutex
wl sync.Mutex
ro *syscall.Overlapped
wo *syscall.Overlapped
}

func (f *wfile) Close() error {
func (f *File) Close() error {
return syscall.Close(f.fd)
}

func (f *wfile) Write(b []byte) (int, error) {
func (f *File) Write(b []byte) (int, error) {
f.wl.Lock()
defer f.wl.Unlock()

Expand All @@ -115,7 +115,7 @@ func (f *wfile) Write(b []byte) (int, error) {
return getOverlappedResult(f.fd, f.wo)
}

func (f *wfile) Read(b []byte) (int, error) {
func (f *File) Read(b []byte) (int, error) {
f.rl.Lock()
defer f.rl.Unlock()

Expand All @@ -130,6 +130,10 @@ func (f *wfile) Read(b []byte) (int, error) {
return getOverlappedResult(f.fd, f.ro)
}

func (f *File) Fd()syscall.Handle{
return f.fd
}

func ctl_code(device_type, function, method, access uint32) uint32 {
return (device_type << 16) | (access << 14) | (function << 2) | method
}
Expand Down Expand Up @@ -257,7 +261,7 @@ func openDev(config Config) (ifce *Interface, err error) {
if err != nil {
return
}
fd := &wfile{fd: file, ro: ro, wo: wo}
fd := &File{fd: file, ro: ro, wo: wo}
ifce = &Interface{isTAP: (config.DeviceType == TAP), ReadWriteCloser: fd}

// bring up device.
Expand Down

0 comments on commit 64b9c37

Please sign in to comment.