aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-06-25 14:31:59 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-06-25 14:31:59 +0200
commit11da1413a60b062e21cf950ae714d70f78787b74 (patch)
treef3e9560718128f3d9f61c1d1fafad33fcd77cc6d /misc
parent3f4a00c3a4cc1c564dc4c55ae2c52cf9fda37ade (diff)
Split functions
Diffstat (limited to 'misc')
-rw-r--r--misc/main.go45
1 files changed, 31 insertions, 14 deletions
diff --git a/misc/main.go b/misc/main.go
index 213de64..dc3d783 100644
--- a/misc/main.go
+++ b/misc/main.go
@@ -127,28 +127,45 @@ func recv(c net.Conn) []byte {
return r
}
-func dump(b []byte, dir string) []byte {
+func dump(b []byte, dir string) {
log.Println(dir)
fmt.Println(hex.Dump(b))
- return b
+}
+
+func Associate(c net.Conn) {
+ dump(associate, ">>> Send associate")
+ send(c, associate)
+ in := recv(c)
+ dump(in, "<<< Recv associate")
+}
+
+func Release(c net.Conn) {
+ dump(release, ">>> Send release")
+ send(c, release)
+ in := recv(c)
+ dump(in, "<<< Recv release")
+}
+
+func Status(c net.Conn) {
+ in := recv(c)
+ dump(in, "<<< Recv status")
+ out := status
+ out[4] = in[4]
+ dump(out, ">>> Send status")
+ send(c, out)
}
func main() {
- c, err := net.Dial("tcp", *service)
+ conn, err := net.Dial("tcp", *service)
if err != nil {
log.Fatal(err)
}
- defer c.Close()
-
- send(c, dump(associate, ">>> Send associate"))
- dump(recv(c), "<<< Recv associate")
+ defer conn.Close()
- dump(recv(c), "<<< Recv status")
- send(c, dump(status, ">>> Send status"))
+ Associate(conn)
+ defer Release(conn)
- dump(recv(c), "<<< Recv status")
- send(c, dump(status, ">>> Send status"))
-
- send(c, dump(release, ">>> Send release"))
- dump(recv(c), "<<< Recv release")
+ for i := 0; i < 3; i++ {
+ Status(conn)
+ }
}