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


Golang C.zmq_msg_size函数代码示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: MessageSize

func MessageSize(message ZMessage) int {
	return int(C.zmq_msg_size(message.Ptr))
}
开发者ID:badgerodon,项目名称:zmq,代码行数:3,代码来源:zmq.go

示例7: Size

func (p *lzmqMessage) Size() int {
	// size_t always fits int, we do not allocate larger messages
	return int(C.zmq_msg_size(p.ptr()))
}
开发者ID:miffa,项目名称:gozero,代码行数:4,代码来源:zmq.go


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