On Thu, 28 Nov 2013 21:44:15 -0500, Etienne wrote:

On 2013-11-28 20:55, Shammah Chancellor wrote:

On 2013-11-28 19:21:31 +0000, Etienne Cimon said:

Does libevent take care of the byte order in tcp requests?

No. Use network byte order. What are you trying to do?

I'm using postgresql in my project and I chose to rewrite the ddb
postgresql native connector to use vibe.d's TCPConnection and be able to
yield. I need it to run LISTEN/NOTIFY commands on active websockets and
I also thought of a long term project to create a MemoryStore /
SessionStore around it because it has some good caching abilities too.

So I'm thinking of building on this:
https://github.com/pszturmaj/ddb/

I fixed most of the bugs but it uses a stream.read(ref out) function to
consume data. I might have to replace it's general use of
std.socketstream read/write functions with consume!T() and sendCmd(),
and rethink the structure around that. I don't know how similar MySQL is
to the frontend/backend api of pgsql. It sucks that I don't have a
similar read function to work with but it's good to know the hton() are
there and used in vibe's tcp library.

Does this look interesting to you?

Yes, htonX can be used without issues (std.bitmanip.bitEndianToNative might be more efficient, but that's a different topic). So looking at the code, I would go about implementing this by replacing class PGStream : SocketStream { with

class PGStream {
    private {
        version (Have_vibe_d) TCPConnection stream;
        else SocketStream stream;
    }

and then for each type instead of

override void write(int x)
{
    super.write(hton(x));
}

do

void write(int x)
{
    stream.write(nativeToBigEndian(x));
}

that should work for both types of stream, because nativeToBigEndian returns a byte array, and have the same effect. Then there is only PGConnection.getMessage which reads the message length, where int len; stream.read(len); len = ntoh(len) - 4; needs to be replaced by ubyte[4] lenbytes; stream.stream.read(lenbytes[]); auto len = bigEndianToNative!int(lenbytes) - 4;.

I think that should be about all.