Exemple #1
0
// MainInterface specifies that the connection should use client when
// receiving bootstrap messages.  By default, all bootstrap messages will
// fail.  The client will be closed when the connection is closed.
func MainInterface(client capnp.Client) ConnOption {
	rc, ref1 := refcount.New(client)
	ref2 := rc.Ref()
	return ConnOption{func(c *connParams) {
		c.mainFunc = func(ctx context.Context) (capnp.Client, error) {
			return ref1, nil
		}
		c.mainCloser = ref2
	}}
}
Exemple #2
0
// addImport increases the counter of the times the import ID was sent to this vat.
func (c *Conn) addImport(id importID) capnp.Client {
	if c.imports == nil {
		c.imports = make(map[importID]*impent)
	} else if ent := c.imports[id]; ent != nil {
		ent.refs++
		return ent.rc.Ref()
	}
	client := &importClient{
		id:   id,
		conn: c,
	}
	rc, ref := refcount.New(client)
	c.imports[id] = &impent{rc: rc, refs: 1}
	return ref
}
Exemple #3
0
// addExport ensures that the client is present in the table, returning its ID.
// If the client is already in the table, the previous ID is returned.
func (c *Conn) addExport(client capnp.Client) exportID {
	for i, e := range c.exports {
		if e != nil && isSameClient(e.rc.Client, client) {
			e.wireRefs++
			return exportID(i)
		}
	}
	id := exportID(c.exportID.next())
	rc, client := refcount.New(client)
	export := &export{
		id:       id,
		rc:       rc,
		client:   client,
		wireRefs: 1,
	}
	if int(id) == len(c.exports) {
		c.exports = append(c.exports, export)
	} else {
		c.exports[id] = export
	}
	return id
}
Exemple #4
0
// addRef increases the counter of the times the import ID was sent to this vat.
func (it *importTable) addRef(id importID) capnp.Client {
	if it.tab == nil {
		it.tab = make(map[importID]*impent)
	}
	ent := it.tab[id]
	var ref capnp.Client
	if ent == nil {
		client := &importClient{
			id:       id,
			manager:  it.manager,
			calls:    it.calls,
			releases: it.releases,
		}
		var rc *refcount.RefCount
		rc, ref = refcount.New(client)
		ent = &impent{rc: rc, refs: 0}
		it.tab[id] = ent
	}
	if ref == nil {
		ref = ent.rc.Ref()
	}
	ent.refs++
	return ref
}