Example #1
0
func NewAcceptor(addr string, newAgent NewAgent) Stopper {
	listener, err := net.Listen("tcp", addr)
	ext.AssertE(err)
	a := &acceptor{Listener: listener, NewAgent: newAgent, stopper: NewStopper()}
	go ext.PCall(a.Run)
	return a
}
Example #2
0
func (c *console) Run() {
	defer c.Stopped()

	re := regexp.MustCompile(`[\w\:\.]+`)
	prompt := C.CString("god> ")
	defer C.free(unsafe.Pointer(prompt))

	var line string

	for !c.StopRequested() {
		cline := C.readline(prompt)
		defer C.free(unsafe.Pointer(cline))
		if cline == nil {
			fmt.Printf("\n")
			break
		}

		C.add_history(cline)
		line = C.GoString(cline)
		args := re.FindAllString(line, -1)
		if len(args) > 0 {
			f := c.funcs[args[0]]
			if f != nil {
				var ret interface{}
				ext.PCall(
					func() {
						ret = f(args[1:])
					})
				ext.LogInfo("RUN_COMMAND\t%s\t%s\t%v\n", args[0], args[1:], ret)
			}
		}
	}
}
Example #3
0
func NewNodeSender(conn net.Conn, encode Encode, compress Compress) MessageQueue {
	s := &nodeSender{Conn: conn, Encode: encode, Compress: compress, stopper: NewStopper(), MessageQueue: NewMessageQueue(32)}
	go ext.PCall(s.Run)
	return s
}
Example #4
0
func NewNodeReceiver(conn net.Conn, decode Decode, decompress Decompress) Stopper {
	r := &nodeReceiver{Conn: conn, Decode: decode, Decompress: decompress, stopper: NewStopper()}
	go ext.PCall(r.Run)
	return r
}
Example #5
0
func NewWorker(id PID, h Handler) Worker {
	w := &worker{PID: id, Handler: h, Stopper: NewStopper()}
	go ext.PCall(w.run)
	return w
}