Discussion:
[omniORB] CORBA::String_member
Default User
2007-10-25 06:03:36 UTC
Permalink
I'm using OmniOrb 4.1.0 on Windows. I'm sending structs as messages. I
have a problem with a client that reports catching an exception,
CORBA::UNKNOWN after sending about 4 messages. I think it's actually
the server that's gone wonky, because restarting the client produces
the error immediately.
From playing around, it seems to be having structs with
CORBA::String_member members. In the IDL, I changed all the strings to
char arrays, like so:

struct JobSubmissionRequest
{
// string appID;
char appID[16];
TransIDType transID;
unsigned short jobID;
FileType file;
DestType dest;
};

I was able to send messages repeatedly. Even if I don't set the strings
to any value, it still shows the error.

Any ideas?



Brian


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Clarke Brunt
2007-10-25 15:17:22 UTC
Permalink
Post by Default User
I'm using OmniOrb 4.1.0 on Windows. I'm sending structs as messages. I
have a problem with a client that reports catching an exception,
CORBA::UNKNOWN after sending about 4 messages. I think it's actually
the server that's gone wonky, because restarting the client produces
the error immediately.
From playing around, it seems to be having structs with
CORBA::String_member members. In the IDL, I changed all the strings
struct JobSubmissionRequest
{
// string appID;
char appID[16];
TransIDType transID;
unsigned short jobID;
FileType file;
DestType dest;
};
I was able to send messages repeatedly. Even if I don't set
the strings
to any value, it still shows the error.
Any ideas?
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.

Clarke Brunt
TRAFFICMASTER PLC
UNIT 22 / ST. JOHN'S INNOVATION CENTRE
COWLEY ROAD / CAMBRIDGE / CB4 0WS
T: 01223 422469
F:
E: ***@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-***@omniorb-support.com and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not omniorb-***@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 ***@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.
--------------------------------------------------------
Default User
2007-10-25 22:06:30 UTC
Permalink
Post by Clarke Brunt
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
Clarke Brunt
2007-10-28 18:51:50 UTC
Permalink
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.
Post by Default User
Post by Clarke Brunt
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.
===================================================================
#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
{
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; }
===================================================================
#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;
}
===================================================================
#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: ***@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-***@omniorb-support.com and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not omniorb-***@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 ***@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.
--------------------------------------------------------
Jason Etheridge
2007-10-29 03:06:30 UTC
Permalink
Post by Clarke Brunt
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.
I'd also suggest stepping through your server's implementation of the
receive() operation in a debugger. There's nothing obviously wrong
with your code (that I can spot either), which implies there's
something else going on in your environment.

What'd be most useful would be to zip up an archive with your version
of the echo example (including IDL, source and Makefile/SLN/PRJ), so
that others can try and replicate your problem.
--
Jason Etheridge mailto:***@etheridge.org
Duncan Grisby
2007-10-29 04:22:04 UTC
Permalink
Post by Default User
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.
If it's failing when you don't touch the data at all, that almost
certainly means that the problem is a mismatch between VC++ debug
options. Make sure that either everything is non-debug or that
everything, including omniORB itself, is the debug version.

Does your example with a struct work if you edit eg3 within the omniORB
sources and build it with the provided omniORB makefiles?

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Default User
2007-10-30 03:04:11 UTC
Permalink
Post by Duncan Grisby
Post by Default User
I have created a shorter example from the "echo 3" example that
shows
Post by Default User
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.
If it's failing when you don't touch the data at all, that almost
certainly means that the problem is a mismatch between VC++ debug
options. Make sure that either everything is non-debug or that
everything, including omniORB itself, is the debug version.
Does your example with a struct work if you edit eg3 within the
omniORB
sources and build it with the provided omniORB makefiles?
That's basically what I did. I'm getting ready to run on Linux, so
if the methodology is correct and it doesn't occur there, then I
won't have any problems. If I do, I'll come back.

Thanks to all for the input.



Brian



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

Continue reading on narkive:
Loading...