Hi,

I am playing with sockets in Pepsi.

I created a SocketAddress object since I fancied wrapping the C struct sockaddr_in directly.

I started...

SocketAddress : Object ( _address )

SocketAddress new
[
        self := super new.
        {
                struct sockaddr_in *address;
                address= (void*)_balloc(sizeof(struct sockaddr_in));
                if (address != NULL)
                {
                        address->sin_family= AF_INET;
                        self->v__address= (oop)address;
                        return (oop)self;
                }
        }.      
        ^self primitiveFailed
]

With a simple Socket object I have got to the point where I can read a few bytes from a web site.

Then I saw Float.st which treats v_self as a sizeof(double). That seemed neat so...

SocketAddress : Object ()

SocketAddress _sizeof { return (oop)sizeof(struct sockaddr_in); }

SocketAddress new
[
        self := super new.
        {
                ((struct sockaddr_in *)self)->sin_family= AF_INET;
        }.
]

Is this a safe thing to do with v_self? I've been looking through the C code to try to work out how the size/allocation of the object works, the position of the vtable etc. If it is safe, how does it work?

Also, I noticed that SmallInteger does something similar e.g. (int) v_self >> 1 but Character is defined in terms of its value slot: Character : Magnitude ( value ). Is this because Character is intended to reuse the integer behaviour in its value slot? i.e. accessing v_self in Character could work but would be duplication of the C code in SmallInteger or is there a another reason?

I'm really just trying to get a feel for good style in this area. Any advice appreciated.

Thanks,

Mike

Attachment: Socket.st
Description: Binary data

Attachment: SocketAddress.st
Description: Binary data

Attachment: SocketAddress.st.orig
Description: Binary data

_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to