[omniORB] CORBA::String_member
Clarke Brunt
clarke.brunt at trafficmaster.co.uk
Sun Oct 28 13:49:46 GMT 2007
Well I can't see anything wrong with the code. I admit that I didn't
read your original message closely enough, and assumed that you were
returning the struct from the server, either as return value, or an
'out' argument, both of which are more likely to be coded incorrectly as
regards memory handling than just passing a structure as an 'in' arg -
not much to go wrong with 'const by reference'!
So I don't know what's going wrong. If it's still going wrong after a
few calls, then by all means persist asking and see whether anyone else
on the list will take it up. I wouldn't be surprised if someone suggests
turning up traceLevel to see what it reveals.
omniorb-list-bounces at omniorb-support.com wrote:
> --- 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__
Clarke Brunt
TRAFFICMASTER PLC
UNIT 22 / ST. JOHN'S INNOVATION CENTRE
COWLEY ROAD / CAMBRIDGE / CB4 0WS
T: 01223 422469
F:
E: clarke.brunt at trafficmaster.co.uk
Please consider the environment before printing this email. --------------------------------------------------------
Trafficmaster PLC is a limited Company registered in England and Wales.
Registered number: 2292714 Registered office: Martell House, University Way, Cranfield, BEDS. MK43 0TR
This message (and any associated files) is intended only for the use of omniorb-list at omniorb-support.com and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not omniorb-list at omniorb-support.com you are hereby notified that any dissemination, copying or distribution of this message, or files associated with this message, is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. Any views or opinions presented are solely those of the author clarke.brunt at trafficmaster.co.uk and do not necessarily represent those of the company.
Warning: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
--------------------------------------------------------
More information about the omniORB-list
mailing list