Kitura/BlueSSLService

Socket does not write until data is read

manoelfd opened this issue · 2 comments

On iOS, when connected with TLS, if there is a read pending (i.e., it's waiting for data), and I attempt to write data to the socket, the socket will not actually writing anything until something is read. There are no errors when writing to the socket.

The code I'm using to connect:

let configuration = SSLService.Configuration() 
socket.delegate = try SSLService(usingConfiguration: configuration)
try socket.connect(to: "...", port: 1337)

Everything works fine if I don't connect with TLS. I tried other libraries and this doesn't occur, so it seems to be an issue with BlueSSLService (and not the server).

Upon further investigation, it seems that this is intentional. The SSLReadWriteDispatcher is a serial queue that is used to dispatch read and write operations. Does anyone know the reason for this? Would it be safe to remove?

SSLReadWriteDispatcher is intended to serialize the read/write calls to allow for synchronous read/write calls. For async usage, try calling try socket.setBlocking(mode: false) once created. You'll likely have to buffer your reads yourself if you do this.