guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble w/sockets


From: Mike Gran
Subject: Re: Trouble w/sockets
Date: Sat, 2 Mar 2013 20:48:45 -0800 (PST)

> From: "address@hidden" <address@hidden>

> (for-each      
>   (lambda (b)
>     (write-char (integer->char b) sock))
>       '(108 0 11 0 0 0 18 0 16 0 0 0 77 73 84 45 77 65 71 73 67 45 67 79
>       79 75 73 69 45 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 243 236 56
>       103 158 249 237 124 101 131 158 31 63 251 239 7 0 0 0 0 0 0 0 0 0
>       0 0 0 0 0 0 0))
> 
> This will obviously be the wrong authentication data for anyone else's X
> server; however, even if X closes the socket prematurely (not that it's
> supposed to, but it might), Guile shouldn't just crash, should it?

Crash? Or throw an error?  I definitely shouldn't crash, but, I could see
how it could throw an error on Guile 2.0.

The problem with `write-char' in Guile 2.0 is that it does all the
conversion to the current locale.  So, once you start hitting the bytes
greater than 127 in your string, `write-char' tries to convert each
byte to something in your encoding.

If your encoding is "C" or anything that strictly uses ASCII as its
character encoding, it'll throw an error when its trying to print any
byte above 127.  If your encoding is UTF-8, those high bytes will become
two byte strings.

Ideally you'd be able to use bytevectors or binary ports or some such.

But you can also fake it by setting the port encoding to ISO-8859-1.
In that encoding the characters 0 to 255 map one-to-one with the bytes
from 0 to 255.
(set-port-encoding! sock "ISO-8859-1")

Hope this helps,

Mike




reply via email to

[Prev in Thread] Current Thread [Next in Thread]