Exemple #1
0
func (m *MockExchange) deliverPacket(pkt *lob.Packet, dst *Pipe) error {
	pkt.TID = 0
	args := m.Called(pkt)
	return args.Error(0)
}
Exemple #2
0
func (c *Channel) write(pkt *lob.Packet, p *Pipe) error {
	if pkt.TID == 0 {
		pkt.TID = tracer.NewID()
	}

	if c.broken {
		// When a channel is marked as broken the all writes
		// must return a BrokenChannelError.
		return c.traceWriteError(pkt, p,
			&BrokenChannelError{c.hashname, c.typ, c.id})
	}

	if c.writeDeadlineReached {
		// When a channel reached a write deadline then all writes
		// must return a ErrTimeout.
		return c.traceWriteError(pkt, p,
			ErrTimeout)
	}

	if c.deliveredEnd {
		// When a channel sent a packet with the "end" header set
		// then all subsequent writes must return io.EOF
		return c.traceWriteError(pkt, p,
			io.EOF)
	}

	c.oSeq++
	hdr := pkt.Header()
	hdr.C, hdr.HasC = c.id, true
	if c.reliable {
		hdr.Seq, hdr.HasSeq = c.oSeq, true
	}
	if !c.serverside && c.oSeq == cInitialSeq {
		hdr.Type, hdr.HasType = c.typ, true
	}

	end := hdr.HasEnd && hdr.End
	if end {
		c.deliveredEnd = true
		c.setCloseDeadline()
	}

	if c.reliable {
		if c.oSeq%30 == 0 || hdr.End {
			c.applyAckHeaders(pkt)
		}
		c.writeBuffer[c.oSeq] = &writeBufferEntry{pkt, end, time.Time{}, p}
		c.needsResend = false
	}

	err := c.x.deliverPacket(pkt, p)
	if err != nil {
		return c.traceWriteError(pkt, p, err)
	}
	statChannelSndPkt.Add(1)
	if pkt.Header().HasAck {
		statChannelSndAckInline.Add(1)
	}

	if c.oSeq == cInitialSeq && c.serverside {
		c.unsetOpenDeadline()
	}

	c.traceWrite(pkt, p)

	if !c.reliable {
		pkt.Free()
	}

	return nil
}