- return c, connChan, nil
-}
-
-// Disconnect disconnects from VPP and releases all connection-related resources.
-func (c *Connection) Disconnect() {
- if c == nil {
- return
- }
-
- connLock.Lock()
- defer connLock.Unlock()
-
- if c.vpp != nil {
- c.disconnectVPP()
- }
- conn = nil
-}
-
-// newConnection returns new connection handle.
-func newConnection(vppAdapter adapter.VppAdapter) (*Connection, error) {
- connLock.Lock()
- defer connLock.Unlock()
-
- if conn != nil {
- return nil, errors.New("only one connection per process is supported")
- }
-
- conn = &Connection{
- vpp: vppAdapter,
- codec: &codec.MsgCodec{},
- channels: make(map[uint16]*channel),
- msgIDs: make(map[string]uint16),
- msgMap: make(map[uint16]api.Message),
- notifSubscriptions: make(map[uint16][]*api.NotifSubscription),
- }
- conn.vpp.SetMsgCallback(conn.msgCallback)
-
- return conn, nil