5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-14 03:20:28 +00:00

Merge pull request #325 from Arceliar/alloc

Fix allocations found in profiling
This commit is contained in:
Arceliar 2019-02-05 17:51:58 -06:00 committed by GitHub
commit 16d754bbbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 15 deletions

View File

@ -51,12 +51,12 @@ ip netns exec node4 ip link set lo up
ip netns exec node5 ip link set lo up ip netns exec node5 ip link set lo up
ip netns exec node6 ip link set lo up ip netns exec node6 ip link set lo up
ip netns exec node1 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node1 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
ip netns exec node2 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node2 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
ip netns exec node3 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node3 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
ip netns exec node4 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node4 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
ip netns exec node5 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node5 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
ip netns exec node6 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & echo '{AdminListen: "none"}' | ip netns exec node6 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null &
echo "Started, to continue you should (possibly w/ sudo):" echo "Started, to continue you should (possibly w/ sudo):"
echo "kill" $(jobs -p) echo "kill" $(jobs -p)

View File

@ -388,7 +388,11 @@ func (a *admin) start() error {
// cleans up when stopping // cleans up when stopping
func (a *admin) close() error { func (a *admin) close() error {
if a.listener != nil {
return a.listener.Close() return a.listener.Close()
} else {
return nil
}
} }
// listen is run by start and manages API connections. // listen is run by start and manages API connections.

View File

@ -14,6 +14,8 @@ var _ = linkInterfaceMsgIO(&stream{})
type stream struct { type stream struct {
rwc io.ReadWriteCloser rwc io.ReadWriteCloser
inputBuffer []byte // Incoming packet stream inputBuffer []byte // Incoming packet stream
frag [2 * streamMsgSize]byte // Temporary data read off the underlying rwc, on its way to the inputBuffer
outputBuffer [2 * streamMsgSize]byte // Temporary data about to be written to the rwc
} }
func (s *stream) close() error { func (s *stream) close() error {
@ -32,10 +34,9 @@ func (s *stream) init(rwc io.ReadWriteCloser) {
// writeMsg writes a message with stream padding, and is *not* thread safe. // writeMsg writes a message with stream padding, and is *not* thread safe.
func (s *stream) writeMsg(bs []byte) (int, error) { func (s *stream) writeMsg(bs []byte) (int, error) {
buf := util.GetBytes() buf := s.outputBuffer[:0]
defer util.PutBytes(buf)
buf = append(buf, streamMsg[:]...) buf = append(buf, streamMsg[:]...)
buf = append(buf, wire_encode_uint64(uint64(len(bs)))...) buf = wire_put_uint64(uint64(len(bs)), buf)
padLen := len(buf) padLen := len(buf)
buf = append(buf, bs...) buf = append(buf, bs...)
var bn int var bn int
@ -69,10 +70,9 @@ func (s *stream) readMsg() ([]byte, error) {
return msg, nil return msg, nil
default: default:
// Wait for the underlying reader to return enough info for us to proceed // Wait for the underlying reader to return enough info for us to proceed
frag := make([]byte, 2*streamMsgSize) n, err := s.rwc.Read(s.frag[:])
n, err := s.rwc.Read(frag)
if n > 0 { if n > 0 {
s.inputBuffer = append(s.inputBuffer, frag[:n]...) s.inputBuffer = append(s.inputBuffer, s.frag[:n]...)
} else if err != nil { } else if err != nil {
return nil, err return nil, err
} }