summaryrefslogtreecommitdiffhomepage
path: root/server/fsm.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-12 16:43:50 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-12 17:24:01 +0900
commit43e65c0a13e07e37dcdaa287b858cdd539c55d60 (patch)
tree502f51fe84c4b33f4b8d499f6eb6f4f6ee0873cc /server/fsm.go
parent2ee83547979eebffd9ed1b3e7530958216d1f85d (diff)
fsm: fix homemade readAll()
Fix a received data corruption bug when a partial read happens. Let's use io.ReadFull() rather than the homemade one. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/fsm.go')
-rw-r--r--server/fsm.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 6b033060..42f2005a 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -21,6 +21,7 @@ import (
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"gopkg.in/tomb.v2"
+ "io"
"net"
"time"
)
@@ -327,12 +328,9 @@ func buildopen(global *config.Global, peerConf *config.Neighbor) *bgp.BGPMessage
func readAll(conn net.Conn, length int) ([]byte, error) {
buf := make([]byte, length)
- for cur := 0; cur < length; {
- if num, err := conn.Read(buf); err != nil {
- return nil, err
- } else {
- cur += num
- }
+ _, err := io.ReadFull(conn, buf)
+ if err != nil {
+ return nil, err
}
return buf, nil
}