unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mike Gran <spk121@yahoo.com>
To: "mark@markwitmer.com" <mark@markwitmer.com>,
	"guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Trouble w/sockets
Date: Sat, 2 Mar 2013 20:48:45 -0800 (PST)	[thread overview]
Message-ID: <1362286125.99740.YahooMailNeo@web120403.mail.ne1.yahoo.com> (raw)
In-Reply-To: <871ubxxie3.fsf@markwitmer.com>

> From: "mark@markwitmer.com" <mark@markwitmer.com>

> (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	other threads:[~2013-03-03  4:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-03  3:38 Trouble w/sockets mark
2013-03-03  4:48 ` Mike Gran [this message]
2013-03-03  5:36   ` mark
2013-03-03  6:35     ` Mike Gran
2013-03-03  7:29     ` Thien-Thi Nguyen
2013-03-04  4:18       ` mark.d.witmer
2013-03-04  4:38         ` mark.d.witmer
2013-03-04 10:02         ` Thien-Thi Nguyen
2013-03-03 10:36   ` Chris Vine
2013-03-04 13:29     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362286125.99740.YahooMailNeo@web120403.mail.ne1.yahoo.com \
    --to=spk121@yahoo.com \
    --cc=guile-user@gnu.org \
    --cc=mark@markwitmer.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).