[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mico-devel
Subject:    Please, help me !! (related with ORB_init and fork)
From:       "Emilio" <inky () wanadoo ! es>
Date:       2000-11-27 17:50:53
[Download RAW message or body]

Hello everybody.

I posted this message some days ago and I've got no answer yet. (Maybe the
problem is not well described?) Please, could somebody help me? It's very
important for me. Give me some clues, at least.

The problem is that I have to separate my program into several processes
with fork(), so:
1. The ORB is initiated and it uses some sockets to communicate with the
server.
2. The program is separated with fork() and a son process is created, and
both processes (the father and son) inherit the open sockets.(I think the
same thing happens in the standard output where the messages from the father
and the son appear mixed).
3. Then, when there is an invocation (from the father or from the son) to a
method, and this method generates an answer, both processes receive that
answer (because they share the sockets), and it's a matter of luck to know
which process will analyze it.

I have to maintain the fork() call because it's a big application and is
already programmed. I also have to work with no-multi-threaded MICO.
I was told that the solution to this problem is to separate the processes
before calling to ORB_init() and then to invoke ORB_init(argc, argv, id) in
both processes. But I need the ORB to do some tasks before I separate the
processes so I thought of re-initiate it again after the separation. Is it
correct? Is this the right way to do that? Is the following code well
programmed?

// Begin.
/* .... */

initORB(); // first call to this method within this program.

/* .... */

int pid;
if ((pid = fork()) < 0) exit(0);
else if (pid == 0)  // the son
{
  /* .... */
  initORB();
  /* .... */
}
else // the father
{
  /* .... */
  initORB();
  /* .... */
}

/* .... */
// End.

where initORB() is:

int initORB(void)
{

  String address1 = "inet:localhost:1234";
  String address2 = "inet:localhost:1235";

  int new_argc = 5;
  char **new_argv = new char*[new_argc+1];

  new_argv[0] = "dummy";
  new_argv[1] = "-ORBNamingAddr";
  new_argv[2] = new char[address1.length()+1];
  strcpy(new_argv[2],(char *)address1.chars());
  new_argv[3] = "-ORBTradingAddr";
  new_argv[4] = new char[address2.length()+1];
  strcpy(new_argv[4],(char *)address2.chars());
  new_argv[5] = 0;

  // orb is declared as CORBA::ORB_var before.
  orb = CORBA::ORB_init( new_argc, new_argv, "mico-local-orb" );
  assert( !CORBA::is_nil( orb ) );

  CORBA::Object_var obj = orb->resolve_initial_references("NameService");
  assert (! CORBA::is_nil (obj));

  // ncRef is declared as CosNaming::NamingContext_var before.
  ncRef = CosNaming::NamingContext::_narrow( obj );
  assert (! CORBA::is_nil (ncRef));

  obj = orb->resolve_initial_references( "TradingService" );
  assert( !CORBA::is_nil( obj ) );

  // lookup is declared as CosTrading::Lookup_var before.
  lookup = CosTrading::Lookup::_narrow( obj );
  assert( !CORBA::is_nil( lookup ) );

  // reg is declared as CosTrading::Register_var before.
  reg = lookup->register_if();
  assert( !CORBA::is_nil( reg ) );

  obj = lookup->type_repos();
  assert( !CORBA::is_nil( obj ) );
  // repo is declared as CosTradingRepos::ServiceTypeRepository_var before.
  repo = CosTradingRepos::ServiceTypeRepository::_narrow( obj );
  assert( !CORBA::is_nil( repo ) );

  delete new_argv[2], new_argv[4];

  return 1;
}


Thank you very much in advance.

Emilio.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic