Browse Source

Use wire.*LengthPrefixed

pull/1780/head
Jae Kwon 9 years ago
parent
commit
3393fc34c2
3 changed files with 10 additions and 9 deletions
  1. +4
    -4
      cmd/tmsp_cli/tmsp_cli.go
  2. +4
    -3
      example/golang/dummy_test.go
  3. +2
    -2
      server/server.go

cmd/tmsp/cli.go → cmd/tmsp_cli/tmsp_cli.go View File


+ 4
- 3
example/golang/dummy_test.go View File

@ -35,6 +35,7 @@ func TestStream(t *testing.T) {
var n int
var err error
var res types.Response
wire.ReadVarint(conn, &n, &err) // ignore
wire.ReadBinaryPtr(&res, conn, 0, &n, &err)
if err != nil {
Exit(err.Error())
@ -71,7 +72,7 @@ func TestStream(t *testing.T) {
var n int
var err error
var req types.Request = types.RequestAppendTx{TxBytes: []byte("test")}
wire.WriteBinary(req, conn, &n, &err)
wire.WriteBinaryLengthPrefixed(req, conn, &n, &err)
if err != nil {
t.Fatal(err.Error())
}
@ -79,7 +80,7 @@ func TestStream(t *testing.T) {
// Sometimes send flush messages
if counter%123 == 0 {
t.Log("flush")
wire.WriteBinary(types.RequestFlush{}, conn, &n, &err)
wire.WriteBinaryLengthPrefixed(types.RequestFlush{}, conn, &n, &err)
if err != nil {
t.Fatal(err.Error())
}
@ -88,7 +89,7 @@ func TestStream(t *testing.T) {
// Send final flush message
var n int
wire.WriteBinary(types.RequestFlush{}, conn, &n, &err)
wire.WriteBinaryLengthPrefixed(types.RequestFlush{}, conn, &n, &err)
if err != nil {
t.Fatal(err.Error())
}


+ 2
- 2
server/server.go View File

@ -85,7 +85,7 @@ func handleRequests(appC types.AppContext, closeConn chan error, conn net.Conn,
var n int
var err error
var req types.Request
wire.ReadBinaryPtr(&req, bufReader, 0, &n, &err)
wire.ReadBinaryPtrLengthPrefixed(&req, bufReader, 0, &n, &err)
if err != nil {
if err == io.EOF {
closeConn <- fmt.Errorf("Connection closed by client")
@ -146,7 +146,7 @@ func handleResponses(closeConn chan error, responses <-chan types.Response, conn
var res = <-responses
var n int
var err error
wire.WriteBinary(res, bufWriter, &n, &err)
wire.WriteBinaryLengthPrefixed(res, bufWriter, &n, &err)
if err != nil {
closeConn <- fmt.Errorf("Error in handleResponses: %v", err.Error())
return


Loading…
Cancel
Save