-func newChannel(id uint16, conn *Connection, codec MessageCodec, identifier MessageIdentifier, reqSize, replySize int) *Channel {
- return &Channel{
- id: id,
- conn: conn,
- msgCodec: codec,
- msgIdentifier: identifier,
- reqChan: make(chan *vppRequest, reqSize),
- replyChan: make(chan *vppReply, replySize),
- replyTimeout: DefaultReplyTimeout,
+func (c *Connection) newChannel(reqChanBufSize, replyChanBufSize int) (*Channel, error) {
+ // create new channel
+ channel := &Channel{
+ conn: c,
+ msgCodec: c.codec,
+ msgIdentifier: c,
+ reqChan: make(chan *vppRequest, reqChanBufSize),
+ replyChan: make(chan *vppReply, replyChanBufSize),
+ replyTimeout: DefaultReplyTimeout,
+ receiveReplyTimeout: ReplyChannelTimeout,
+ }
+
+ // store API channel within the client
+ c.channelsLock.Lock()
+ if len(c.channels) >= 0x7fff {
+ return nil, errors.New("all channel IDs are used")
+ }
+ for {
+ c.nextChannelID++
+ chID := c.nextChannelID & 0x7fff
+ _, ok := c.channels[chID]
+ if !ok {
+ channel.id = chID
+ c.channels[chID] = channel
+ break
+ }