summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tmp/automap.go103
-rw-r--r--tmp/proto.go33
-rw-r--r--tmp/socket.go84
3 files changed, 0 insertions, 220 deletions
diff --git a/tmp/automap.go b/tmp/automap.go
deleted file mode 100644
index 187960c..0000000
--- a/tmp/automap.go
+++ /dev/null
@@ -1,103 +0,0 @@
-package server
-
-import (
- "strconv"
- "sort"
- "fmt"
- "io"
-)
-
-type autokey struct {
- flag bool
- n int
- v string
-}
-
-type automap map[string]interface{}
-
-type autokeys []autokey
-
-func (t autokey) String() string {
- return t.v
-}
-
-func (t autokeys) Len() int {
- return len(t)
-}
-
-func (t autokeys) Less(i, j int) bool {
- a := &t[i]
- b := &t[j]
-
- if a.flag && b.flag {
- return a.n < b.n
- }
-
- if !a.flag && !b.flag {
- return a.v < b.v
- }
-
- return b.flag
-}
-
-func (t autokeys) Swap(i, j int) {
- t[i], t[j] = t[j], t[i]
-}
-
-func (m automap) add(v interface{}) {
- for n := 1;; n++ {
- k := fmt.Sprint(n)
- if _, ok := m[k]; !ok {
- m[k] = v
- break
- }
- }
-}
-
-func (m automap) del(k string) bool {
- if _, ok := m[k]; !ok {
- return false
- }
-
- delete(m, k)
-
- return true
-}
-
-func (m automap) rename(old string, new string) bool {
- if _, ok := m[old]; !ok {
- return false
- }
-
- if _, ok := m[new]; ok {
- return false
- }
-
- m[new] = m[old]
-
- delete(m, old)
-
- return true
-}
-
-func (m automap) show(w io.Writer) {
- var keys autokeys
-
- for k, _ := range m {
- t := autokey{v: k}
-
- n, err := strconv.Atoi(k)
- if err == nil {
- t.flag = true
- t.n = n
- }
-
- keys = append(keys, t)
- }
-
- sort.Sort(keys)
-
- for _, k := range keys {
- fmt.Fprintln(w, k, m[k.v])
- }
-}
diff --git a/tmp/proto.go b/tmp/proto.go
deleted file mode 100644
index 104f1fa..0000000
--- a/tmp/proto.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package server
-
-type proto interface {
- Open() (proto, error)
- Close() error
- String() string
-}
-
-func protoShow(r *request) {
- r.c.s.proto.show(r.out)
-}
-
-func protoDel(r *request) {
- r.expect(1)
-
- if !r.c.s.proto.del(r.args[0]) {
- r.Fatal("no such proto")
- }
-}
-
-func protoRename(r *request) {
- r.expect(2)
-
- if !r.c.s.proto.rename(r.args[0], r.args[1]) {
- r.Fatal("rename failed")
- }
-}
-
-func init() {
- newCmd(protoDel, "proto", "del")
- newCmd(protoShow, "proto", "show")
- newCmd(protoRename, "proto", "rename")
-}
diff --git a/tmp/socket.go b/tmp/socket.go
deleted file mode 100644
index febd650..0000000
--- a/tmp/socket.go
+++ /dev/null
@@ -1,84 +0,0 @@
-package server
-
-import (
- "strconv"
- "fmt"
-)
-
-const MAXPORT = 1 << 16 - 1
-
-type tcpListen struct {
- addr string
-}
-
-type tcpOut struct {
- addr string
-}
-
-func (t *tcpListen) Open() (proto, error) {
- return nil, errNotImplemented
-}
-
-func (t *tcpListen) Close() error {
- return nil
-}
-
-func (t *tcpListen) String() string {
- return fmt.Sprintf("tcp <- %s", t.addr)
-}
-
-func (t *tcpOut) Open() (proto, error) {
- return nil, errNotImplemented
-}
-
-func (t *tcpOut) Close() error {
- return nil
-}
-
-func (t *tcpOut) String() string {
- return fmt.Sprintf("tcp -> %s", t.addr)
-}
-
-func parsePort(r *request, s string) int {
- port, err := strconv.Atoi(s)
- if err != nil {
- r.Fatalf("bad port value: %v", err)
- }
- if port <= 0 || port > MAXPORT {
- r.Fatal("bad port value")
- }
- return port
-}
-
-func addTcpListen(r *request) {
- r.expect(1, 2)
-
- var host string
- var n int
-
- if r.argc > 1 {
- host = r.args[n]
- n++
- }
-
- port := parsePort(r, r.args[n])
- t := &tcpListen{addr: fmt.Sprintf("%s:%d", host, port)}
-
- r.c.s.proto.add(t)
-}
-
-func addTcpOut(r *request) {
- r.expect(2)
-
- host := r.args[0]
- port := parsePort(r, r.args[1])
-
- t := &tcpOut{addr: fmt.Sprintf("%s:%d", host, port)}
-
- r.c.s.proto.add(t)
-}
-
-func init() {
- newCmd(addTcpListen, "add", "tcp", "listen")
- newCmd(addTcpOut, "add", "tcp", "out")
-}