pkg: provide sock_tcp support for lwip#5938
Conversation
9e404f6 to
6aeaf16
Compare
|
But just rebased for now, since #5923 was merged. |
|
Not time, sorry. |
|
Adaption to #6137 (comment) also needed... |
6aeaf16 to
2cc62bd
Compare
|
Provided the same treatment to this PR as I did for #5937. |
|
Ping? |
|
Not WIP any more? |
|
Yapp. |
|
Not sure I'm the best person to review this since I haven't used sock so far. |
|
I'll add @smlng as our resident TCP expert ;-) |
|
(also I would suggest to first review and merge |
|
Rebased to current master |
|
From #5937 (comment):
The phytec board issue is due it not being included in lwIP's auto-init routine yet (which was not possible due it not being netdev2 before #6453 was merged). This is more about fixing #4672 (or, as a workaround, writing a custom initialization routine for that device in |
|
Oops wrong PR 😄 |
|
I think this PR needs to be rebased since Jenkins spotted some errors about timex.h constants being changed. |
|
There was no change to master since my last rebase, so a rebase won't change that. |
|
I need however adapt this PR for #6399 |
|
That was what I meant. |
|
Done |
|
@smlng ping? |
|
@miri64 sorry, busy ... However, Jenkins founds ram overflow for board |
|
it was renamed in #6417. Fixed. |
smlng
left a comment
There was a problem hiding this comment.
See comments. In general: there is a lot of if .. else and switch .. case madness in pkg/lwip/contrib/sock/lwip_sock.c. I tried to untangle all cases, but I got lost at some places.
pkg/lwip/contrib/sock/lwip_sock.c
Outdated
| #if LWIP_TCP | ||
| else if (tmp->type & NETCONN_TCP) { | ||
| err = netconn_write_partly(tmp, data, len, 0, &written); | ||
| if (err == ERR_OK) { |
There was a problem hiding this comment.
this is duplicate code, same is done below in switch
pkg/lwip/contrib/sock/lwip_sock.c
Outdated
| } | ||
| #if LWIP_TCP | ||
| else if (tmp->type & NETCONN_TCP) { | ||
| err = netconn_write_partly(tmp, data, len, 0, &written); |
There was a problem hiding this comment.
can't you reuse res instead of introducing an addition var with written? As far as I see, you set res = written anyway afterwards?!
There was a problem hiding this comment.
Mh… this might lead to overflows, but that is also true for the current way of handling => will adapt.
| int res; | ||
| assert(sock != NULL); | ||
| mutex_lock(&sock->mutex); | ||
| if (sock->conn == NULL) { |
There was a problem hiding this comment.
could be simplified to
int res = 0;
if (!sock->conn || lwip_sock_get_addr(sock->conn, (struct _sock_tl_ep *)ep,0)) {
res = -ENOTCONN;
}
mutex_unlock(&sock->mutex);
return res;
There was a problem hiding this comment.
Will do, but I prefer sock->conn == NULL over !sock->conn since it does not mix boolean operations with pointer checks
|
|
||
| assert(queue != NULL); | ||
| mutex_lock(&queue->mutex); | ||
| if (queue->conn == NULL) { |
| res = -1; | ||
| break; | ||
| } | ||
| if (res == 0) { |
There was a problem hiding this comment.
look like this could or should go into the ERR_OK case above?
| return -EAGAIN; | ||
| } | ||
| } | ||
| else if (timeout != 0) { |
There was a problem hiding this comment.
so actually else should suffice here
|
btw. I still need to test this |
|
Adressed |
|
I just tested with RIOT native and However, I think the test application needs work - lots of code duplication ... |
smlng
left a comment
There was a problem hiding this comment.
In general the test application is quite long, which is good as it covers many cases. However, it also makes it hard to read and many functions could be merged to avoid code duplication. For instance everything exists twice for IPv4 and IPv6, and further: many function only differ only in an argument used e.g. with or w/o port defined and so on.
And I'm unsure if everything works as expected (see comments), because the subtasks do not reset all settings to start from scratch.
| _server_addr.port = _TEST_PORT_REMOTE; | ||
| _server_addr.netif = SOCK_ADDR_ANY_NETIF; | ||
|
|
||
| msg_send(&msg, _server); /* start server on _TEST_PORT_REMOTE */ |
There was a problem hiding this comment.
I think this won't do anything, as the server is started above in L156 already and wasn't stopped in between.
There was a problem hiding this comment.
The server is stopped in the tear_down() function which is called in between tests.
| msg_t msg = { .type = _SERVER_MSG_START }; | ||
|
|
||
| _server_addr.family = AF_INET; | ||
| _server_addr.port = _TEST_PORT_LOCAL; |
There was a problem hiding this comment.
Will this setting be applied, the server is already running, hence, no changes will be made to its settings and port will stay _TEST_PORT_REMOTE, or not?
This seems to be the general nature with these kind of unittest-like test. Furthermore, this is also true for the |
|
@miri64 sure reworking and unifying the tests seems reasonable, but also a task (or multiple) for future PR(s). So I'm fine with postponing this, but what about my other comments, regarding (re)starting the TCP server process, which IMO does not work as it should, or am I mistaken? |
|
Those came after I wrote the comment, but before I hit "Comment" (which took me several hours 😊) |
|
Will look into them |
|
@miri64 ah damn, oversaw the BUT: we should remember (make a knot somewhere), that the tests should be made more readable and without that much code duplication. |
These knots are called issues in GitHub :P |
0165af7 to
b915d15
Compare
|
|
See #6596 |
This was taken out of #5802 and only provides the
sock_tcppart and the tests for it.This contains duplicate changes to #5936, so merging any of these might require rebase.
Depends on
#5923(merged).