hang using omniorb and java - Object
This is a discussion on hang using omniorb and java - Object ; I am writing a client/server application for my final project. The
client is is a java and the server is in c (msvc7) and i'm using omni
orb on the server. My problem is the client hangs on some of ...
-
hang using omniorb and java
I am writing a client/server application for my final project. The
client is is a java and the server is in c (msvc7) and i'm using omni
orb on the server. My problem is the client hangs on some of the
method calls.
The following code will not return the structure to the client. The
message box comes up for each instance of a file but an exception is
thrown on the client at the end.
/*--------------------------idl----------------------------*/
struct file_info {
string name;
string type;
string time;
long size;
};
typedef sequence<file_info> directory_contents;
struct directory {
string name;
directory_contents contents;
};
/*--------------------------C++-----------------------------*/
directory* Operations_i::dir () {
WIN32_FIND_DATA wfd;
HANDLE hFind;
file_info_var fi;
directory_var directory_inst = new directory;
directory_inst->contents = (directory_contents)* new
directory_contents(100);
directory_inst->contents.length(100);
CORBA::ULong count = 0;
hFind = FindFirstFile ("*", &wfd);
if (hFind != INVALID_HANDLE_VALUE) {
BOOL hasMore = true;
do {
fi = new file_info;
fi->name = (const char*) wfd.cFileName;
//fi->size = 0;
//fi->type = CORBA::string_dup (" ");
directory_inst->contents[count] = fi;
MessageBox (NULL, fi->name, "server message", MB_OK);
hasMore = FindNextFile (hFind, &wfd);
if (hFind != INVALID_HANDLE_VALUE)
hasMore = false;
count++;
}
while (hasMore);
}
FindClose (hFind);
return (directory*) &directory_inst;
}
/*---------------------------java-------------------------------*/
directory dir_inst = operationsRef.dir ();
/****************************************************************/
/*---------------------------------------------------------------
and this method works once and hangs on the second call.
-----------------------------idl--------------------------------*/
interface Operations {
string pwd ();
};
/*---------------------------c++--------------------------------*/
char* Operations_i:
wd () {
char* current_directory;
GetCurrentDirectory (1024, current_directory);
return CORBA::string_dup(current_directory);
}
/*---------------------------java-------------------------------*/
System.out.println (operationsRef.pwd());
/*--------------------------------------------------------------*/
-
Re: hang using omniorb and java
warren_k_harding@hotmail.com (Warren Harding) wrote in
news:3f54840e.0404140049.3441ea37@posting.google.com:
> I am writing a client/server application for my final project. The
> client is is a java and the server is in c (msvc7) and i'm using omni
> orb on the server. My problem is the client hangs on some of the
> method calls.
> The following code will not return the structure to the client. The
> message box comes up for each instance of a file but an exception is
> thrown on the client at the end.
>
There are various problems with your code, some of them are shown below.
You should get a better understanding of the C++ mapping and the usual
advice is to read Henning & Vinoski's book[1] or the specification [2]
itself.
[1]: <http://www.iona.com/hyplan/vinoski/#book>
[2]: <http://www.omg.org/technology/documents/formal/c++.htm>
> /*--------------------------idl----------------------------*/
> struct file_info {
> string name;
> string type;
> string time;
> long size;
> };
>
> typedef sequence<file_info> directory_contents;
> struct directory {
> string name;
> directory_contents contents;
> };
> /*--------------------------C++-----------------------------*/
> directory* Operations_i::dir () {
> WIN32_FIND_DATA wfd;
> HANDLE hFind;
> file_info_var fi;
> directory_var directory_inst = new directory;
> directory_inst->contents = (directory_contents)* new
> directory_contents(100);
You should eliminate the previous instruction and just leave the next
one:
> directory_inst->contents.length(100);
> CORBA::ULong count = 0;
> hFind = FindFirstFile ("*", &wfd);
> if (hFind != INVALID_HANDLE_VALUE) {
> BOOL hasMore = true;
> do {
> fi = new file_info;
> fi->name = (const char*) wfd.cFileName;
> //fi->size = 0;
> //fi->type = CORBA::string_dup (" ");
> directory_inst->contents[count] = fi;
> MessageBox (NULL, fi->name, "server message", MB_OK);
> hasMore = FindNextFile (hFind, &wfd);
> if (hFind != INVALID_HANDLE_VALUE)
> hasMore = false;
> count++;
> }
> while (hasMore);
What happens if the directory has more than 100 entries? You would write
past the end of the directory_inst->contents sequence (i.e. at 101, 102,
....) which is undefined and simply wrong. So you should check if you have
reached the maximum length (100) and if so stop the iteration.
Also if you have found entries less than 100 you should update the
directory_inst->contents sequence length to be the right one (not 100)
like this:
directory_inst->contents.length(count);
Of course the best approach is to not to have any upper limit in the
number of entries and just adjust the length of the sequence in every
iteration.
> }
> FindClose (hFind);
> return (directory*) &directory_inst;
You should have a return statement like this:
return directory_inst._retn();
> }
> [ snip! ]
> /*---------------------------c++--------------------------------*/
>
> char* Operations_i:
wd () {
> char* current_directory;
This should be:
char current_directory[1024];
> GetCurrentDirectory (1024, current_directory);
> return CORBA::string_dup(current_directory);
> }
>
Cheers
Stelios
--
Stelios G. Sfakianakis | Center of Medical Informatics
Voice: +30-2810-391650 | Institute of Computer Science
PGP Key ID: 0x5F30AAC2 | FORTH, http://www.forth.gr
Similar Threads
-
By Application Development in forum lisp
Replies: 4
Last Post: 12-10-2007, 09:34 PM
-
By Application Development in forum Java
Replies: 4
Last Post: 09-20-2007, 02:57 AM
-
By Application Development in forum Object
Replies: 4
Last Post: 10-30-2006, 08:18 AM
-
By Application Development in forum Java
Replies: 0
Last Post: 02-06-2004, 12:19 AM
-
By Application Development in forum Java
Replies: 0
Last Post: 02-06-2004, 12:19 AM