Why?

Dave Cragg dcragg at lacscentre.co.uk
Tue Oct 5 09:58:48 EDT 2004


On 5 Oct 2004, at 14:37, Frank D. Engel, Jr. wrote:

> Okay, so I got tired of waiting for RevDB to be fixed for PostgreSQL 
> (or for some explanation of how to set it up, in case my drivers are 
> not correctly positioned), so I am trying to write my own, 
> Transcript-native PostgreSQL driver for Rev (with its own API, by 
> means of a 'start using' command...)  Never tried this before, but I 
> did get the 'start using' to work.
>
> I *think* I was able to get sockets working, too, but for some reason, 
> at least under OS X, I cannot seem to read from a socket.  What am I 
> doing wrong here?  I have the following handler in my code:
>
> function pgFetchMessage
>   read from socket pg_sock for 5
>   put it into x
>   put (charToNum(char 2 of x) * 16777216) + (charToNum(char 3 of x) * 
> 65536) + (charToNum(char 4 of x) * 256) + charToNum(char 5 of x) \
>       into l
>   read from socket pg_sock for l
>   put it into z
>   answer charToNum(the first char of x) titled (pg_sock) && (the 
> length of x)
>   return (x & z)
> end pgFetchMessage
>
>
> The "answer" line results in the following title bar (empty message):
>
> localhost:5432 0
>
> Why would this happen?  That "0" means that the length of string "x" 
> (which should contain exactly five characters, right?) is zero.  In 
> other words, that string is empty -- but it shouldn't be!
>
It could be that there is no data on the socket when you do the read.  
You could try replacing the "read from socket pg_sock for 5" with this:

put empty into x
repeat while length(x) < 5
   read from socket pg_sock for 5 - length(x)
   put it after x
end repeat

Or, use the "with message" form of read, which I find to be more 
reliable, However, you'd have to change the structure of your handler  
a little.

Cheers
Dave



More information about the use-livecode mailing list