本文整理匯總了Golang中C.zmq_msg_init_size函數的典型用法代碼示例。如果您正苦於以下問題:Golang zmq_msg_init_size函數的具體用法?Golang zmq_msg_init_size怎麽用?Golang zmq_msg_init_size使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了zmq_msg_init_size函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: MessageInitSize
func MessageInitSize(message ZMessage, size int) os.Error {
return handle(C.zmq_msg_init_size(message.Ptr, C.size_t(size)))
}
示例3: toMsg
func toMsg(msg *C.zmq_msg_t, data []byte) {
C.zmq_msg_init_size(msg, C.size_t(len(data)))
if len(data) > 0 {
C.memcpy(C.zmq_msg_data(msg), unsafe.Pointer(&data[0]), C.size_t(len(data)))
}
}
示例4: allocate
func (p *lzmqMessage) allocate(length int) os.Error {
return p.Provider().OkIf(C.zmq_msg_init_size(p.ptr(), C.size_t(length)) == 0)
}