Example #1
0
func (h *Heartbeat) request() {
	// close the session on any errors
	defer h.sess.Close()

	// request highest possible priority for heartbeats
	priority := frame.StreamPriority(0x7FFFFFFF)
	stream, err := h.sess.OpenStream(priority, heartbeatExtensionType, false)
	if err != nil {
		return
	}

	// send heartbeats and then check that we got them back
	var id uint32
	for {
		time.Sleep(h.interval)

		if err := binary.Write(stream, binary.BigEndian, id); err != nil {
			return
		}

		var respId uint32
		if err := binary.Read(stream, binary.BigEndian, &respId); err != nil {
			return
		}

		if id != respId {
			return
		}

		// record the time
		h.mark <- 1
	}
}
Example #2
0
func (a *sessionAdaptor) OpenStream(priority StreamPriority, streamType StreamType, fin bool) (Stream, error) {
	str, err := a.ISession.OpenStream(frame.StreamPriority(priority), frame.StreamType(streamType), fin)
	return &streamAdaptor{str}, err
}