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
Allow passing net.PacketConn #24
Conversation
Also the tests should pass... |
https://github.com/xtaci/kcp-go/pull/24/files#diff-801d2c9dc8234c70b6c954d643436df1R105 |
Current coverage is 85.04% (diff: 84.61%)@@ master #24 diff @@
==========================================
Files 6 6
Lines 1427 1431 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1206 1217 +11
+ Misses 171 160 -11
- Partials 50 54 +4
|
What about BlockCrypt? |
Judging at the old code, block can be reused. |
newFEC in ListenWithOptions may fail and l.fec may be nil, also accessing member of member is really awful. |
I'll add a copy method, and use that |
That sadly won't happen for another 2 weeks as I am goijg away on hiliday. |
have a good holiday |
Actually, found a few minutes to add it, before I depart. |
Sure, and why is that wrong? |
the result will be different between the following:
|
Sure, but what you'd expect to happen? |
I would prefer a consistent behavior,without worrying about the sequence of parameters. |
This method is somewhat internal hence why I think we can allow it to be inconsistent, yet I guess we would then have to limit possibility from the client API. |
I think simplify by taking parameters out of *Listener would be enough. |
Yet that doesn't prevent people from providing multiple instances of fec and so on, so I think it's a moot problem we are trying to solve, and people who misuse the api can face the consequences. |
So I am back. |
I think raddr & net.PacketConn parameters in Dial function are semantically conflicted, |
No, they are not conflicting, as one is providing where to dial, and the other one provide via what to dial, which is exactly the case here that is needed for stun. |
please make another PR for this, this branch has conflicts. |
I can just rebase this PR |
ok cool |
rebased |
found another problem:
if you pass in a conn and s.l == nil, how can i tell the conn has Write method? |
Took me a while to understand the question. The reason it works in my specific case is because my net.PacketConn has a wrapper that deals with that, but you are right, it won't work in the generic case. Can we remove the writeTo wrapper and use WriteTo everywhere instead? |
Write/WriteTo has different cost in syscall, Write() in UDP is about 4 times faster than WriteTo(). Low-end router devices benefit a lot from connected UDP. |
Sure, so do you have any suggestions? |
it's really a hard problem, I think to make a new PacketConn interface may solve this. |
As in ConnectedPacketConn { ? |
I mean some wrappers, the caller should bind Write() method to conn.Write() or conn.WriteTo() |
Can you elaborate? I am not sure I understand what you mean. |
we do not need this method, we just wrap the connected UDP
|
Oh so you mean do the wrapping internally in the lib for connections we know are connected? |
exactly, callers know this. |
Great idea. I'll do this tonight hopefully. |
Added the wrapper. Made it public as others might have use-cases for it too. |
good job. |
@AudriusButkevicius see the latest commit: NewConn + ServeConn, is this good ? |
I thiink yhe API is now much worse, as there are two functions which are not obvious why are they there for, and yet we still have the Options mess convoluted in some functions. Anyways that will be good enough for my usecase tho. |
opts are mess, i think i 'll remove that. net.UDPConn is a special case of PacketConn. Provided as a default. |
So the API is still compatible, yet I am able to pass a connection in to perform NAT traversal.