Skip to content
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

expose tcp_read/ssl_read errors #713

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

jiahuang
Copy link
Contributor

This PR exposes HCI 1008 (select) errors on read so that it can be handled in the JS layer.

@@ -261,9 +261,14 @@ static int l_tm_tcp_read (lua_State* L)
uint8_t buf[512];
size_t buf_len = sizeof(buf);
int err = tm_tcp_read(socket, buf, &buf_len);
(void) err;

if (err < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. tm_tcp_read returns errno on error:
https://github.com/tessel/runtime/blob/master/src/posix/tm_net.c#L169

…which at least for the POSIX-defined errors are mandated to have positive values: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html

So: any non-zero value indicates error…the sign of the number should not be checked here, or you will certainly miss errors under POSIX (and probably CC3K too unless it happens to provide negative errno values of its own…).

@natevw
Copy link
Contributor

natevw commented Feb 13, 2015

Glad this is getting hooked up — please see comments on patch though for some logic changes necessary to make it work as you intend for the tcp case especially.

@@ -195,9 +195,11 @@ TCPSocket.prototype.connect = function (/*options | [port], [host], [cb]*/) {
var closeRet = tm.tcp_close(self.socket); // returns -57 if socket is already closed
if (closeRet < 0 && closeRet != -tm.ENOTCONN){
// couldn't close socket, throw an error
// failed to connect, stay silent
console.log("Failed to close socket", self.socket);
Copy link
Member

Choose a reason for hiding this comment

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

This is the opposite of staying silent

Copy link
Member

Choose a reason for hiding this comment

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

But yeah, should we have internal code be emitting console.logs if it's just going to throw the error immediately?

@natevw
Copy link
Contributor

natevw commented Feb 27, 2015

@jiahuang is this just tying up loose ends, or was the missing error handling related to tessel/t1-firmware#128 too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants