search for: connectionmap

Displaying 3 results from an estimated 3 matches for "connectionmap".

2020 Apr 21
0
Re: [PATCH nbdkit v2] Add the ability to write plugins in golang.
...} type PluginConnectionInterface interface { // Open, GetSize and PRead are required for all plugins. // Other methods are optional. Close() GetSize() (uint64, error) PRead(buf []byte, offset uint64, flags uint32) error } Now, we need todo some mapping var connectionID uint var connectionMap map[uint]PluginConnectionInterface //export implOpen func implOpen(c_readonly C.int) unsafe.Pointer { readonly := false if c_readonly != 0 { readonly = true } h, err := pluginImpl.Open(readonly) if err != nil { set_error(err) return nil } if h == 0 { panic("Open me...
2020 Apr 21
2
[PATCH nbdkit v2] Add the ability to write plugins in golang.
Thanks: Dan Berrangé XXX UNFINISHED: - Is using uintptr for the handle a good idea? Plugins must return something != 0. In other languages we would allow plugins to return an arbitrary object here, but this is not possible in golang because of lack of GC roots. - Default can_* methods are hard to implement. Ideally we would be able to test if a user plugin implements a
2020 Apr 23
2
Re: [PATCH nbdkit v2] Add the ability to write plugins in golang.
...+ panic("plugin must implement GetSize()") +} + +func (c Connection) PRead(buf []byte, offset uint64, flags uint32) error { + panic("plugin must implement PRead()") +} + +// The implementation of the user plugin. +var pluginImpl PluginInterface +var nextConnectionId uintptr +var connectionMap map[uintptr]ConnectionInterface + +// Callbacks from the server. These translate C to Go and back. + +func set_error(err error) { + perr, ok := err.(PluginError) + if ok { + if perr.Errno != 0 { + SetError(perr.Errno) + } + Error(perr.Errmsg) + } else { + Error(err.Error()) + } +} + +//expor...