zhangmeng
2019-05-20 26f699593d76d6fa4bcf320c84fd723343c4b5f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
 
import (
    "context"
    "demo/deliver"
    "flag"
    "fmt"
    "os"
)
 
const dLen = 12 * 1024 * 1024
 
var ctx, cancel = context.WithCancel(context.Background())
 
func senderMode(ipc string, m deliver.Mode, count int, one bool) {
    if m == deliver.ReqRep {
        req(ipc, m)
    } else if m == deliver.Shm {
        shmSender(ipc, 2, 32*1024*1024)
    }
 
    if one {
        oneSender(ipc, m)
    } else {
        nSender(ipc, m, count)
    }
}
 
func recvMode(ipc string, m deliver.Mode, count int, n bool) {
    if m == deliver.ReqRep {
        rep(ipc, m)
    } else if m == deliver.Shm {
        shmReciever(ipc, count)
    }
 
    if n {
        nReciever(ipc, m, count)
    } else {
        oneReciever(ipc, m)
    }
}
 
var (
    proc         string
    procCount    int
    mode         string
    ipc          string
    oneSendnRecv bool
)
 
const (
    act  = "act"
    pass = "pass"
)
 
func init() {
    flag.StringVar(&proc, "p", "act", "proc as sender")
    flag.IntVar(&procCount, "c", 1, "proc run count")
 
    flag.StringVar(&mode, "m", "pushpull", "proc run mode pushpull or pubsub etc.")
 
    flag.StringVar(&ipc, "i", "ipc:///tmp/pic.ipc", "ipc label")
 
    flag.BoolVar(&oneSendnRecv, "n", true, "one send n recv")
}
 
func modeType(t string) deliver.Mode {
 
    if t == "pushpull" {
        return deliver.PushPull
    } else if t == "pubsub" {
        return deliver.PubSub
    } else if t == "pair" {
        return deliver.Pair
    } else if t == "reqrep" {
        return deliver.ReqRep
    } else if t == "shm" {
        return deliver.Shm
    }
 
    return deliver.NONE
}
 
func main() {
    flag.Parse()
 
    m := modeType(mode)
    if m > deliver.ModeStart {
        if proc == act {
            senderMode(ipc, m, procCount, oneSendnRecv)
        } else {
            recvMode(ipc, m, procCount, oneSendnRecv)
        }
    }
 
    fmt.Fprintf(os.Stderr,
        "Usage: pushpull push|pull <URL> <ARG> ...\n")
    os.Exit(1)
 
}