use embeded elements instead or private field for /dev/net/tun

this makes it possible to get *os.File by using type assertion over
ReadWriteCloser.

resolves #7
This commit is contained in:
Song Gao 2016-04-16 12:41:54 -05:00
parent 4a6164f5ed
commit 6a76f249f6
2 changed files with 5 additions and 19 deletions

20
if.go
View file

@ -1,14 +1,12 @@
package water
import (
"os"
)
import "io"
// Interface is a TUN/TAP interface.
type Interface struct {
isTAP bool
file *os.File
name string
io.ReadWriteCloser
name string
}
// Create a new TAP interface whose name is ifName.
@ -39,15 +37,3 @@ func (ifce *Interface) IsTAP() bool {
func (ifce *Interface) Name() string {
return ifce.name
}
// Implement io.Writer interface.
func (ifce *Interface) Write(p []byte) (n int, err error) {
n, err = ifce.file.Write(p)
return
}
// Implement io.Reader interface.
func (ifce *Interface) Read(p []byte) (n int, err error) {
n, err = ifce.file.Read(p)
return
}