vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

add `C7.Stream` support #36

Closed tanner0101 closed 8 years ago

tanner0101 commented 8 years ago

Adding C7 Stream support would allow people to easily import Socks and plug it into their existing Stream code.

If this is something @czechboy0 thinks should be included in Socks, it should be pretty easy.

extension Socks.TCPClient: Stream {
    public enum Error: ErrorProtocol {
        case unsupported
    }

    public var closed: Bool {
        return socket.isClosed
    }

    public func send(_ data: Data, timingOut deadline: Double) throws {
        try send(bytes: data.bytes)
    }

    public func flush(timingOut deadline: Double) throws {
        throw Error.unsupported
    }

    public func receive(upTo byteCount: Int, timingOut deadline: Double) throws -> Data {
        let bytes = try receive(maxBytes: byteCount)
        return Data(bytes)
    }
}

This would also rely on #35 since C7 stream includes a closed property.

czechboy0 commented 8 years ago

Actually, I'd prefer to hold off on adding C7 as a dependency here until we have a bit more we get out of it (especially nowadays when I frequently get a conflict of C7 versions high up the dependency tree, so until things stabilize a bit I'd prefer to hold off).

I hope it's not too much trouble for Vapor to include this extension in your repo for now and I expect to add this later down the line when there aren't new versions of C7 being released so often.

tanner0101 commented 8 years ago

As long as #35 is solved in a way that doesn't create conflicts with C7.Stream (basically using var closed: Bool) then it's totally fine to hold off on C7 support inside of Socks.