-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package watermob | ||
|
||
type Protector interface { | ||
Protect(fd int) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package watermob | ||
|
||
import ( | ||
"net" | ||
"time" | ||
) | ||
|
||
// This file contains the explicitly defined types for the watermob package that | ||
// maps to standard library types. This is done to allow for easy swapping of | ||
|
||
// net.Addr | ||
type NetAddr interface { | ||
Network() string | ||
String() string | ||
} | ||
|
||
// net.Conn | ||
type NetConn interface { | ||
Read(b []byte) (n int, err error) | ||
Write(b []byte) (n int, err error) | ||
Close() error | ||
LocalAddr() NetAddr | ||
RemoteAddr() NetAddr | ||
SetDeadline(t time.Time) error | ||
SetReadDeadline(t time.Time) error | ||
SetWriteDeadline(t time.Time) error | ||
} | ||
|
||
type netConn struct { | ||
embeddedConn net.Conn | ||
} | ||
|
||
func (c *netConn) Read(b []byte) (n int, err error) { | ||
return c.embeddedConn.Read(b) | ||
} | ||
|
||
func (c *netConn) Write(b []byte) (n int, err error) { | ||
return c.embeddedConn.Write(b) | ||
} | ||
|
||
func (c *netConn) Close() error { | ||
return c.embeddedConn.Close() | ||
} | ||
|
||
func (c *netConn) LocalAddr() NetAddr { | ||
return c.embeddedConn.LocalAddr() | ||
} | ||
|
||
func (c *netConn) RemoteAddr() NetAddr { | ||
return c.embeddedConn.RemoteAddr() | ||
} | ||
|
||
func (c *netConn) SetDeadline(t time.Time) error { | ||
return c.embeddedConn.SetDeadline(t) | ||
} | ||
|
||
func (c *netConn) SetReadDeadline(t time.Time) error { | ||
return c.embeddedConn.SetReadDeadline(t) | ||
} | ||
|
||
func (c *netConn) SetWriteDeadline(t time.Time) error { | ||
return c.embeddedConn.SetWriteDeadline(t) | ||
} | ||
|
||
func NewNetConn(c net.Conn) NetConn { | ||
return &netConn{c} | ||
} |