Comments (10)
Could you provide more information about the assertion that fails?
Maybe this is related to #164
from czmq.
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.
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.
In first version,I didn't add the zsocket_destroy() ,it is the same error
from czmq.
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.
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.
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.
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.
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.
OK, thanks for explaining it. I've pushed a patch that should fix this: #202
from czmq.
Related Issues (20)
- How to create a SUB socket and Bind? No Bind/Connect methods available HOT 3
- Trouble with EPGM/multicast pub/sub HOT 4
- Differences in the list of installed header files between builds made using cmake and autotools HOT 2
- Android / Java build fails on CentOS 7 HOT 2
- can use zsock_new_pub() api set ipv6 HOT 3
- Android / Java bindings/jni/ci_build.sh fails on Ubuntu 22.04 HOT 3
- zauth `zsock_bind()` fails when called for the second time from a different thread
- Lingering broken TCP connections when using zproxy
- czmq bindiing jni should be deployed to maven central jcenter is now read only. HOT 1
- Tests on OSX? HOT 1
- Ios Build Fails Please check the log on IOS sdk 16.2 HOT 2
- zsock_events() segfaults if called too often HOT 4
- How to get peer PID with czmq? HOT 1
- Saving certificate to memory?
- An error occurs when the zsock_set_tcp_keepalive function is executed
- ziflist crashes when there are 'alias' net devices HOT 1
- zpoller_wait() will fail if WiFi networks are switched or after Windows sleep and even rebuilding all sockets doesn't make it recover HOT 9
- No MSYS2 package HOT 2
- zloop allows calling start() again but timer removal fails then HOT 2
- Issue with libczmq-dev HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from czmq.