Hi,

In a nutshell: how do I read binary data from a socket with socket,
get_byte et al ?

I have written a Redis client (against 2.8) which is fully functional and
ready to release but I have been writing test cases for as many of the
commands as I can without going mad on it and when I use the DUMP command
it barfs. Here is the session:

| ?- [gpredis].
compiling /home/sean/tmp/gnu-prolog-redis-client/gpredis.pl for byte code...
/home/sean/tmp/gnu-prolog-redis-client/gpredis.pl compiled, 192 lines read
- 16073 bytes written, 17 ms

(4 ms) yes
| ?- redis(set(gnu_prolog, 'Is awesome!')).
STATUS: OK

yes
| ?- redis(get(gnu_prolog)).
STRING: Is awesome!

true ?

yes
| ?- redis(dump(gnu_prolog)).
uncaught exception: error(representation_error(character),get_code/2)
| ?-

The problem is that I am opening the socket like this:

redis_connect(Conn) :-
redis_connect(Conn, localhost, 6379).

redis_connect(redis(SI, SO, S), Host, Port) :-
socket('AF_INET', S),
 socket_connect(S, 'AF_INET'(Host, Port), SI, SO),
* set_stream_type(S, binary).  %% added to see if I could fix it but no
dice so far!*

and then I use *get_code/2* everywhere. That seemed like a good idea
initially because redis deals with strings but they are binary safe and
this obviously isn't, I can cope with that if I can figure out how to do it
with set_stream_type/. open/3,open/4 allow the mode to be set but how do I
coerce a socket into binary mode with GNU Prolog?

Somewhere in there I need to force it into binary mode but it being Friday
and all I can't seem to figure it out...I am really keen to release this
project to GitHub but I refuse until I am happy with it!

My client* handles all redis commands* by de-constructing the term passed
into the redis() predicate, output to the console but the redis_do()
predicate passes back the results. Once I have this issue solved it will be
a matter of days to complete and release it so any assistance would be
appreciated. I will probably crack it tonight myself but I am at work and
thought I would look into it at lunchtime! This is my first "useful" bit of
Prolog (well, useful to me so far!) and I am keen to complete it *and*
understand it.

:)

Thanks,
Sean.
_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to