Move TCP connection away from Mac Network lib over to swift-nio enabling - #5
Conversation
| return decoded | ||
| } | ||
|
|
||
| private func readFrame(buffer: inout ByteBuffer) throws -> ByteBuffer? { |
There was a problem hiding this comment.
Not sure if I did implemented correctly frames decoding, but I left some comments here. Let me know how does it look.
This handler is mostly responsible for reading data and packaging them up into frames.
| send(data: greeting) | ||
| } | ||
|
|
||
| private func stateDidChange(to state: IBConnection.State) { |
There was a problem hiding this comment.
As this is not Network from MacOs we manage the state ourselves. Not sure if you want to do anything with it
| _ = channel.writeAndFlush(buffer) | ||
| } | ||
|
|
||
| public func receiveMessage(_ data: Data) { |
There was a problem hiding this comment.
This is being called, by our 2nd Handler that handles frames from the 1st handler. If that make sense.
and I understand we 1st need to get the initial frame after the greeting. otherwise we read data as usual
| import Foundation | ||
| import NIOCore | ||
|
|
||
| class IBMessageHandler: ChannelInboundHandler { |
There was a problem hiding this comment.
This is our massage handler, that simply converts frames in data and we pass them to our IBConnection
# Conflicts: # .DS_Store # .gitignore
|
To get us into same page i included your proposal as NIOClient etc into the dev branch. Hopefully didn't miss anything crucial. At the moment it seems to stuck at opening connection though and never reach connected state to write the greeting message. |
|
@stensoosaar |
|
@stensoosaar let me convert this PR into draft. Till I fix the connection so it is reliable. |
|
@stensoosaar PR ready for review :) connection is working!
|
| } | ||
|
|
||
| let lengthPrefix = buffer.getInteger(at: buffer.readerIndex, as: Int32.self)! | ||
| let frameLength = Int(lengthPrefix.littleEndian) |
There was a problem hiding this comment.
FYI:
I had error here, thought it is bigEndian, but it does appear to be littleEndian
| case initializing | ||
| case connecting(String) | ||
| case connected | ||
| case connectedToAPI |
There was a problem hiding this comment.
also added, state indicating we are connected to the API
|
Many thanks! Its working! One more thing though... Could you review the connection locking logic, as there seems to be outgoing message race between user requests and handshaking process... |


Move TCP connection away from Mac Network lib over to swift-nio enabling, by doing this we enable framework to work wherever Swift does. such as Linux, Windows, even server side.
@stensoosaar
I've tried to keep everything as you had with modifying the connection layer in most.
I haven't had a chance to test it with the IB as IU will get my access back after 15th next month. I'm counting here on your help.
I will leave comments below to address what I think is important.
Let me know what you think :)!