NozeIO / Noze.io

Evented I/O streams for Swift
http://noze.io
307 stars 11 forks source link

Draft UDP socket support, inspired by Node's dgram module #14

Closed lichtblau closed 7 years ago

lichtblau commented 7 years ago

Mostly functional UDP socket support.

Bit rough around the edges, but tests pass on Linux, and the new tests also seem to work on Darwin ("swift test" only, after deleting existing tests which don't work).

TODO: Updating the Xcode project for new sources and tests.

helje5 commented 7 years ago

I pushed that into the feature/dgram branch.

helje5 commented 7 years ago

I did a few changes, please review. I think I could merge that into develop that way though it would be kinda cool to have this as a proper stream first.

lichtblau commented 7 years ago

Thanks!

Node doesn't actually implement the dgram sockets as streams, does it? It sounds like a nice feature. There could be two different use cases:

One is a byte stream. This might make sense (only) in the specialized case where we would support the connect syscall, which instructs a UDP socket to only ever send data to a specific peer, and only accept that from that peer. So in practise it's for UDP clients, but not servers. Using connect is possibly a bit exotic, but BSD sockets offer it.

The other is to keep supporting the generic case. The objects being streamed would be "Datagram" pairs of bytes and peer -- in both directions though, both when sending and receiving.

Personally this is not a priority for me. I'd be happy to do any other cleanups required for merging though, if you can propose something.

helje5 commented 7 years ago

Node doesn't actually implement the dgram sockets as streams, does it?

Node does not (really) have streams of arbitrary types the way Noze.io has it. Technically it does have object streams, but only with one object at the time, making it kinda useless for real world usage (and AFAIK people hardly use byte streams in Node, let alone object streams ;-).

In Noze.io, if something emits same-or-similar typed objects, it almost always can and should be done as a stream as that offers so much extra l1337 (transforms, pipes, back-pressure, etc).

I can't follow you on the byte stream thing. UDP doesn't guarantee delivery order. An UDP stream should just deliver packets it receives. Packet ordering would be a thing a stream on top could do.

As mentioned I think it would be a Duplex<Datagram, [UInt8]>. The readable end would provide Datagram structs (sender-address + payload) while you would write payloads ([UInt8]) into it (the address is implicit in this case, right? Or not? Hm.)

Personally this is not a priority for me.

Never mind, this is a nice to have, not a must have. Probably going to merge into develop and possibly master tomorrow.

helje5 commented 7 years ago

Merged into develop. Will do master when Travis is through.