[m-dev.] Socket Library

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Oct 20 23:24:39 AEDT 2010


Hi,

On Wed, 20 Oct 2010, Daniel Waterworth wrote:

>>> I would recommend using an exported enumeration to return the result
>>> status.  Passing small integers back and forth over the foreign language
>>> interface tends to lead to less maintainable code IMO.
>>>
>> I agree with that point, exported enumerations are a nice way to do
>> that.  They didn't exist when I wrote most of my interfaces.

...

> So it seems the best way to throw error conditions is for the C code
> to return an item from an exported enumeration and for the mercury
> code to output a stream.result(socket_error) where socket_error is the
> aforementioned enumeration. I will implement this now.

Another (similar) approach would be to map the error codes in C onto
an enumeration in Mercury using a foreign_enum proc.

...

> One last question. I've been using the string type to store data, this
> isn't ideal as it is null terminated, is there a more appropriate
> type? Or will the string type in the future be implemented as a
> bytestring?

A more appropriate type to use is the stdlib's bitmap type.  (Although,
examples of its use in C code are a little thin on the ground.)

Julien.


More information about the developers mailing list