diff options
author | mhalaj1 <matus.halaj@pantheon.tech> | 2021-08-26 20:15:08 +0200 |
---|---|---|
committer | mhalaj1 <matus.halaj@pantheon.tech> | 2021-09-07 15:24:53 +0200 |
commit | c09ee3241377aae2530a73d48c4e20641d76d0ee (patch) | |
tree | 219fd1f7d9ba595f0f4c8dac9796bc76ce3556fc /core/stream.go | |
parent | debc52dea8a81417bb08ca5bb934c7876b6d65e0 (diff) |
Refactoring and fixes
* refactor creation of new channel
* add missing closing of created streams
* correct documentation regarding thread safety of stream
Signed-off-by: mhalaj1 <matus.halaj@pantheon.tech>
Change-Id: Ic601efff298fcbdecaafab83fa236253af69de21
Diffstat (limited to 'core/stream.go')
-rw-r--r-- | core/stream.go | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/core/stream.go b/core/stream.go index 3d417f1..363cc9f 100644 --- a/core/stream.go +++ b/core/stream.go @@ -20,14 +20,12 @@ import ( "fmt" "reflect" "sync" - "sync/atomic" "time" "git.fd.io/govpp.git/api" ) type Stream struct { - id uint32 conn *Connection ctx context.Context channel *Channel @@ -57,15 +55,9 @@ func (c *Connection) NewStream(ctx context.Context, options ...api.StreamOption) for _, option := range options { option(s) } - // create and store a new channel - s.id = atomic.AddUint32(&c.maxChannelID, 1) & 0x7fff - s.channel = newChannel(uint16(s.id), c, c.codec, c, s.requestSize, s.replySize) - s.channel.SetReplyTimeout(s.replyTimeout) - // store API channel within the client - c.channelsLock.Lock() - c.channels[uint16(s.id)] = s.channel - c.channelsLock.Unlock() + s.channel = c.newChannel(s.requestSize, s.replySize) + s.channel.SetReplyTimeout(s.replyTimeout) // Channel.watchRequests are not started here intentionally, because // requests are sent directly by SendMsg. |