Kitura / BlueSocket

Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.
Apache License 2.0
1.41k stars 197 forks source link

Reading Less than SOCKET_MINIMUM_READ_BUFFER_SIZE? #217

Closed chigkim closed 1 year ago

chigkim commented 1 year ago

Is that possible for me to either change SOCKET_MINIMUM_READ_BUFFER_SIZE or read less than SOCKET_MINIMUM_READ_BUFFER_SIZE? If I allocate only 4 bytes of Data and read from it, what happens if you read more than 4 bytes?

chigkim commented 1 year ago

In case someone has the same question.

let buf = 256
var p = UnsafeMutablePointer<CChar>.allocate(capacity: buf)
try socket.read(into: p, bufSize: buf, truncate:true)
let data = Data(bytes: p, count: buf)
p.deallocate()