[omniORB] CORBA::String_member

Default User defaultuserbr at yahoo.com
Thu Oct 25 10:06:13 BST 2007


--- Clarke Brunt <clarke.brunt at trafficmaster.co.uk> wrote:


> Well the inevitable suspicion is that you're not handling
> memory-allocation for the string correctly - perhaps it's being freed
> twice on server-side (once by you, and once by the ORB), or perhaps
> you're not creating it in such a way that the ORB is able to free it
> correctly.
> 
> I think we could do with seeing your server code which creates struct
> and string and returns it, and the IDL for the method of interest.

I have created a shorter example from the "echo 3" example that shows
the same behavior. I'm not including the orb init code, as that's
boilerplate. In this case the "server" receives the message from
the "client". All the server does is acknowledge receipt of a 
message, it doesn't even access the data members of the struct. 
I hacked this together in a hurry, so pardon the sloppiness.


Server code:
===================================================================
#include <echo.hh>

#ifdef HAVE_STD
#  include <iostream>
   using namespace std;
#else
#  include <iostream.h>
#endif
  typedef CORBA::ULong arrayULong[200];
   typedef CORBA::Double arrayDouble[200];

static CORBA::Boolean bindObjectToName(CORBA::ORB_ptr,
CORBA::Object_ptr);


class Echo_i : public POA_Echo
{
public:
  inline Echo_i() {}
  virtual ~Echo_i() {}
  virtual void receive(const JobSubmissionRequest& request);

};

JobSubmissionRequest req;

void Echo_i::receive(const JobSubmissionRequest& request)
{
cout << "Received request message\n";

//  CORBA::String_var src = request.appID;
//  cout << "Received: " << (char*)src << endl;
//  cout << "Received: " << request.data1[0]<<" -> " <<
request.data1[199]<< endl;
//  cout << "Received: " << request.data2[0]<<" -> " <<
request.data2[199]<< endl;
}


Client code:
===================================================================
#include <echo.hh>
#include <string.h>

#ifdef HAVE_STD
#  include <iostream>
   using namespace std;
#else
#  include <iostream.h>
#endif
  typedef CORBA::ULong arrayULong[200];
   typedef CORBA::Double arrayDouble[200];

static CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb);

static void send(Echo_ptr e, const JobSubmissionRequest& request)
{
  if( CORBA::is_nil(e) ) {
    cerr << "send: The object reference is nil!\n" << endl;
    return;
  }

   e->receive(request);

   cout << "Sent request message\n";

 // cout << "Sent: " << request.appID << endl;
 // cout << "Sent: " << request.data1[0]<<" -> " <<
request.data1[199]<< endl;
 // cout << "Sent: " << request.data2[0]<<" -> " <<
request.data2[199]<< endl;
}

//////////////////////////////////////////////////////////////////////

int
main (int argc, char **argv) 
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = getObjectReference(orb);

    Echo_var echoref = Echo::_narrow(obj);
    CORBA::Double d = .5;
   JobSubmissionRequest request;
   
cout << "building arr\n";
    for(int i = 0; i < 200; i++)
    {
       request.data1[i] = i+1;
       request.data2[i] = i+.5;
    }
  
  CORBA::String_var src = (const char*) "App 1";
  request.appID = CORBA::string_dup(src);

//  strcpy((char*)request.appID, "Test");

cout << "ready to send\n";
    for (CORBA::ULong count=0; count < 1000; count++)
      send(echoref, request);

    orb->destroy();
  }
  catch(CORBA::TRANSIENT&) {
    cerr << "Caught system exception TRANSIENT -- unable to contact the
"
         << "server." << endl;
  }
  catch(CORBA::SystemException& ex) {
    cerr << "Caught a CORBA::" << ex._name() << endl;
  }
  catch(CORBA::Exception& ex) {
    cerr << "Caught CORBA::Exception: " << ex._name() << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  return 0;
}

IDL:
===================================================================

#ifndef __ECHO_IDL__
#define __ECHO_IDL__

//interface Echo {
//  short echoString(in string mesg);
//};

struct JobSubmissionRequest
{
//	char appID[16];
	string appID;
	unsigned long data1[200];
	double data2[200];
};

interface Echo {
  void receive(in JobSubmissionRequest req);
};


#endif  // __ECHO_IDL__






__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the omniORB-list mailing list