当前位置: 首页>>代码示例>>Golang>>正文


Golang C.zmq_msg_close函数代码示例

本文整理汇总了Golang中C.zmq_msg_close函数的典型用法代码示例。如果您正苦于以下问题:Golang zmq_msg_close函数的具体用法?Golang zmq_msg_close怎么用?Golang zmq_msg_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zmq_msg_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RecvBytes

/*
Receive a message part from a socket.

For a description of flags, see: http://api.zeromq.org/2-2:zmq-recv#toc2
*/
func (soc *Socket) RecvBytes(flags Flag) ([]byte, error) {
	if !soc.opened {
		return []byte{}, ErrorSocketClosed
	}
	var msg C.zmq_msg_t
	if i, err := C.zmq_msg_init(&msg); i != 0 {
		return []byte{}, errget(err)
	}
	defer C.zmq_msg_close(&msg)

	var size C.int
	var err error

	var i C.int
	i, err = C.zmq_recv(soc.soc, &msg, C.int(flags))
	if i == 0 {
		size = C.int(C.zmq_msg_size(&msg))
	} else {
		size = -1
	}

	if size < 0 {
		return []byte{}, errget(err)
	}
	if size == 0 {
		return []byte{}, nil
	}
	data := make([]byte, int(size))
	C.my_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size))
	return data, nil
}
开发者ID:carosio,项目名称:chello,代码行数:36,代码来源:zmq2.go

示例2: RecvBytesWithMetadata

/*
Receive a message part with metadata.

This requires ZeroMQ version 4.1.0. Lower versions will return the message part without metadata.

The returned metadata map contains only those properties that exist on the message.

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

For a description of metadata, see: http://api.zeromq.org/4-1:zmq-msg-gets#toc3
*/
func (soc *Socket) RecvBytesWithMetadata(flags Flag, properties ...string) (msg []byte, metadata map[string]string, err error) {
	if !soc.opened {
		return []byte{}, map[string]string{}, ErrorSocketClosed
	}

	metadata = make(map[string]string)

	var m C.zmq_msg_t
	if i, err := C.zmq_msg_init(&m); i != 0 {
		return []byte{}, metadata, errget(err)
	}
	defer C.zmq_msg_close(&m)

	size, err := C.zmq_msg_recv(&m, soc.soc, C.int(flags))
	if size < 0 {
		return []byte{}, metadata, errget(err)
	}

	data := make([]byte, int(size))
	if size > 0 {
		C.zmq4_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), C.size_t(size))
	}

	if minor > 0 {
		for _, p := range properties {
			ps := C.CString(p)
			s, err := C.zmq_msg_gets(&m, ps)
			if err == nil {
				metadata[p] = C.GoString(s)
			}
			C.free(unsafe.Pointer(ps))
		}
	}
	return data, metadata, nil
}
开发者ID:gallir,项目名称:zmq4,代码行数:46,代码来源:zmq4.go

示例3: RecvEvent

/*
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
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:40,代码来源:zmq3.go

示例4: Recv

// Receive a message from the socket.
// int zmq_recv (void *s, zmq_msg_t *msg, int flags);
func (s *zmqSocket) Recv(flags SendRecvOption) (data []byte, err error) {
	// Allocate and initialise a new zmq_msg_t
	err = nil
	var m C.zmq_msg_t
	if C.zmq_msg_init(&m) != 0 {
		println("init")
		err = errno()
		return
	}
	defer C.zmq_msg_close(&m)
	// Receive into message
	if C.zmq_recvmsg(s.s, &m, C.int(flags)) != 0 {
		println("recvmsg")
		err = errno()
		return
	}
	// Copy message data into a byte array
	// FIXME Ideally this wouldn't require a copy.
	size := C.zmq_msg_size(&m)
	if size > 0 {
		data = make([]byte, int(size))
		C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
	} else {
		data = nil
	}
	return
}
开发者ID:mgranberry,项目名称:gozmq,代码行数:29,代码来源:zmq.go

示例5: Recv

// Receive a message from the socket.
// int zmq_recv (void *s, zmq_msg_t *msg, int flags);
func (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {
	// Allocate and initialise a new zmq_msg_t
	var m C.zmq_msg_t
	var rc C.int
	if rc, err = C.zmq_msg_init(&m); rc != 0 {
		err = casterr(err)
		return
	}
	defer C.zmq_msg_close(&m)
	// Receive into message
	if rc, err = C.zmq_recvmsg(s.s, &m, C.int(flags)); rc == -1 {
		err = casterr(err)
		return
	}
	err = nil
	// Copy message data into a byte array
	// FIXME Ideally this wouldn't require a copy.
	size := C.zmq_msg_size(&m)
	if size > 0 {
		data = make([]byte, int(size))
		C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
	} else {
		data = nil
	}
	return
}
开发者ID:somia,项目名称:gozmq,代码行数:28,代码来源:zmq_3_x.go

示例6: RecvEvent

func (s *Socket) RecvEvent(flags SendRecvOption) (ty Event, addr string, ex int64, err error) {
	// Allocate and initialise a new zmq_msg_t
	var m C.zmq_msg_t
	var rc C.int
	if rc, err = C.zmq_msg_init(&m); rc != 0 {
		err = casterr(err)
		return
	}
	defer C.zmq_msg_close(&m)
	// Receive into message
	if rc, err = C.zmq_recvmsg(s.s, &m, C.int(flags)); rc == -1 {
		err = casterr(err)
		return
	}
	var ev *C.zmq_event_t
	size := C.zmq_msg_size(&m)
	if uintptr(size) != unsafe.Sizeof(*ev) {
		err = errors.New("Invalid event message received")
		return
	}
	err = nil

	ev = (*C.zmq_event_t)(C.zmq_msg_data(&m))
	ty = Event(ev.event)
	addr = C.GoString(C.ev_get_addr(ev))
	ex = int64(C.ev_get_extra(ev))
	return
}
开发者ID:unkstar,项目名称:gozmq,代码行数:28,代码来源:zmq_3_x_hack.go

示例7: SendBytes

/*
Send a message part on a socket.

For a description of flags, see: http://api.zeromq.org/2-2:zmq-send#toc2
*/
func (soc *Socket) SendBytes(data []byte, flags Flag) (int, error) {
	datac := C.CString(string(data))
	var msg C.zmq_msg_t
	if i, err := C.my_msg_init_data(&msg, unsafe.Pointer(datac), C.size_t(len(data))); i != 0 {
		return -1, errget(err)
	}
	defer C.zmq_msg_close(&msg)
	n, err := C.zmq_send(soc.soc, &msg, C.int(flags))
	if n != 0 {
		return -1, errget(err)
	}
	return int(n), nil
}
开发者ID:patrickToca,项目名称:zmq2,代码行数:18,代码来源:zmq2.go

示例8: RecvBytes

/*
Receive a message part from a socket.

For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2
*/
func (soc *Socket) RecvBytes(flags Flag) ([]byte, error) {
	var msg C.zmq_msg_t
	if i, err := C.zmq_msg_init(&msg); i != 0 {
		return []byte{}, errget(err)
	}
	defer C.zmq_msg_close(&msg)

	size, err := C.zmq_msg_recv(&msg, soc.soc, C.int(flags))
	if size < 0 {
		return []byte{}, errget(err)
	}
	if size == 0 {
		return []byte{}, nil
	}
	data := make([]byte, int(size))
	C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size))
	return data, nil
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:23,代码来源:zmq3.go

示例9: RecvEvent

/*
Receive a message part from a socket interpreted as an event.

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

For a description of event_type, see: http://api.zeromq.org/4-1: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) {
	if !soc.opened {
		return EVENT_ALL, "", 0, ErrorSocketClosed
	}
	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)

	if minor == 0 {
		C.zmq4_get_event40(&msg, &et, &val)
	} else {
		C.zmq4_get_event41(&msg, &et, &val)
	}
	more, e := soc.GetRcvmore()
	if e != nil {
		err = errget(e)
		return
	}
	if !more {
		err = ErrorMoreExpected
		return
	}
	addr, e = soc.Recv(flags)
	if e != nil {
		err = errget(e)
		return
	}

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

	return
}
开发者ID:gallir,项目名称:zmq4,代码行数:52,代码来源:zmq4.go

示例10: SendPart

// Sends a single message part. The `more` flag is used to specify whether this is the last part of the message (false),
// or if there are more parts to follow (true). SendPart is fairly low-level, and usually Send will be the preferred
// method to use.
func (s *Socket) SendPart(part []byte, more bool) (err error) {
	for {
		err = nil
		var msg C.zmq_msg_t
		toMsg(&msg, part)
		flags := C.int(0)
		if more {
			flags = C.ZMQ_SNDMORE
		}
		r := C.zmq_msg_send(&msg, s.sock, flags)
		if r == -1 {
			err = zmqerr()
		}
		C.zmq_msg_close(&msg)
		if err != ErrInterrupted {
			break
		}
	}
	return
}
开发者ID:pakohan,项目名称:go-zmq,代码行数:23,代码来源:zmq.go

示例11: RecvEvent

/*
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)

	if _, minor, _ := Version(); minor == 0 {
		C.get_event40(&msg, &et, &val)
	} else {
		C.get_event41(&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
}
开发者ID:JeremyOT,项目名称:zmq4,代码行数:50,代码来源:zmq4.go

示例12: Send

// Send a message to the socket.
// int zmq_send (void *s, zmq_msg_t *msg, int flags);
func (s *zmqSocket) Send(data []byte, flags SendRecvOption) error {
	var m C.zmq_msg_t
	// Copy data array into C-allocated buffer.
	size := C.size_t(len(data))

	if C.zmq_msg_init_size(&m, size) != 0 {
		return errno()
	}

	if size > 0 {
		// FIXME Ideally this wouldn't require a copy.
		C.memcpy(unsafe.Pointer(C.zmq_msg_data(&m)), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
	}

	if C.zmq_sendmsg(s.s, &m, C.int(flags)) != 0 {
		// zmq_send did not take ownership, free message
		C.zmq_msg_close(&m)
		return errno()
	}
	return nil
}
开发者ID:aaudis,项目名称:gozmq,代码行数:23,代码来源:zmq.go

示例13: RecvPart

// Receives a single part along with a boolean flag (more) indicating whether more parts of the same message follow
// (true), or this is the last part of the message (false). As with Send/SendPart, this is fairly low-level and Recv
// should generally be used instead.
func (s *Socket) RecvPart() (part []byte, more bool, err error) {
	var msg C.zmq_msg_t
	C.zmq_msg_init(&msg)
	for {
		err = nil
		r := C.zmq_msg_recv(&msg, s.sock, 0)
		if r == -1 {
			err = zmqerr()
		}
		if err != ErrInterrupted {
			break
		}
	}
	if err != nil {
		C.zmq_msg_close(&msg)
		return
	}
	part = fromMsg(&msg)
	// Check for more parts
	more = (s.getInt(C.ZMQ_RCVMORE) != 0)
	return
}
开发者ID:pakohan,项目名称:go-zmq,代码行数:25,代码来源:zmq.go

示例14: fromMsg

func fromMsg(msg *C.zmq_msg_t) []byte {
	defer C.zmq_msg_close(msg)
	return C.GoBytes(C.zmq_msg_data(msg), C.int(C.zmq_msg_size(msg)))
}
开发者ID:pakohan,项目名称:go-zmq,代码行数:4,代码来源:zmq.go

示例15: MessageClose

func MessageClose(message ZMessage) os.Error {
	return handle(C.zmq_msg_close(message.Ptr))
}
开发者ID:badgerodon,项目名称:zmq,代码行数:3,代码来源:zmq.go


注:本文中的C.zmq_msg_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。