Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymorphism with interface doesnt work #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FKrotkih
Copy link

If we are using derived class that implements an interface throught base type or that interface, then polymorphism doesnt work. It works only in case using derived type explicitly. "public new" it is not enough. The way to go is to explicitly implement the part of the interface that you want to override. https://stackoverflow.com/questions/12314990/override-method-implementation-declared-in-an-interface

If we are using derived class that implements an interface throught base type or that interface, then polymorphism doesnt work. It works only in case using derived type explicitly. "public new" it is not enough. The way to go is to explicitly implement the part of the interface that you want to override.
https://stackoverflow.com/questions/12314990/override-method-implementation-declared-in-an-interface
@jeikabu
Copy link
Owner

jeikabu commented Oct 14, 2022

Interesting. Thanks for the fix, give me a few days to test it.
Did you have a snippet that demonstrates the issue/bug?

@FKrotkih
Copy link
Author

I don't have ready spippet, but i can describe what to do. We need C++ (to get the original pair1 protocol) and C# parts.

On C# side do:

var nngctx = new NngLoadContext(System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location));
var factory = NngLoadContext.Init(nngctx, "nng.Factories.Latest.Factory");
var socket = factory.PairOpen().Unwrap();
socket.Notify(nng.Native.Defines.NngPipeEv.AddPre, PipeEventCallback, IntPtr.Zero);
var context = socket.CreateAsyncContext(factory).Unwrap();
var listener = socket.ListenerCreate("tcp://*:5000").Unwrap();
listener.Start();
stoppingToken.Register(() =>{ context.Aio.Cancel(); });
while (!stoppingToken.IsCancellationRequested) {
    var msg = await context.Receive(stoppingToken);
}

On C++ side do:

nng_socket socket;
nng_dialer dialer;
int rv = nng_pair1_open(&socket);
rv = nng_pipe_notify(socket, NNG_PIPE_EV_ADD_POST, pipe_callback, 0);
rv = nng_dial(socket, "tcp://*:5000", &dialer, NNG_FLAG_NONBLOCK);
// waiting for pipe_callback call... it means that connection has estabilished, and all is ok
// otherwise it means that there are two different protocols 'pair0' (we set "nng.Factories.Latest.Factory", but it still calls Pair0Open) and 'pair1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants