Archived

This forum has been archived. Please start a new discussion on GitHub.

ICE calling a Single Threaded DLL

Hello.

Im trying to build an application with ICE that would only use a single instance of an Application. What I mean is that it should be able to accept connection from multiple clients but all the processes are going to be managed by one application. Hmmm. Lets put it this way.

1. Server starts, setup ICE initializations stuff, then creates a new instance of a VB DLL.
2. Client 1 connects and sends a string expecting a return parameter.
3. Server recieves the string and sends it to the VB DLL instance.
4. VB DLL returns a value and returns it to ICE server.
5. Ice Server returns the value to Client 1.
6. Client 2 connects and sends a string to the Ice Server.
7. Ice server recieves the string AND DOES NOT create a new instance of the VB DLL ... it will keep on using the current one.
8. VB DLL recieves the string ... but works on it for some time.
9. Client 1 sends another string to the Ice server.
10. ICe Server recieves Client 1's string but waits till the VB DLL is finished with Client 2's command.
11. VB DLL is finishes with the Client 2's command and returns a value.
12. Ice Send the string back to client 2.
13. Ice now sends the string to VB DLL.
14. Client 2 recieves the value and is Happy.
15. VB Dll Receives the string ,work on it and return result.
16. Ice Server returns result to Client 1.
17. Client one recieves result and is Happy.

I have made a slice definition for this and I'm already working on the client and server codes for the VB DLL interaction.
interface jSockets
{
string jclCommand(string command);
};

I fear that, since I don't understand ICE full yet (I just read the docs), I might be missing some crucial stuff. So anybody has suggestions or reminders related with this endeavor?

Thanks.

Alex

Comments

  • marc
    marc Florida
    Ice does not create any DLLs. So it's up to your code to load one or several DLLs.

    If you want to avoid that your code is called by multiple threads, you have two possibilities:
    1. You can simply set the server side thread pool size to one. Then only one thread will call operations on Ice objects.
    2. You can add mutex protection to your operations, so that only one thread can enter them.
  • Hello Marc,

    The server will be calling either an EXE or a DLL through OLE automation. I'm actually having some trouble with converting char* to ::std::string right now.

    Considering my C++ skills, I think that the first one is the best option for me.

    So, how do I set the server side pool to 1?

    Thanks.

    Alex
  • marc
    marc Florida
    That's described in the manual. Just set the property Ice.ThreadPool.Server.Size to 1.
  • Thats great since its only as simple as setting a property. :)

    Thanks. I'll try it ASAP.

    Alex
  • I'm a bit embarrased to ask but I couldn't make this work.

    First off, the documentation states that:
    Ice.Config

    Synopsis
    --Ice.Config --Ice.Config=1 --Ice.Config=config_file

    Description
    This property must be set from the command line with the --Ice.Config, --
    Ice.Config=1, or --Ice.Config=config_file option.
    If the Ice.Config property is empty or set to 1, the Ice run time examines the contents of the ICE_CONFIG environment variable to retrieve the pathname of a configuration file. Otherwise, Ice.Config must be set to the pathname of a configuration file. (Pathnames can be relative or absolute.) Further property values are read from the configuration file thus specified.

    So I created a file called jSockets.cfg and put in the following entry:
    // Make sure that were using only a single server thread
    Ice.ThreadPool.Server.Size = 1

    I initially thought that all I have to do is update the slice2cpp script to include the option as described above. It didn't work. I tried again by updating the C++ command line parameters ... didn't work too.

    So how do I do this?

    Thanks.

    Alex
  • bernard
    bernard Jupiter, FL
    Hi Alex,

    Yes, we need to add more details on the configuration in the documentation!

    The --Ice parameters must be passed to the Ice::initialize() function, for example:

    int main(int argc, char* argv[])
    {
    Ice::CommunicatorPtr communicator = Ice::initialize(argc, argv);
    //...
    }

    If you want to use the config file jSockets.cfg, you would use:
    program --Ice.Config=jSockets.cfg

    If you initialize the communicator in a DLL, you may not be able to get the argc/argv from the main program; you can then either manufacture the argc/argv or (easier) use initializeWithProperties().

    Also note that properties such as the thread pool size affect the runtime behavior: pass them to your program, not slice2cpp!

    Best regards,
    Bernard
  • Hello Bernard,

    Thanks. I haven't thought of that. ;)

    Alex