Proposed changes on sock TCP interface#29
Proposed changes on sock TCP interface#29brummer-simon wants to merge 1 commit intomiri64:gnrc/feat/sockfrom brummer-simon:gnrc/feat/sock
Conversation
|
Closed on purpose? |
| * @return -ENOMEM, if the system was not able to allocate sufficient memory. | ||
| */ | ||
| typedef struct sock_tcp_queue sock_tcp_queue_t; | ||
| int sock_tcp_init(sock_tcp_t *sock); |
There was a problem hiding this comment.
I don't see, why this function can't be merged with _connect/_listen (you could still define a function internally if you want to save code size ;-))
|
Okay … now I'm confused: How would you listen and except a connection request with this API? And how would you implement a socket wrapper? |
| * @param[in] sock A TCP sock object. | ||
| */ | ||
| void sock_tcp_stop_listen(sock_tcp_queue_t *queue); | ||
| void sock_tcp_release(sock_tcp_t *sock); |
There was a problem hiding this comment.
Again: don't see why this can't be done in _disconnect...
There was a problem hiding this comment.
It can be done in disconnect, but in a case where you open and close connection in a loop(default vor basicly every server) there must be memory allocated and freed with each loop. By seperating adding and release function, this behavrior can be avoided.
|
On the Socket Wrapper: Actually this could be a problem. On accepting a passive connection: The server would call connect with a Port to listen on, given in the local endpoint. The Function call blocks until a connection has been established (until a peer tries to connect to that port). |
|
I'll aim for an processing logic like this: sock_tcp_init(sock); Instead of: while(true){ To avoid multiple receive buffer allocation and freeing inside the packet buffer. I'd prefer to allocate a buffer a single time and reusing it instead of allocation and freeing with each loop. |
|
But with sock_tcp_listen(queue);
while(true) {
sock_tcp_accept(queue, &sock);
/* Do things */
sock_tcp_disconnect(sock);
}
sock_tcp_stop_listen(queue); |
If it is actually a lot faster, consider adding a receive buffer cache (shudder) to tcp_queue_t. |
|
Also: how to handle multiple incoming connection requests with this? |
|
@brummer-simon are you using the mbox mod for netreg (RIOT-OS#5526) or the vanilla netreg? I think using it would simplify things for you a lot, too. |
|
@brummer-simon Did you see any actual performance degradation due to de/reallocating a receive buffer? |
|
By having multiple threads waiting for an incomming connection. The only problem with that: If you want to accept multiple connections and process a single one at a time. This would not be possible. In the server case: you could handle avoiding freeing and allocating with listen and stop listen. In a client case that doesn't work. By introducing the init and release call it would be a unified way for server and clients. @ Kaspar: The performance is not the problem but allocating and freeing with multiple connections leads to framentation. In my bulk testing after few hundred connections the pktbuf is not able to find a fitting place for a receive buffer anymore and my test breaks ... |
Maybe @miri64 can elaborate what malloc algorithm pktbuf is using and how it tries to defeat fragmentation. |
It uses first fit. There is no fragmentation prevention, because up until now we assumed there was no use-case that could produce it. Maybe we need a special TCP-pktbuf? |
shudder Maybe just make a sufficiently large buffer part of sock_tcp_t? |
|
I'll trief that, with a mss of 1220 Bytes the size struct breakes the Am 23.08.2016 12:46 nachm. schrieb "Kaspar Schleiser" <
|
|
with a mss of 1220 Bytes the size struct breakes the
platforms stack size.
Don't allocate the queue on stack.
|
|
I'll still think the easiest Solution might be just reusing the sucessully The Problem with the external buffer is that the Buffer must be allocated All in All i would prefer the init and release Function and reusing Am 23.08.2016 12:49 nachm. schrieb "Simon Brummer" <
|
|
@ Kaspar: True don't allocate on stack is a possibility but this is Am 23.08.2016 1:06 nachm. schrieb "Simon Brummer" < I'll still think the easiest Solution might be just reusing the sucessully The Problem with the external buffer is that the Buffer must be allocated All in All i would prefer the init and release Function and reusing Am 23.08.2016 12:49 nachm. schrieb "Simon Brummer" <
|
This might be the easiest solution for your implementation together with |
|
So you Go with move the Buffer into the struct and allocate sock_tcp_t Am 23.08.2016 1:18 nachm. schrieb "Kaspar Schleiser" <
|
Well, there are other options:
|
Why shudder? The pktbuf-API was always conceived to allow for adapted implementations for the use-case. For pure UDP the current implementation is optimal so
It is not broken for that use-case, so what is there is no need to fix it. If it does not fit another use-case, I don't see why we should meddle with something that isn't broken. |
|
TCP is so complex anyway. A little extra bytes of code for fragmentation prevention do not hurt there (even if you use UDP with that buffer), but they might for pure UDP. |
|
For pure UDP the current implementation is optimal
;)
|
Here are my proposed changes on the sock TCP interface. Again sorry for the late addition.