Ejemplo n.º 1
0
/*
Receive a message part from a socket interpreted as an event.

For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2

For a description of event_type, see: http://api.zeromq.org/3-2:zmq-socket-monitor#toc2

For an example, see: func (*Socket) Monitor
*/
func (soc *Socket) RecvEvent(flags Flag) (event_type Event, addr string, value int, err error) {
	var msg C.zmq_msg_t
	if i, e := C.zmq_msg_init(&msg); i != 0 {
		err = errget(e)
		return
	}
	defer C.zmq_msg_close(&msg)

	size, e := C.zmq_msg_recv(&msg, soc.soc, C.int(flags))
	if size < 0 {
		err = errget(e)
		return
	}

	var t C.zmq_event_t
	if size < C.int(unsafe.Sizeof(t)) {
		err = errors.New("Not an event")
		return
	}

	et := C.int(0)
	val := C.int(0)
	addrs := C.get_event(&msg, &et, &val)
	defer C.free(unsafe.Pointer(addrs))

	event_type = Event(et)
	addr = C.GoString(addrs)
	value = int(val)

	return
}
Ejemplo n.º 2
0
Archivo: zmq4.go Proyecto: rayqiu/zmq4
/*
Receive a message part from a socket interpreted as an event.

For a description of flags, see: http://api.zeromq.org/4-0:zmq-msg-recv#toc2

For a description of event_type, see: http://api.zeromq.org/4-0:zmq-socket-monitor#toc3

For an example, see: func (*Socket) Monitor
*/
func (soc *Socket) RecvEvent(flags Flag) (event_type Event, addr string, value int, err error) {
	var msg C.zmq_msg_t
	if i, e := C.zmq_msg_init(&msg); i != 0 {
		err = errget(e)
		return
	}
	defer C.zmq_msg_close(&msg)
	size, e := C.zmq_msg_recv(&msg, soc.soc, C.int(flags))
	if size < 0 {
		err = errget(e)
		return
	}
	et := C.int(0)
	val := C.int(0)

	C.get_event(&msg, &et, &val)

	more, e := soc.GetRcvmore()
	if e != nil {
		err = errget(e)
		return
	}
	if !more {
		err = errors.New("More expected")
		return
	}
	addr, e = soc.Recv(flags)
	if e != nil {
		err = errget(e)
		return
	}

	event_type = Event(et)
	value = int(val)

	return
}