Version 9 introduced the
WolframStreamsLibrary.h header for LibraryLink. It contains
What can I do with this header? How can I use these functions? Are the documented anywhere?
Update 2018 March: Partial spelunking results, someone else may want to pick up the trail.
Currently, my best guess is that this is for extending Mathematica with new streams. I believe it to be the analogue of
DefineOutputStreamMethod. The struct
MInputStream contains most of the functions that would be passed to
DefineInputStreamMethod. The actual analogue is
WolframLibray.h, which I believe sets the equivalents of the
NameTestFunction. My (unverified!) guesses for the parameters of
const char *name, same as
void (*ctor)(MInputStream, const char* msgHead, void* optionsIn), same as
"ConstructorFunction". Should fill out the
MInputStreamstruct passed to it. But in what format does it receive the options?
mbool (*handlerTest)(void*, char*), probably the same as
"NameTestFunction". But what is the
void *parameter for? The
void* methodData, possibly pointer to private data used by the stream implementation.
void (*destroyMethod)(void* methodData), possibly for freeing the
methodData? This is not the
There are still many key questions remaining before one could actually implement everything that is needed.
What is the
methodData? A state unique to each instance of the stream, or shared by all of them? (I assume this is shared, and the individual state is in the
MInputStream struct.) What exactly should each of these functions do?
An example implementation is woefully needed. After some more spelunking, I found one in
SystemFiles/Links/SocketLink/Source/C. This example may provide enough information for us to write our own implementation, but I have not yet had the time/motivation to do all this. I still wanted to share my findings with others who may be interested in continuing the spelunking.
Note that the SocketLink example won't answer all questions: it often passes
NULL pointers or simply ignores arguments (e.g the options in the constructor).