Commit Graph

34 Commits (97380a75c6d99de522396161873b67342bb1e96c)

Author SHA1 Message Date
Christopher Haster 97380a75c6 Restructured nsapi headers
- Provide nsapi.h as central entry point
- Provide nsapi_types.h as c-compatible destination for nsapi types
- Standardize include paths
2016-07-21 18:22:55 -05:00
Russ Butler 04e4d9f450 Fix async NSAPI race condition
Remove read and write mutexes since multiple calls to send or multiple
calls to recv on different threads is undefined behavior.
This is because the size of data sent or received by these calls is
undefined and could lead to the data being interleaved.  The code now
asserts that there are not multiple threads calling send at the same
or calling recv at the same time.  Note that calling send and recv from
different threads at the same time is still safe and well defined
behavior.

By removing the read and write mutexes and associated timeout it
guarantees that a stack call will always be made and thus the value
NSAPI_ERROR_TIMEOUT cannot get falsely returned.
2016-07-21 18:20:59 -05:00
Russ Butler 90cd978785 Separate interface from stack in NSAPI
This patch consists of:
-Add NetworkInterface to wrap objects bound to a stack and update
    socket code to handle this in addition to NetworkStacks
-Update MeshInterface to inherit from NetworkInterface
-Update NanostackInterface so it only inherits from NetworkStack
-Add MeshInterfaceNanostack and update LoWPANNDInterface and
    ThreadInterface to inherit from this
2016-07-21 18:20:45 -05:00
geky 3ee8e30ae4 Added NSAPI_KEEPINTVL/NSAPI_KEEPIDLE options to the socket API 2016-07-21 18:19:21 -05:00
Christopher Haster a6edc268f3 Coalesce redundant events to reduce cpu usage in lazy implementations
*cough* esp8266 *cough*

this is especially important for event-loop based systems where
excessive events results in problematic memory consumption.
2016-07-21 18:19:21 -05:00
Russ Butler c3baf2792e Fix SocketAddress constructor to support ipv6
Fix typo causing ipv6 addresses in the constructor to fail.
2016-07-21 18:19:21 -05:00
Christopher Haster 1c0a7c2426 Adopt Callback class in NetworkSocketAPI 2016-07-21 18:19:21 -05:00
Russ Butler 8f33c0fc4f Add synchronization to the network socket API
Add mutexes to protect the network socket API.  Also use semaphores to
wait for read/write events.  Also fix a typo in the comments for
timeout.
2016-07-21 18:19:21 -05:00
Christopher Haster 3d310c2463 Small bug fixes
mirrored from:
https://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/

- Fix bug with SocketAddress init per @c1728p9
- Fix issue with not passing interface through accept call
- Fix port issue in SocketAddress constructor
2016-07-21 18:19:21 -05:00
Christopher Haster 710fab5b8b Add NSAPI_ERROR_PARAMETER
per @c1728p9
2016-07-21 18:19:21 -05:00
Christopher Haster 943dd711a9 Added WFI to save power in temporary polling implementation 2016-07-21 18:19:21 -05:00
Christopher Haster f2715b7e77 Consolidate set_timeout/set_blocking behaviour
- Avoids ambiguity when both are used
- Matches Python behaviour
2016-07-21 18:19:21 -05:00
Christopher Haster bd5e913ca1 Separate Stack/Interface concept into two distinct classes 2016-07-21 18:19:21 -05:00
Christopher Haster a4f1071996 Add standardized stack options 2016-07-21 18:19:21 -05:00
Christopher Haster abd25f9bb3 Added workaround for bug in newlib sscanf
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1399224
2016-07-21 18:19:21 -05:00
Christopher Haster cd4a521e22 Fix race condition in socket close 2016-07-21 18:19:21 -05:00
Christopher Haster fc71badb69 Rename Interface -> Stack
NetworkInterface  -> NetworkStack
EthernetInterface -> EthernetStack
WiFiInterface     -> WiFiStack
CellularInterface -> CellularStack
MeshInterface     -> MeshStack
2016-07-21 18:19:21 -05:00
Christopher Haster d36a0b6b88 Revised documentation for Interface classes 2016-07-21 18:19:21 -05:00
Christopher Haster aa2357a836 Revisited documentation for Socket API 2016-07-21 18:19:21 -05:00
Christopher Haster 0ae11b49e8 Removed is_connected function
- Not supported by TCP/UDP protocols
- Uncommon and less useful with proper error handling
2016-07-21 18:19:21 -05:00
Christopher Haster b9d9842846 Revisited documentation for NetworkInterface specific methods 2016-07-21 18:19:21 -05:00
Christopher Haster d84f4be6ed Added support for shortened form ipv6 addresses
supported:
    1.2.3.4
    1:2:3:4:5:6:7:8
    1:2::7:8
    ::

currently not supported:
    1:2:3:4:5:6:1.2.3.4
2016-07-21 18:19:21 -05:00
Christopher Haster 3fa1bb6469 Revised stack specific configurations
Adds the following functions for direct configuration of interface
- (set|get)stackopt
- (set|get)sockopt
2016-07-21 18:19:21 -05:00
Christopher Haster 63725d653c Move bind to Socket
Bind can operate on any IP socket and is not specific to a protocol
2016-07-21 18:19:21 -05:00
Russ Butler aea45c88ce Fix ipv6 addr in SocketAddress
Correctly set and return the ipv6 address.
2016-07-21 18:19:21 -05:00
Christopher Haster 56e11d6709 Added better support for SocketAddress/string addresses/ports 2016-07-21 18:19:21 -05:00
Christopher Haster bd8cbf0fcb Move to SocketAddress in gethostbyname 2016-07-21 18:19:21 -05:00
Christopher Haster 3f08f3957c Added support for storing bytes directly in SocketAddress
Bytes are stored by default, however enough space is allocated in
a SocketAddress to generate the string representation if necessary.

Currently there is no support for shortened addresses
2016-07-21 18:19:20 -05:00
Christopher Haster 1b368cf525 Renamed NetworkInterface create/destroy methods to match Socket methods
- socket_create -> socket_open
- socket_destroy -> socket_close
2016-07-21 18:19:20 -05:00
Christopher Haster dfc1ca4cef Move to single state-change interrupt
Pros
- Easier to implement
- More similar to SIGIO in BDS sockets

Cons
- Less information, but this information had a high risk of being
  faulty/spurious
2016-07-21 18:19:20 -05:00
Christopher Haster a7e6c105b3 Remove shutdown parameter from close call
Pros
- Simplifies interface
- Easier base implementation

Cons
- May need shutdown functionality, in this case shutdown
  can be added as another function in the future
2016-07-21 18:19:20 -05:00
Christopher Haster d38ccb70a6 Add open call as alternative to passing NetworkInterface at construction
Pros
- Allows memory to be statically allocated
- Avoids issues with Thread creation before entering main
- Matches existing APIs such as FunctionPointer and Ticker

Cons
- Does not enforce passing a NetworkInterface
2016-07-21 18:19:20 -05:00
Christopher Haster 4c7992cb24 Matched changes NetworkSocketAPI
Responded to feedback from mbed-client implementation
to introduce a full feature set that should support most
of the use cases for the API.
2016-07-21 18:19:10 -05:00
Bogdan Marinescu 9f668f1a8f Preparing new layout - added net/NetworkSocketAPI
Origin: https://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/
2016-04-05 16:40:57 +01:00