Skip to content

emb6: provide sock_udp port#6012

Merged
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:emb6/feat/sock
Apr 26, 2017
Merged

emb6: provide sock_udp port#6012
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:emb6/feat/sock

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Oct 27, 2016

Basically just an adapted carbon copy of emb6_conn_udp. Testable with tests/emb6. Not in the mood to write more indepth test like for the more stable stacks ;-).

@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 labels Oct 27, 2016
@miri64 miri64 added this to the Release 2017.01 milestone Oct 27, 2016
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 13, 2017

Ping?

@miri64 miri64 added the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Jan 18, 2017
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 18, 2017

Rebased for today's Hack'n'ACK.

@PeterKietzmann PeterKietzmann modified the milestones: Release 2017.01, Release 2017.04 Jan 26, 2017
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 28, 2017

@PeterKietzmann can we maybe get this merged today, then we can delete conn soon-ish ;-).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 28, 2017

Rebased to current master

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 28, 2017

Okay, I can't fix the issues Jenkins reports right now. Will do later.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 28, 2017

Rebased and adapted to master.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 11, 2017

If we merge this before the release, we can remove conn for the release ;-)

@miri64 miri64 mentioned this pull request Apr 18, 2017
@kaspar030 kaspar030 modified the milestone: Release 2017.04 Apr 21, 2017
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Can we finally merge this tonight?

/* change to emb6 thread context */
if (evproc_putEvent(E_EVPROC_TAIL, EVENT_TYPE_CONN_SEND, &send_cmd) == E_SUCCESS) {
/* block thread until data was send */
mutex_lock(&send_cmd.block);
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.

mutex was already locked 4 lines above, need to lock again here?

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.

is this because in _output_callback its unlocked if successful?

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.

but why unlock in _output_callback and lock here again, couldn't you just omit the unlock in _output_callback.

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.

Yes, this is basically a hacked way of waiting for the data to be sent (see comment above this line) ;-)


/**
* @defgroup
* @ingroup
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.

looks a bit empty around here 😉

res = -ETIMEDOUT;
break;
case _MSG_TYPE_RCV:
mutex_lock(&sock->mutex);
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.

it is necessary to lock here already, if possible (and safe) move lock below one line above memcpy?

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.

sock->recv_info in the line below needs protection. It is set in _input_callback() which is set in the emb6 thread's context.

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 25, 2017
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Addressed comments

mutex_lock(&sock->mutex);
mbox_init(&sock->mbox, sock->mbox_queue, SOCK_MBOX_SIZE);
atomic_flag_clear(&sock->receivers);
if ((res = _reg(&sock->sock, sock, _input_callback, local, remote)) < 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_reg either returns 0 on success or < 0 on error. Thus you can shorten the function:

if ((res = _reg(...))) {
   sock->sock.input_callback = NULL;
}
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.

I think this makes the code harder to understand.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about:

res = _reg(...);
if (res) {
    /* there was an error */
   sock->sock.input_callback = NULL;
}
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.

Disregarding the comment the still read "if there is a result, set input_callback to zero". Doing a boolean operation here makes this a lot clearer, IMHO (without requiring a comment).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please rephrase, I honestly don't understand what you mean.

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.

I think we talked past each other (thought you were talking about the < 0)... I wasn't aware anymore about the code below. Will fix.

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.

Addressed

}
atomic_fetch_add(&sock->receivers, 1);
if (_mbox_get(&sock->mbox, &msg, blocking) == 0) {
return -EAGAIN;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible to get here with the timer still active? in that case it must be removed.

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.

You mean the timeout timer? That's only active when timeout > 0. _mbox_get() returns 0 in non-blocking mode (timeout == 0). Will add a comment.

tests/emb6/udp.c Outdated
#ifdef MODULE_CONN_UDP
static char conn_inbuf[CONN_INBUF_SIZE];
#ifdef MODULE_EMB6_SOCK_UDP
static char sock_inbuf[CONN_INBUF_SIZE];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CONN?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Addressed comments.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Fixed issues reported by Murdock (needed to rebase for that).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Fixed/explained away errors reported by cppcheck

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

Any chance to get this merged today as well?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 25, 2017

(just want to make removal of conn possible ASAP for the next release ;-))

}
}
if (remote != NULL) {
udp_socket_connect(c, (uip_ipaddr_t *)&remote->addr, remote->port);
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.

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.

Because it only returns -1 if c or c->udp_conn is NULL, which can't happen at this point.

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.

mhm, I think that is exactly what happens below in L243 where _reg is called with &tmp and tmp->udp_conn is never set, hence NULL or something random.

Copy link
Copy Markdown
Member

@smlng smlng Apr 26, 2017

Choose a reason for hiding this comment

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

ah sorry remote == NULL, may bad

if ((sock->sock.input_callback != NULL) &&
(sock->sock.udp_conn->lport != 0)) {
mutex_lock(&sock->mutex);
memset(&ep->addr, 0, sizeof(ipv6_addr_t));
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.

why is address just set to all 0s and not copied from sock as in gnrc_sock_udp, for example?

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.

Because the local end point in emb6 doesn't have an address (since there are no interfaces).

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.

understood

return -ENOTCONN;
}
/* cppcheck-suppress nullPointerRedundantCheck
* remote == NULL implies that sock != NULL (see assert at start of functon)
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.

/functon/function/

}
send_cmd.remote = remote;
}
if ((remote == NULL) && (sock->sock.udp_conn->rport == 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.

this could be

else if (sock->sock.udp_conn->rport == 0) {
    return -ENOTCONN;
}

cause above you check remote != NULL hence if that is not the case, it must be remote == NULL

* without checking (sock != NULL) first => this check afterwards isn't
* redundant */
if (sock == NULL) {
int res;
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.

why not use send_cmd.res here?

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.

Because it's the result of the send command, not the result of _reg() (and I don't want to dig into emb6's code now to make sure I don't have to zero it again bevore puttilng send_cmd in its event queue ;-))

Copy link
Copy Markdown
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

minor changes, please squash after fixing!

tests/emb6/udp.c Outdated
port = (uint16_t)atoi((char *)args);
if ((res = conn_udp_create(&server_conn, &server_addr,
sizeof(server_addr), AF_INET6, port)) < 0) {
uint16_t port = (uint16_t)atoi((char *)args);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

casts unneccessary

tests/emb6/udp.c Outdated
}
/* parse port */
port = (uint16_t)atoi(port_str);
dst.port = (uint16_t)atoi(port_str);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cast not needed

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 26, 2017

Addressed comments and squashed

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 26, 2017

Murdock's happy. :-)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 26, 2017

@smlng are you okay too?

@miri64 miri64 merged commit c23d624 into RIOT-OS:master Apr 26, 2017
@miri64 miri64 deleted the emb6/feat/sock branch April 26, 2017 12:22
@emmanuelsearch
Copy link
Copy Markdown
Member

@miri64 shall we not also remove conn from the /contrib dir?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Apr 27, 2017

@emmanuelsearch #6976

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.

5 participants