[swift-server-dev] Draft proposal for TLS Service APIs (please review)
Michael Chiu
hatsuneyuji at icloud.com
Thu Mar 23 07:28:48 CDT 2017
> The disadvantage of Collection over Array (or UnsafePointer) is that there is not standardised way to quickly get a raw pointer to it, right? How would you efficiently grab the data, by iterating over the Collection? :-)
>
> Also, what you propose doesn’t actually work in Swift 3.0. Does it work in 3.1 or 4? (`error: cannot specialize non-generic type ‘Collection’`)
>
>> Like the followings:
>> func tlsWrite(buffer: Collection<UInt8>) throws
>> func tlsWritev(vectors: Collection<iovec>)
>>
>> If it is possible it will be very helpful since
>> 1) it is very swifty and user friendly
>> 2) vectorIO could significantly reduce the overhead to merge fragments of bytes into a single buffer.
>
> +1 on vectors.
>
> My headache with the design is that it doesn’t support async I/O (even if you don’t implement that right away, you could still design the API to support it). For read/write I would propose to match the GCD channel API.
>
> hh
>
Collection will never work since it is a generic protocol. But Collection<UInt8> will work.
I’m not quite sure if there’s way to write bytes into OpenSSL’s BIO, I guess it’s probably not, but if it’s possible we should be able to write bytes into the buffer directly.
An other alternative solution is to add an other layer of protocol, to force the type the collection contains must provide a method for raw byte access to the object it contains.
For example let’s say:
protocol RawBufferRepresentable {
func rawBuffer() -> (UnsafeRawPointer, Int)
}
And on the TLS side:
fun tlsWrite(contents: AnyCollection<RawBufferRepresentable>)
Or even
protocol IOVectorRepresentable {
func vectors() -> [iovec]
}
fun tlsWritev(vector: IOVectorRepresentable)
For vector IO, actually I started a project on DiscreteData type, which could theoretically archive zero copy (even on some writes) and reducing duplicated contents in the same buffer. The project is in very early stage but some fundamental feature is already working. Please check it out if interested. There should be still a lot of bugs, tho.
https://github.com/michael-yuji/DiscreteData <https://github.com/michael-yuji/DiscreteData>
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170323/76b62ba0/attachment.html>
More information about the swift-server-dev
mailing list