Re: MathLink portnumbers and internal types
- To: email@example.com
- Subject: [mg10981] Re: [mg10937] MathLink portnumbers and internal types
- From: John Fultz <firstname.lastname@example.org>
- Date: Sun, 15 Feb 1998 02:10:47 -0500
> I wish to have a process to communicate via mathlink peer to peer to a > remote computer. The problem is that I a start new mathlink > connections as needed from forked processes and I have found no way of > telling wich portnumber has been chosen. > > The problem will probably be solved if I knew how the internal mathlink > types MLINK (struct MLink) and MLENV (struct ml_environment) is > constructed, the info should be in them. I have searched the online > help, The Mathematica book and the mathlink tutorial. I have looked in > mathlink.h, mprep generated code and from the debugger. The simple > answer is that these types is hidden inside the libML.a library file. It would be bad to expose MLINK and MLENV to user tinkering. Implementational details of data types such as these are hidden to make it easier to keep MathLink source code compatible from one revision of Mathematica to the next. If programmers rely on internal knowledge of these structures, then the compatibility issue becomes a very difficult one. Much the similar philosophy is taken in many other API's; for example, the Win32 API similarly hides implementational details for handles to windows, device contexts, fonts, brushes, etc. The correct thing to do is to have an API whereby you can query the attributes of an MLINK or MLENV as required. There is, in fact, an API that queries the information you need from an MLINK pointer; if you look in mathlink.h, you'll see the following: /* MLName returns a pointer to the link's name. * Links are generally named when they are created * and are based on information that is potentially * useful and is available at that time. * Do not attempt to deallocate the name's storage * through this pointer. The storage should be * considered in read-only memory. */ MLDECL( kcharp_ct, MLName, ( MLINK mlp)); MLDECL( long, MLNumber, ( MLINK mlp)); MLDECL( charp_ct, MLSetName, ( MLINK mlp, kcharp_ct name)); So, MLName returns a const char * pointer to the linkname (i.e. "####@host" for a TCP connection). I think (but don't recall for certain) that MLNumber returns the actual socket number (for a TCP connection) from that. Incidentally, I agree that you shouldn't have to go mucking about in mathlink.h to try to get this information; unfortunately, I don't know of anywhere else where this particular information is documented. > I will be very grateful for any pointers! > > -- > /Stefan > email@example.com Sincerely, John Fultz firstname.lastname@example.org Front End Group Wolfram Research, Inc.