Code Monkey home page Code Monkey logo

Comments (10)

ulikoehler avatar ulikoehler commented on May 22, 2024

Could you provide more information about the assertion that fails?
Maybe this is related to #164

from czmq.

balanceren avatar balanceren commented on May 22, 2024

sorry,i don't know how to modify the style to make the code clear.

int main (void)
{
    zctx_t *ctx = zctx_new ();
    void * child = zthread_fork(ctx, client_task, "child1");
    int t = 0;
    while(!zctx_interrupted && t != 20)
    {
        char cmd[10]={0};
        sprintf(cmd,"Get %d\n",t++);
        zstr_send(child,cmd);
        Sleep(300);
    }
    /*
    if I don't do these below, 
    the assert false,after call zctx_destroy (&ctx);
    */
    //zstr_send(child,"DELETE");
    //char * str = zstr_recv(child);
    //free(str);

    zctx_destroy (&ctx);
    return 0;
}

static void client_task (void *args, zctx_t *ctx, void *pipe)
{
    void * client = zsocket_new (ctx, ZMQ_DEALER);
    void * sub   = zsocket_new(ctx,ZMQ_SUB);
    char identity [10]={0};
    if(args)
    {
        int len = min(strlen((char *)args),9);
        memcpy(identity,args,len);
        zsockopt_set_identity (client, identity);
    }

    zsocket_connect (client, "tcp://localhost:5570");
    zsocket_connect (sub, "tcp://localhost:5556");
    bool run = true;
    while (run) {
        zmq_pollitem_t items [] = { 
            { client, 0, ZMQ_POLLIN, 0 },
            { sub, 0, ZMQ_POLLIN, 0 },
            { pipe, 0, ZMQ_POLLIN, 0 }};

            int rc = zmq_poll (items, 3, 1000);
            if (rc == -1)
                break;          //  Interrupted
            if (items [0].revents & ZMQ_POLLIN)
            {
                printf("client\n");
            }
            if (items [1].revents & ZMQ_POLLIN)
            {
                printf("sub\n");
            }
            if (items [2].revents & ZMQ_POLLIN)
            {
                char * str = zstr_recv (pipe);
                printf("pipe__%s\n",str);
                if(strcmp(str,"DELETE")==0)
                    run = false;
                else    //cmd
                    zstr_send(client,str);
                free(str);
            }
    }
    zstr_send(pipe,"END");
    zsocket_destroy(ctx,client);
    zsocket_destroy(ctx,sub);
}

from czmq.

hintjens avatar hintjens commented on May 22, 2024

I've not tried yet to reproduce this, but try removing the
zsocket_destroy() calls. You don't need these and they may be causing
zctx_destroy confusion. It shouldn't assert anyhow.

On Wed, Jun 26, 2013 at 4:02 PM, balanceren [email protected]:

int main (void)
{
zctx_t ctx = zctx_new ();
*
void * child = zthread_fork(ctx, client_task, "child1");
*

  • int t = 0;
    while(!zctx_interrupted && t != 20)
    {
    char cmd[10]={0};
    sprintf(cmd,"Get %d\n",t++);
    zstr_send(child,cmd);
    Sleep(300);
    }
    /*
    if I don't do these below,
    the assert false,after call zctx_destroy (&ctx);
    */
    //zstr_send(child,"DELETE");
    //char * str = zstr_recv(child);
    //free(str);

zctx_destroy (&ctx);
return 0;

}

static void client_task (void *args, zctx_t *ctx, void *pipe)
{
void * client = zsocket_new (ctx, ZMQ_DEALER);
void * sub = zsocket_new(ctx,ZMQ_SUB);
char identity [10]={0};
if(args)
{
int len = min(strlen((char *)args),9);
memcpy(identity,args,len);
zsockopt_set_identity (client, identity);
}

zsocket_connect (client, "tcp://localhost:5570");

zsocket_connect (sub, "tcp://localhost:5556");
bool run = true;
while (run) {
zmq_pollitem_t items [] = {
{ client, 0, ZMQ_POLLIN, 0 },
{ sub, 0, ZMQ_POLLIN, 0 },
{ pipe, 0, ZMQ_POLLIN, 0 }};

int rc = zmq_poll (items, 3, 1000);
if (rc == -1)
    break;          //  Interrupted
if (items [0].revents & ZMQ_POLLIN)
{
    printf("client\n");
}
if (items [1].revents & ZMQ_POLLIN)
{
    printf("sub\n");
}
if (items [2].revents & ZMQ_POLLIN)
{
    char * str = zstr_recv (pipe);
    printf("pipe__%s\n",str);
    if(strcmp(str,"DELETE")==0)
        run = false;
    else    //cmd
        zstr_send(client,str);
    free(str);
}

}
zstr_send(pipe,"END");
zsocket_destroy(ctx,client);
zsocket_destroy(ctx,sub);

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/199#issuecomment-20049236
.

from czmq.

balanceren avatar balanceren commented on May 22, 2024

In first version,I didn't add the zsocket_destroy() ,it is the same error

from czmq.

balanceren avatar balanceren commented on May 22, 2024

I debug the zmq when it term, and find the bug, but I don't know how to fix it.

when the child thread get the term cmd,and
call zctx__socket_destroy,this below code will call

void zsocket_set_linger (void *zocket, int linger) 
{
#   if defined (ZMQ_LINGER)
    int rc = zmq_setsockopt (zocket, ZMQ_LINGER, &linger, sizeof (int));
    printf("errorno =%x=%d____%d\n",_errno(),errno,ETERM);
    assert (rc == 0 || errno == ETERM);

the assert condition is rc and the errno,
if the ctx_terminated is true, the errno will be set to ETERM,

  int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
     size_t optvallen_)
 {
     if (unlikely (ctx_terminated)) {
        errno = ETERM;
        printf("setsockopt =%x=%d____%d\n",_errno(),errno,ETERM);
        return -1;
    }

but, I found the _errno() has different address, so It is the reason why errno != ETERM.

from czmq.

hintjens avatar hintjens commented on May 22, 2024

Can you get more information?

  • which socket is this failing on
  • which zctx, the parent or the child thread
  • what is the errno that it is actually getting

Thanks

On Thu, Jun 27, 2013 at 4:22 AM, balanceren [email protected]:

I debug the zmq when it term, and find the bug, but I don't know how to
fix it.

when the child thread get the term cmd,and
call zctx__socket_destroy,this below code will call
void zsocket_set_linger (void *zocket, int linger)
{

if defined (ZMQ_LINGER)

int rc = zmq_setsockopt (zocket, ZMQ_LINGER, &linger, sizeof (int));
printf("errorno =%x=%d____%d\n",_errno(),errno,ETERM);
assert (rc == 0 || errno == ETERM);

the assert condition is rc and the errno,
if the ctx_terminated is true, the errno will be set to ETERM,
int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
size_t optvallen_)
{
if (unlikely (ctx_terminated)) {
errno = ETERM;

    printf("setsockopt =%x=%d____%d\n",_errno(),errno,ETERM);

    return -1;
}

but, I found the _errno() has different address, so It is the reason why
errno != ETERM.


Reply to this email directly or view it on GitHubhttps://github.com//issues/199#issuecomment-20093330
.

from czmq.

balanceren avatar balanceren commented on May 22, 2024

there is the code in my previous reply, you can test it.

if the _errno() got same address, the code is ok.

I compile the zmq to static lib and link to my app, and then the _errno() got the same address.

if I compile the zmq to dll in windows, the _errno() got different address

from czmq.

hintjens avatar hintjens commented on May 22, 2024

I can't test the code, don't have a Windows box, and the problem doesn't
happen on Windows.

What I know is that on Windows, errno is per-thread; this is why _errno()
has different addresses in some cases. It means if one thread sets it,
another thread won't get the same value.

Could you try to get me the information I asked for, then I'll try to see
what might be happening.

On Fri, Jun 28, 2013 at 8:47 AM, balanceren [email protected]:

there is the code in my previous reply, you can test it.

if the _errno() got same address, the code is ok.

I compile the zmq to static lib and link to my app, and then the _errno()
got the same address.

if I compile the zmq to dll in windows, the _errno() got different address


Reply to this email directly or view it on GitHubhttps://github.com//issues/199#issuecomment-20172998
.

from czmq.

balanceren avatar balanceren commented on May 22, 2024

the errno is per dll,
http://social.msdn.microsoft.com/Forums/vstudio/en-US/b4500c0d-1b69-40c7-9ef5-08da1025b5bf/setting-errno-from-within-a-dll

I suggest the zcmq use a self errno to manage the errno status.

from czmq.

hintjens avatar hintjens commented on May 22, 2024

OK, thanks for explaining it. I've pushed a patch that should fix this: #202

from czmq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.