You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.3 KiB

8 years ago
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "net"
  7. "reflect"
  8. "github.com/tendermint/tendermint/abci/types"
  9. cmn "github.com/tendermint/tendermint/libs/common"
  10. )
  11. func main() {
  12. conn, err := cmn.Connect("unix://test.sock")
  13. if err != nil {
  14. log.Fatal(err.Error())
  15. }
  16. // Make a bunch of requests
  17. counter := 0
  18. for i := 0; ; i++ {
  19. req := types.ToRequestEcho("foobar")
  20. _, err := makeRequest(conn, req)
  21. if err != nil {
  22. log.Fatal(err.Error())
  23. }
  24. counter++
  25. if counter%1000 == 0 {
  26. fmt.Println(counter)
  27. }
  28. }
  29. }
  30. func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
  31. var bufWriter = bufio.NewWriter(conn)
  32. // Write desired request
  33. err := types.WriteMessage(req, bufWriter)
  34. if err != nil {
  35. return nil, err
  36. }
  37. err = types.WriteMessage(types.ToRequestFlush(), bufWriter)
  38. if err != nil {
  39. return nil, err
  40. }
  41. err = bufWriter.Flush()
  42. if err != nil {
  43. return nil, err
  44. }
  45. // Read desired response
  46. var res = &types.Response{}
  47. err = types.ReadMessage(conn, res)
  48. if err != nil {
  49. return nil, err
  50. }
  51. var resFlush = &types.Response{}
  52. err = types.ReadMessage(conn, resFlush)
  53. if err != nil {
  54. return nil, err
  55. }
  56. if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
  57. return nil, fmt.Errorf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush))
  58. }
  59. return res, nil
  60. }