Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TCP connection away from Mac Network lib over to swift-nio enabling #5

Merged
merged 8 commits into from
Apr 25, 2024

Conversation

shial4
Copy link
Collaborator

@shial4 shial4 commented Apr 24, 2024

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 :)!

return decoded
}

private func readFrame(buffer: inout ByteBuffer) throws -> ByteBuffer? {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our massage handler, that simply converts frames in data and we pass them to our IBConnection

@stensoosaar
Copy link
Owner

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.

@shial4
Copy link
Collaborator Author

shial4 commented Apr 25, 2024

@stensoosaar
Yea, I've fixed it already. Pull the recent changes. Although it disconnects now when I try to send any message. Like subscribe to real time data

@shial4
Copy link
Collaborator Author

shial4 commented Apr 25, 2024

@stensoosaar let me convert this PR into draft. Till I fix the connection so it is reliable.

@shial4 shial4 marked this pull request as draft April 25, 2024 11:11
@shial4 shial4 marked this pull request as ready for review April 25, 2024 12:04
@shial4
Copy link
Collaborator Author

shial4 commented Apr 25, 2024

@stensoosaar PR ready for review :)

connection is working!

Screenshot 2024-04-25 at 10 04 57 PM Screenshot 2024-04-25 at 10 04 32 PM

}

let lengthPrefix = buffer.getInteger(at: buffer.readerIndex, as: Int32.self)!
let frameLength = Int(lengthPrefix.littleEndian)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.