Skip to content

Commit

Permalink
Read /proc/net files with a single read syscall.
Browse files Browse the repository at this point in the history
As per shirou#361
  • Loading branch information
apoorv007 committed Jun 24, 2017
1 parent 82608f2 commit 53b6dfd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions net/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package net

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -610,14 +611,18 @@ func processInet(file string, kind netConnectionKindType, inodes map[string][]in
// IPv6 not supported, return empty.
return []connTmp{}, nil
}
lines, err := common.ReadLines(file)

contents, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}

lines := bytes.Split(contents, []byte("\n"))

var ret []connTmp
// skip first line
for _, line := range lines[1:] {
l := strings.Fields(line)
l := strings.Fields(string(line))
if len(l) < 10 {
continue
}
Expand Down Expand Up @@ -664,15 +669,17 @@ func processInet(file string, kind netConnectionKindType, inodes map[string][]in
}

func processUnix(file string, kind netConnectionKindType, inodes map[string][]inodeMap, filterPid int32) ([]connTmp, error) {
lines, err := common.ReadLines(file)
contents, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}

lines := bytes.Split(contents, []byte("\n"))

var ret []connTmp
// skip first line
for _, line := range lines[1:] {
tokens := strings.Fields(line)
tokens := strings.Fields(string(line))
if len(tokens) < 6 {
continue
}
Expand Down

0 comments on commit 53b6dfd

Please sign in to comment.