[nanomsg] Multi thread question

  • From: "Li Ke" <like@xxxxxxxxxxxxxxxxxxx>
  • To: "nanomsg" <nanomsg@xxxxxxxxxxxxx>
  • Date: Wed, 28 May 2014 15:42:20 +0800

Hi, everyone.


Here I got a question about the mutithread environment.


I am trying to employ nanomsg on android native code.
I got a function foo() to do all the nanomsg work, mostly like this:


void foo()
{
  int pull = ::nn_socket(AF_SP, NN_PULL);
  int ret = ::nn_bind(pull, name);
  int recvfd;
  std::size_t ss;r
  ret = ::nn_getsockopt(pull, NN_SOL_SOCKET, NN_RCVFD, &recvfd, &ss);
  if(ret == 0){
      // get recvfd ok  and print the recvfd
  }
  else{
      // error
  }
  .....
  nn_close(pull);
} 


When I use one same thread to call foo, it works OK, and the recvfd is an 
positive integer (recvfd > 0);
However, while I try to put foo in another thread, the ret of nn_getsockopt 
return 0 but the recvfd is always 0.


Could anyone help me?
Thanks a lot.




------------------
—— Parachute Studio
Meet your creativity.
 www.parachute-studio.cc

Other related posts: