bvarga / delphizmq

0MQ Delphi binding
GNU Lesser General Public License v3.0
137 stars 63 forks source link

Dealer -> Router: zmq_ctx_set_monitor not function properly #1

Closed acalahorro closed 11 years ago

acalahorro commented 11 years ago

I'm developing in delphi language to libzmq.dll 3.2 using your wrapper as it's very useful! Now, my application is working with architecture "Dealer to Router" properly but I would like introduce the monitor event.

With the call "zmq_ctx_set_monitor" when a event is generated then the function is activated but I believe that the parameter values can't be correct, for example these are: event: 4611060 data(addr: ' Oêf@{êf', fd: 2704024, err: 2704024, interval: 2704024)

Attached the code itself can be useful:

procedure OnEventMonitor(s: Pointer; event: Integer; data: zmq_event_data_t); var AEvent: String; begin AEvent := '';

case (event) of ZMQ_EVENT_CONNECTED: AEvent := 'ZMQ_EVENT_CONNECTED'; ZMQ_EVENT_CONNECT_DELAYED: AEvent := 'ZMQ_EVENT_CONNECT_DELAYED'; ZMQ_EVENT_CONNECT_RETRIED: AEvent := 'ZMQ_EVENT_CONNECT_RETRIED'; ZMQ_EVENT_LISTENING: AEvent := 'ZMQ_EVENT_LISTENING'; ZMQ_EVENT_ACCEPTED: AEvent := 'ZMQ_EVENT_ACCEPTED'; ZMQ_EVENT_BIND_FAILED: AEvent := 'ZMQ_EVENT_BIND_FAILED'; ZMQ_EVENT_ACCEPT_FAILED: AEvent := 'ZMQ_EVENT_ACCEPT_FAILED'; ZMQ_EVENT_CLOSED: AEvent := 'ZMQ_EVENT_CLOSED'; ZMQ_EVENT_CLOSE_FAILED: AEvent := 'ZMQ_EVENT_CLOSE_FAILED'; ZMQ_EVENT_DISCONNECTED: AEvent := 'ZMQ_EVENT_DISCONNECTED'; end;

WriteInLog(Format('%s (addr:%s|fd:%d|err:%d|interval:%d)', [AEvent, data.addr, data.fd, data.err, data.interval])); end;

procedure TfrmForm.btRunClick(Sender: TObject); begin try FZMQContext := TZMQContext.create; FZMQContext.RegisterMonitor(OnEventMonitor); except on e:exception do WriteInLog('Run: ' + e.Message); end; end;

Thank you very much in advance, thankful for this great wrapper too! Regards.

bvarga commented 11 years ago

Yes, It's possible, I just added blindly the monitor support, without tests.

I tried to quickly figure out what are the good parameters, but had no luck (I think the problem is in the dll). Digged deeper, and found that in the new version 3.2.2 RC2 it's changed, the zmq_ctx_set_monitor is completely missing from the dll, but there's a new similar zmq_socket_monitor which probably will replace the old one. There's a discussion about this change on the mailing list. In short the monitoring is connected to the socket, rather the context.

I'll try to quickly implement this new monitoring logic.

acalahorro commented 11 years ago

Hello Mr.Varga, thank you for the quick reply! I viewed other codes with another programming language and I think that the implementation is correct, so I also believe that the fail must be in the dll. If you could include the new release will be fantastic, Thanks you very much another time!!

bvarga commented 11 years ago

New monitoring logic pushed, and added some info how to use it into the Readme. Feel free to share your thoughts about this implementation, and the usability (pros, cons).

acalahorro commented 11 years ago

Hello Mr.Varga, I have been working with your new release and the general process is properly and it's very fast to implement!

I only have problems sometimes when disconnected or connected event is invoked, after this event the addr value isn't correct, I think this issue is addressed in https://zeromq.jira.com/browse/LIBZMQ-384. e.g. the change of the addr's value is: îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþU’kè`ë.

However, I have tested with libzmq3-x86-v100-mt-gd.dll also and it seems that the error happens less often. I don't know if it is possible or by chance..

Trying to help, seem that the error occurs most often when the client starts firstly, rather than the server. it is curious because the error isn't always generated in similar situations, sometimes it happens at first communication and other times when there have been several connections and disconnections before.

Thank you very much!

bvarga commented 11 years ago

If it's a bug in the dll, there's not much I can do, just report it in the zeromq issue tracker. The dll is quite new, (october 10). Maybe you can try to build your own dll from the zeromq3-x source, or build the development version of zeromq libzmq and let's see what's happening.It seems they fixed this issue, but this monitoring part was rewritten completly.

Tried with the latest (just built) zeromq3-x and libzmq dll-s, and I can see your problem,I think it's a bug in zeromq.

bvarga commented 11 years ago

In the new stable 3.2.2 it's fixed (https://zeromq.jira.com/browse/LIBZMQ-384). The project dlls updated with the stable release dlls pulled from: http://www.zeromq.org/distro:microsoft-windows. pull the master, and it should work.