示例#1
0
func main() {
	runtime.LockOSThread()
	context, _ /*TODO*/ := zmq.NewContext()
	socket, _ /*TODO*/ := context.NewSocket(zmq.PUSH)
	socket.Bind("tcp://*:" + strconv.Itoa(*port))
	contextEOF, _ /*TODO*/ := zmq.NewContext()
	eof, _ /*TODO*/ := contextEOF.NewSocket(zmq.PUB)
	eof.Bind("tcp://*:" + strconv.Itoa(*portEOF))

	socket.SetSockOptInt(zmq.LINGER, 5000)
	eof.SetSockOptInt(zmq.LINGER, 5000)

	var partialLine []byte = nil

	bufStdin := bufio.NewReader(os.Stdin)

	line, isPrefix, err := bufStdin.ReadLine()
	for err == nil {
		if isPrefix || partialLine != nil {
			partialLine = append(partialLine, line...)
		}

		if !isPrefix {
			if partialLine != nil {
				socket.Send(partialLine, 0)
				partialLine = nil
			} else {
				socket.Send(line, 0)
			}
		}

		line, isPrefix, err = bufStdin.ReadLine()
	}
	socket.Close()
	context.Close()

	eof.Send([]byte("EOF"), 0)

	eof.Close()
	contextEOF.Close()
}
示例#2
0
func main() {
	context, _ /*TODO*/ = zmq.NewContext()

	finished := make(chan bool)
	rcvEOF := make(chan bool)

	go loopRcv(rcvEOF, finished)

	go testEOF(rcvEOF)

	<-finished
	context.Close()
}