示例#1
0
func from_packet(c_packet *C.ENetPacket) []byte {
	log.Printf("from packet: %#v", c_packet)
	if c_packet == nil {
		return nil
	}
	defer C.enet_packet_destroy(c_packet)
	return C.GoBytes(unsafe.Pointer(c_packet.data), C.int(c_packet.dataLength))
}
示例#2
0
文件: peer.go 项目: deft-code/go-enet
// enet_peer_send
func (peer *Peer) Send(channelID uint8, data []byte, flags Flag) error {
	c_packet := new_packet(data, flags)
	defer C.enet_packet_destroy(c_packet)

	ret := C.enet_peer_send(peer.peer, C.enet_uint8(channelID), c_packet)
	if ret < 0 {
		return errors.New("ENet failed to send packet")
	}
	return nil
}
示例#3
0
文件: event.go 项目: hycxa/waiter
func eventFromCEvent(cEventI interface{}) Event {
	cEvent := cEventI.(*C.ENetEvent)
	defer C.enet_packet_destroy(cEvent.packet)

	return Event{
		Type:      EventType(cEvent._type),
		Peer:      peerFromCPeer(cEvent.peer),
		ChannelId: uint8(cEvent.channelID),
		Data:      uint32(cEvent.data),
		Packet:    packetFromCPacket(cEvent.packet),
	}
}
示例#4
0
文件: packet.go 项目: boj/goenet
func (p *ENetPacket) Destroy() {
	C.enet_packet_destroy((*C.ENetPacket)(p))
}