Skip to content

pkg: provide sock_tcp support for lwip#5938

Merged
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:pkg/feat/lwip-sock-tcp
Feb 13, 2017
Merged

pkg: provide sock_tcp support for lwip#5938
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:pkg/feat/lwip-sock-tcp

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Oct 12, 2016

This was taken out of #5802 and only provides the sock_tcp part and the tests for it.

This contains duplicate changes to #5936, so merging any of these might require rebase.

Depends on #5923 (merged).

@miri64 miri64 added Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: pkg Area: External package ports State: waiting for other PR State: The PR requires another PR to be merged first labels Oct 12, 2016
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 31, 2016

Needs adaptation to #5945 edit: and #6114.

@miri64 miri64 force-pushed the pkg/feat/lwip-sock-tcp branch from 9e404f6 to 6aeaf16 Compare November 5, 2016 09:27
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 5, 2016

But just rebased for now, since #5923 was merged.

@miri64 miri64 added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Nov 5, 2016
@kaspar030 kaspar030 assigned OlegHahm and unassigned kaspar030 Nov 18, 2016
@kaspar030
Copy link
Copy Markdown
Contributor

Not time, sorry.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 18, 2016

Adaption to #6137 (comment) also needed...

@miri64 miri64 force-pushed the pkg/feat/lwip-sock-tcp branch from 6aeaf16 to 2cc62bd Compare November 29, 2016 19:56
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 29, 2016

Provided the same treatment to this PR as I did for #5937.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 13, 2017

Ping?

@OlegHahm
Copy link
Copy Markdown
Member

Not WIP any more?

@miri64 miri64 removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jan 13, 2017
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 13, 2017

Yapp.

@OlegHahm
Copy link
Copy Markdown
Member

Not sure I'm the best person to review this since I haven't used sock so far.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 13, 2017

I'll add @smlng as our resident TCP expert ;-)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 13, 2017

(also I would suggest to first review and merge sock_udp or sock_ip, since it would reduce the number of lines in this PR)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

Rebased to current master

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

From #5937 (comment):

On a phytec board I don't get an IPv6 address. ps() crashes the node but this is probably an issue of #6372.

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 lwip_bootstrap()) than about this specific application. Might be that the crashing of ps() is related to that, but I don't have a PhyTec board at hand to test.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

Oops wrong PR 😄

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Feb 8, 2017

I think this PR needs to be rebased since Jenkins spotted some errors about timex.h constants being changed.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

There was no change to master since my last rebase, so a rebase won't change that.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

I need however adapt this PR for #6399

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Feb 8, 2017

That was what I meant.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2017

Done

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 10, 2017

@smlng ping?

@smlng
Copy link
Copy Markdown
Member

smlng commented Feb 10, 2017

@miri64 sorry, busy ... However, Jenkins founds ram overflow for board nucleo32-f042 in tests/lwip_sock_tcp -> add to insuff mem list?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 10, 2017

it was renamed in #6417. Fixed.

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

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.

#if LWIP_TCP
else if (tmp->type & NETCONN_TCP) {
err = netconn_write_partly(tmp, data, len, 0, &written);
if (err == ERR_OK) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is duplicate code, same is done below in switch

}
#if LWIP_TCP
else if (tmp->type & NETCONN_TCP) {
err = netconn_write_partly(tmp, data, len, 0, &written);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can't you reuse res instead of introducing an addition var with written? As far as I see, you set res = written anyway afterwards?!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could be simplified, see above

res = -1;
break;
}
if (res == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

look like this could or should go into the ERR_OK case above?

return -EAGAIN;
}
}
else if (timeout != 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so actually else should suffice here

@smlng
Copy link
Copy Markdown
Member

smlng commented Feb 10, 2017

btw. I still need to test this

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 10, 2017

Adressed

@smlng
Copy link
Copy Markdown
Member

smlng commented Feb 13, 2017

I just tested with RIOT native and netcat from host -> success. My test app is here.

However, I think the test application needs work - lots of code duplication ...

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

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 */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this won't do anything, as the server is started above in L156 already and wasn't stopped in between.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The server is stopped in the tear_down() function which is called in between tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(see l. 69)

msg_t msg = { .type = _SERVER_MSG_START };

_server_addr.family = AF_INET;
_server_addr.port = _TEST_PORT_LOCAL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dito.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

However, I think the test application needs work - lots of code duplication ...

This seems to be the general nature with these kind of unittest-like test. Furthermore, this is also true for the sock_udp and sock_ip tests. Ideally I would like to unify them anyways later on. So can we maybe move that issue to a separate PR?

@smlng
Copy link
Copy Markdown
Member

smlng commented Feb 13, 2017

@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?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

Those came after I wrote the comment, but before I hit "Comment" (which took me several hours 😊)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

Will look into them

@smlng
Copy link
Copy Markdown
Member

smlng commented Feb 13, 2017

@miri64 ah damn, oversaw the CALL makro definition. Well then, I tested and it works, so ACK -> please squash as needed and let Murdock have a final look.

BUT: we should remember (make a knot somewhere), that the tests should be made more readable and without that much code duplication.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

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

@miri64 miri64 force-pushed the pkg/feat/lwip-sock-tcp branch from 0165af7 to b915d15 Compare February 13, 2017 19:12
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

Rebased squashed

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 13, 2017

These knots are called issues in GitHub :P

See #6596

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 13, 2017
@miri64 miri64 merged commit c0b9b0f into RIOT-OS:master Feb 13, 2017
@miri64 miri64 deleted the pkg/feat/lwip-sock-tcp branch February 13, 2017 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants