Skip to content

Commit

Permalink
make unix socket implement SockAddr interface (#42)
Browse files Browse the repository at this point in the history
* make unix socket implement SockAddr interface

* typo

* impl CmpRFC to implement SockAddr interface
  • Loading branch information
swayne275 authored Mar 15, 2022
1 parent c7188e7 commit e364f8b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions unixsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func NewUnixSock(s string) (ret UnixSock, err error) {
return ret, nil
}

// Contains returns true if sa and us have the same path
func (us UnixSock) Contains(sa SockAddr) bool {
usb, ok := sa.(UnixSock)
if !ok {
return false
}

return usb.path == us.path
}

// CmpAddress follows the Cmp() standard protocol and returns:
//
// - -1 If the receiver should sort first because its name lexically sorts before arg
Expand All @@ -41,6 +51,9 @@ func (us UnixSock) CmpAddress(sa SockAddr) int {
return strings.Compare(us.Path(), usb.Path())
}

// CmpRFC doesn't make sense for a Unix socket, so just return defer decision
func (us UnixSock) CmpRFC(rfcNum uint, sa SockAddr) int { return sortDeferDecision }

// DialPacketArgs returns the arguments required to be passed to net.DialUnix()
// with the `unixgram` network type.
func (us UnixSock) DialPacketArgs() (network, dialArgs string) {
Expand Down

0 comments on commit e364f8b

Please sign in to comment.