I'm using latest libzmq-3.1.0 so some of the functions changed a bit.

I'm also a "C" coder more than "C++", and never used boost, but that to 
be said, this example did not ever made problem for me:

I was using my own built zmq.dll from luajit ffi bindings that I keep:
https://github.com/malkia/ufo/tree/master/bin/Windows/x86

// file: a.c
// compile with: cl -O2 -MD a.c
// I'm using Windows WDK 7.1, but Windows SDK 7.1, or Visual Studio 
prompt should work too

#include <process.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "..\..\..\..\libzmq\include\zmq.h"

#pragma comment(lib,"zmq")

#define INTERNAL_DATA_SOCKET "inproc://data"
#define MESSAGE  "{\"m_t\": 0, \"data\": {}}"

void *context;
static char msg[] = MESSAGE;

unsigned __stdcall outputWorker(void*);

int main(int argc, char* argv[]) {
        void* intDataSocket;
        int messagesToStore = 1;
        
         context = zmq_init(1);
        _beginthreadex(NULL, 0, outputWorker, NULL, 0, NULL);

         intDataSocket = zmq_socket(context, ZMQ_PUB);
        printf("intDataSocket=%d\n",intDataSocket);
         printf("zmq_connect=%d\n",zmq_connect(intDataSocket, 
INTERNAL_DATA_SOCKET));
         printf("zmq_setsockopt=%d\n",zmq_setsockopt(intDataSocket, 
ZMQ_SNDHWM, &messagesToStore, sizeof(messagesToStore)));
         printf("zmq_setsockopt=%d\n",zmq_setsockopt(intDataSocket, 
ZMQ_RCVHWM, &messagesToStore, sizeof(messagesToStore)));

         while(1) {
                 int rc = zmq_send(intDataSocket, msg, sizeof(msg), 0);
                 assert(rc == sizeof(msg));
         }
         return 0;
}

unsigned __stdcall outputWorker(void*a) {
         void *intDataSocket = zmq_socket(context, ZMQ_SUB);
         printf("zmq_bind=%d\n",zmq_bind(intDataSocket, 
INTERNAL_DATA_SOCKET));
         printf("zmq_setsockopt=%d\n",zmq_setsockopt(intDataSocket, 
ZMQ_SUBSCRIBE, "", 0));

         while(1) {
                char buf[sizeof(msg)];
                 int rc = zmq_recv(intDataSocket, buf, sizeof(buf), 0);
                assert(rc = sizeof(buf));
         }
        
        return 0;
}

On 1/18/2012 4:24 PM, Serg Gulko wrote:
> Correction - lines 59, 60 and 62
>
> On Wed, Jan 18, 2012 at 7:07 PM, Serg Gulko <[email protected]
> <mailto:[email protected]>> wrote:
>
>     Hello!
>
>     Thanks for hint, I really was using HWM incorrectly. I changed it
>     according spec but problem is still here..
>
>     http://pastebin.com/tDFpbhM0
>
>
>     But when I commented any operations on subscriber part(lines 68, 69,
>     70 and 71) everything working without problems.
>
>     Serg
>     On Wed, Jan 18, 2012 at 3:46 PM, Chuck Remes <[email protected]
>     <mailto:[email protected]>> wrote:
>
>
>         On Jan 18, 2012, at 2:32 PM, Serg Gulko wrote:
>
>          > Yes, in this example I using constant size message(22 bytes)
>         - I want keep only one 22 bytes message.
>          > Or I wrong?
>
>         You are wrong. For HWM, you pass the *number of messages*. What
>         your code does is pass the *number of bytes*. That is incorrect.
>
>         Change it to set the HWM to 1. There are lots of C code examples
>         in the guide. Refer to one of those examples for the exact syntax.
>
>         cr
>
>         _______________________________________________
>         zeromq-dev mailing list
>         [email protected] <mailto:[email protected]>
>         http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to