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

Add notifications through websockets #2004

Merged
merged 13 commits into from
Apr 7, 2016

Conversation

fortizc
Copy link
Contributor

@fortizc fortizc commented Apr 5, 2016

Implements #1669

const size_t WSConstants::DataSize = 128;
// Ok, this is can be a macro, but I prefer
// to be consistent
const std::string WSConstants::ProtocolName = "orion-ws";
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we have talked about this in the past but I don't rembember... what is the purpose of this "orion-ws"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the protocol name used for the clients to connect with our service

Copy link
Member

Choose a reason for hiding this comment

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

While we decide the right name ( @jmcanterafonseca , any suggestion?) maybe we should use something that clearly specifies that the name is temporal, e.g. orion-ws-experimental.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, the sub-protocol, application level protocol, is an optional part in the Javascript API.

Having said that, wouldn't it be 'ngsiv2-json' a proper name for the sub-protocol? Maybe in the future we implement 'ngsiv2-text' or 'ngsiv2-binary' ...

By the way, there is a registry of subprotocols

https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name

if we say 'orion-xxx' it can be less standard if others decide to implement this as we have done for Orion.

Copy link
Member

Choose a reason for hiding this comment

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

+1 for "ngsiv2-json"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changet it in c824a6c

Remove subscription from DB when websocket connection is closed
if (pos == std::string::npos)
return false;

char buff[25];
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to use (in globals/limits.h)

#define MAX_LENGTH_SUBID 24

and size the buff variable with MAX_LENGTH_SUBID + 1. Otherwise, the raw 24 and 25 may be a bit obscure.

(const is also ok if you prefer that to #deffine)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 661796d

@fgalan
Copy link
Member

fgalan commented Apr 6, 2016

LGTM (passing the ball to @kzangeli for final LGTM + merge + delete branch)

if (written == -1)
return 1;
}

Copy link
Member

Choose a reason for hiding this comment

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

A few things about this loop ...
To detect -1 from lws_write you need a separate variable, the accumulating 'written' cannot be used:

int bytes = lws_write(it->second, (p + written), strlen(msg), LWS_WRITE_TEXT);
if (bytes == -1)
  return 1;
written += bytes

AND, the third parameter to lws_write, the size of the buffer to be sent must adapt to the number of bytes already written, and strlen should not be calculated in each loop, so:

int bytes = lws_write(it->second, (p + written),  msg_size - written, LWS_WRITE_TEXT);

Also (this is just my opinion), isn't &p[written] easier to understand than p + written ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 51652e9
and about to use &p[written] or p + writter, I prefer the second option, because is really a pointer not an array.

Copy link
Member

Choose a reason for hiding this comment

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

As I said, just my opinion :-)

@kzangeli
Copy link
Member

kzangeli commented Apr 7, 2016

LGTM

@kzangeli kzangeli merged commit 7c49798 into telefonicaid:feature/1181_websockets Apr 7, 2016
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.

4 participants