Example #1
0
/* int xs_recv (void *sck,void *buf,size_t len,int flags) */
func (sck *xsSocket) Recv(flags SocketOption) ([]byte, error, uint64) {

	var msg C.xs_msg_t
	r := C.xs_msg_init(&msg)
	if r != 0 {
		return nil, errno(), 0
	}

	defer C.xs_msg_close(&msg)

	r = C.xs_recvmsg(sck.sck, &msg, C.int(flags))
	if r == -1 {
		return nil, errno(), 0
	}
	size := C.xs_msg_size(&msg)
	var more uint64
	more_size := C.size_t(unsafe.Sizeof(more))
	C.xs_getmsgopt(&msg, C.XS_MORE, unsafe.Pointer(&more), &more_size)

	if size > 0 {
		data := make([]byte, int(size))
		C.memcpy(unsafe.Pointer(&data[0]), C.xs_msg_data(&msg), size)
		return data, nil, more
	}

	return nil, nil, more /* nothing to recv */
}
Example #2
0
func (msg *xsMessage) Size() int {

	return int(C.xs_msg_size(&msg.msg))
}