Skip to content

Commit

Permalink
change NewNetUnixByPath to NewNetUnixByReader for unix domain parser
Browse files Browse the repository at this point in the history
Signed-off-by: madk <[email protected]>
  • Loading branch information
peonone committed May 25, 2019
1 parent ea4aa43 commit 4d4a0fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion net_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bufio"
"errors"
"fmt"
"io"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -103,10 +104,16 @@ func NewNetUnixByPath(path string) (*NetUnix, error) {
return nil, err
}
defer f.Close()
return NewNetUnixByReader(f)
}

// NewNetUnixByReader returns data read from /proc/net/unix by a reader.
// It might returns an error with partial parsed data, if an error occur after some data parsed.
func NewNetUnixByReader(reader io.Reader) (*NetUnix, error) {
nu := &NetUnix{
Rows: make([]*NetUnixLine, 0, 32),
}
scanner := bufio.NewScanner(f)
scanner := bufio.NewScanner(reader)
// Omit the header line.
scanner.Scan()
header := scanner.Text()
Expand Down
2 changes: 1 addition & 1 deletion net_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package procfs

import (
"os"
"testing"
)

Expand Down Expand Up @@ -118,7 +119,6 @@ func TestNewNetUnixWithoutInode(t *testing.T) {
t.Fatal(err)
}
nu, err := NewNetUnixByPath(fs.proc.Path("net/unix_without_inode"))

if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 4d4a0fb

Please sign in to comment.