← Back to team overview

ooc-dev team mailing list archive

StreamSocket API overhaul

 

I'm currently overhauling the StreamSocket API, and it's come quite far.
This:

socket := ServerSocket new()
ai: InAddr

match(inet_pton(AddressFamily IP4, "0.0.0.0", ai&)) {
    case -1 =>
// Check errno, it should be set to EAFNOSUPPORT
"Invalid address family (?)." println()
    case 0 =>
// src does not contain a character string representing a valid network
address in the specified address family.
"Invalid network address." println()
    case 1 =>
// Success!
"Success!" println()
}

addr := SocketAddressIP4 new(ai, 8000)
socket bind(addr)
socket listen(100)

while(true) {
    conn := socket accept()
    writer := conn writer()
    writer write("<html><body>Hello, from the ooc socket
world!</body></html>")
    conn close()
}

is now this:

socket := ServerSocket new("0.0.0.0", 8000)

while(true) {
    conn := socket accept()
    conn out write("<html><body>Hello, from the ooc socket
world!</body></html>")
    conn close()
}

I'm honestly quite impressed, there's a few more kinks to work out (namely
`conn in` basically makes rock scream and writhe in pain for no apparent
reason and StreamSocketReader acting oddly).

The current implemented ideas are at: https://gist.github.com/661903
I'm working on allowing you to use `conn out` (implemented) and `conn in`
(implemented, but see aforementioned "kinks") instead of creating your own
StreamSocketWriter and StreamSocketReader respectively.

Any more ideas for the ServerSocket API?


Also, if someone could toss me some more advanced code using StreamSocket so
I could look for potential areas to improve upon and/or make more nicely
aligned with the ServerSocket API, that'd be great!

---

Nick Markwell
http://duckinator.net - personal website
http://blog.duckinator.net/ - blog
http://github.com/RockerMONO/ - software projects
http://gallery.duckinator.net/ - photo gallery
nick@xxxxxxxxxxxxxx