osd-contiki/apps
Peter 432f12e156 Several changes to fix bugs and harden mqtt code.
1. The PT_MQTT_WAIT_SEND() macro has several issues:

- It does not check the return value from process_post(), which
  sometimes returns an error code. See next issue.

- Each time the macro is called, is posts an event to itself. The idea
seems to be that the event should be absorbed by the macro itself, so
when the macro terminates there is NOT a net growth of the event
queue. This does not work.  The reason is that the
PROCESS_WAIT_EVENT() sometimes absorbs a broadcast event instead of
its own event, and then the number of events in the event queue
increases. This leads to event explosions and overflow in the event
queue.

- The macro cannot call PT_EXIT(). This will expand to a return
statement, causing a return from the function calling the macro
(mqtt_process), rather then exiting the protothread (which was
probably the intention). Protothreads have lexical scope...

Fixes: 1) Check return value from process_post() 2) Loop until the
event posted to itself is absorbed (rather than just absorbing the
next event) 3) Replace PT_EXIT() with PT_INIT() (doesn't really make a
difference, could probably just be removed).

2. Change order of the checks in the protothread-calling loops in
mqtt_process().  Reason: When a protothread has been cleared by
PT_MQTT_WAIT_SEND(), it will not return a value, so checking against
PT_EXITED does not make sense.

3. PT_MQTT_WRITE_BYTES() should initialize conn->out_write_pos to 0.
When PT_MQTT_WRITE_BYTES() does not finish (due to TCP disconnect for
instance), it may leave conn->out_write_pos with a non-zero
value. Next time PT_MQTT_WRITE_BYTES() is called, it will take data
from the wrong place.

4. Put MQTT_CONN_STATE_ABORT_IMMEDIATE before
MQTT_CONN_STATE_NOT_CONNECTED in the enum list, so that the check
if(conn->state > MQTT_CONN_STATE_NOT_CONNECTED) in mqtt_connect()
fails when in state MQTT_CONN_STATE_ABORT_IMMEDIATE. Otherwise, it
will deadlock and not reattempt connections while in this state.
2017-03-21 16:43:15 +01:00
..
about A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
antelope Avoid compilation warnings in Antelope. 2014-09-05 18:21:47 +02:00
at-master AT driver (master) and example 2016-05-15 12:19:04 +02:00
calc A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
cmdd Removed CC_FASTCALL. 2015-11-01 18:10:17 +01:00
codeprop Added MSP430X ELFLOADER support to load image with large memory model. 2015-06-15 17:53:18 +05:30
collect-view Changed the name of the rimeaddr module to linkaddr 2014-01-29 20:12:24 +01:00
dhcp Fix DHCP client retries. 2015-06-21 14:25:52 +02:00
directory A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
email Moved the ctk files from core/lib into core/lib/ and core/lib/libconio 2014-01-26 23:20:46 +01:00
er-coap apps/er-coap/er-coap-separate.h: fix warning: function declaration isn't a prototype 2016-03-02 07:12:33 +01:00
ftp Updated include paths for the moved files under net/ 2014-01-26 23:20:23 +01:00
http-post-auth Changed the parameter 'char * data' of process_start to the 2014-06-12 13:40:28 +02:00
httpd-ws A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
ipso-objects ipso-temperature: Use "Cel" for degrees celsius 2016-05-04 19:21:56 +02:00
irc Moved the ctk files from core/lib into core/lib/ and core/lib/libconio 2014-01-26 23:20:46 +01:00
json Merge pull request #1438 from jkent/jsonparse 2016-03-11 14:23:17 +01:00
mqtt Several changes to fix bugs and harden mqtt code. 2017-03-21 16:43:15 +01:00
netconf Integrates uip-nameserver API 2015-01-09 09:44:06 +01:00
oma-lwm2m Merge pull request #1677 from gebart/pr/lwm2m-instance-list 2016-09-06 16:50:11 +02:00
orchestra Orchestra: avoid a link error for nbr_routes 2017-01-19 13:55:08 +01:00
ping6 A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
powertrace Remove commented-out code 2015-10-20 10:11:47 +02:00
process-list A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
program-handler Merge pull request #1344 from tsparber/fix-doxygen 2015-11-30 22:07:15 +01:00
rest-engine squash clean up left overs 2016-07-09 10:39:23 +02:00
serial-shell [doc] Give files a common structure by placing license first (partial) 2014-11-10 23:54:49 +01:00
servreg-hack Remove commented-out code 2015-10-20 10:11:47 +02:00
shell Fixes error when processes name are not used 2016-02-22 16:02:06 +01:00
slip-cmd Updated include paths for the moved files under net/ 2014-01-26 23:20:23 +01:00
telnet A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
telnetd Added missing charset abstraction. 2015-07-16 17:55:26 +02:00
unit-test Do not return test execution status. The information is already available in the test object, and it becomes possible for test function to easily clean up state allocated during the test by putting such code after UNIT_TEST_END. 2011-12-01 14:40:54 +01:00
webbrowser Improved dicarding of text in the HTML header. 2016-10-11 11:25:31 +02:00
webserver Add missing variable declaration 2017-03-18 14:01:10 +00:00
webserver-nano Adding a gitattributes and correcting line-endings 2015-09-07 15:40:02 +02:00