コード例 #1
0
ファイル: session.go プロジェクト: zhaohaidao/libchan
// Receive receives a message sent across the channel from
// a sender on the other side of the transport.
func (r *receiver) Receive(message interface{}) error {
	r.decodeLock.Lock()
	defer r.decodeLock.Unlock()
	if r.decoder == nil {
		r.decoder = msgpack.NewDecoder(r.stream)
		r.decoder.AddExtensions(r.stream.initializeExtensions())
	}

	decodeErr := r.decoder.Decode(message)
	if decodeErr == io.EOF {
		r.stream.Close()
		r.decoder = nil
	}
	return decodeErr
}
コード例 #2
0
ファイル: session.go プロジェクト: beibei1990/libchan
// Receive receives a message sent across the channel from
// a sender on the other side of the transport.
func (c *channel) Receive(message interface{}) error {
	if c.direction == outbound {
		return ErrWrongDirection
	}

	c.decodeLock.Lock()
	defer c.decodeLock.Unlock()
	if c.decoder == nil {
		c.decoder = msgpack.NewDecoder(c.stream)
		c.decoder.AddExtensions(c.initializeExtensions())
	}

	decodeErr := c.decoder.Decode(message)
	if decodeErr == io.EOF {
		c.stream.Close()
		c.decoder = nil
	}
	return decodeErr
}