[omniORB] problems with EINTR and errno?

Matthew N. White matthew.white@marconi.com
Thu, 17 May 2001 11:17:03 -0400


Hi,
    I'm using omniORB on redhat linux 7.0 (I updated my glibc and
libstdc++).  Basically what I am doing is creating a shared library
which another application loads to access a notification service.  This
application starts a thread that calls ORB_init and attempts to obtain a
reference to an event channel.  I am running into problems when the
application calls

    CORBA::Object_var channel_ref = name_context->resolve(name);

where name is the name of an event channel, and name_context is the
context for the naming service, which was successfully obtained.
A COMM_FAILURE exception is thrown that is resulting from a failed call
to connect() in tcpSocketMTfactory.cc:1271.  The code that is failing
is:

  if (connect(sock,(struct sockaddr *)&raddr,
       sizeof(struct sockaddr_in)) == RC_SOCKET_ERROR)
  {
# ifndef __WIN32__
    if (errno != EINPROGRESS) {
      CLOSESOCKET(sock);
      return RC_INVALID_SOCKET;
    }
    ...

When I run the gdb debugger on the ORB code and break at this point,
looking at errno gives a value of 4, which is EINTR, meaning the call to
connect was interrupted by a signal, which would explain the error.
When I simply printf the value of errno, however, it is zero, which to
to makes no sense to me, but also explains the error.  Modifying to code
to check for an errno of zero, e.g.

 if (connect(sock,(struct sockaddr *)&raddr,
       sizeof(struct sockaddr_in)) == RC_SOCKET_ERROR)
  {
# ifndef __WIN32__
    if (errno != EINPROGRESS && errno != 0) {
      CLOSESOCKET(sock);
      return RC_INVALID_SOCKET;
    }
    ...

causes the application to work fine (it appears), as an experiment.
Also, I don't get these COMM_FAILURE exceptions if I have my application
call ORB_init with its main thread instead of spawning another thread
specifically for this purpose.

So is there anything that could explain this behavior?  Forgive me if
I'm doing something stupid here, I'm very new to CORBA and C++ threads
programming.

Thanks for any replies in advance.

Matt W.