Пример #1
0
// TODO: Documentation
func (sc *ServerClient) Send(p *packet.Packet, ensure bool) {
	if ensure {
		p.EnsureArrival = sc.server.ensureID()
	} else {
		p.EnsureArrival = nil
	}
	b, err := proto.Marshal(p)
	if err != nil {
		log.Println("Error encoding packet to", sc.addr, "-", err)
	} else {
		sc.server.Send(sc.addr, b, p.GetEnsureArrival())
	}
}
Пример #2
0
// TODO: Documentation
func (c *Client) Write(p *packet.Packet, ensure bool) error {
	if ensure {
		c.lock.Lock()
		c.lastEnsure++
		p.EnsureArrival = proto.Uint64(c.lastEnsure)
		c.lock.Unlock()
	} else {
		p.EnsureArrival = nil
	}

	b, err := proto.Marshal(p)
	if err != nil {
		return err
	}

	if ensure {
		c.lock.Lock()
		c.ensured[p.GetEnsureArrival()] = &clientEnsure{b, time.Now(), MaxRetries}
		c.lock.Unlock()
	}

	_, err = c.conn.Write(b)
	return err
}