BLE mbed Endpoint network stack for mbedConnectorInterface. The stack makes use of a special BLE Socket abstraction to create socket() semantics over BLE.

Dependencies:   libnsdl_m0 BLE_API Base64 nRF51822 SplitterAssembler

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Socket.cpp Source File

Socket.cpp

00001 /* Copyright (C) 2012 mbed.org, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 #include "Socket/Socket.h"
00019 #include <cstring>
00020 
00021 using std::memset;
00022 
00023 #include "UartRPCFunctions.h"
00024 
00025 Socket::Socket() : _sock_fd(-1), _blocking(true), _timeout(1500) {
00026     
00027 }
00028 
00029 void Socket::set_blocking(bool blocking, unsigned int timeout) {
00030     _blocking = blocking;
00031     _timeout = timeout;
00032 }
00033 
00034 int Socket::init_socket(int type) {
00035     // Not used for BLE shim
00036     return 0;
00037 }
00038 
00039 int Socket::select(struct timeval *timeout, bool read, bool write) {
00040     // Not used for BLE shim...
00041     return 0;
00042 }
00043 
00044 int Socket::wait_readable(TimeInterval& timeout) {
00045     return select(&timeout._time, true, false);
00046 }
00047 
00048 int Socket::wait_writable(TimeInterval& timeout) {
00049     return select(&timeout._time, false, true);
00050 }
00051 
00052 int Socket::close(bool shutdown) {
00053    ble_rpc_close_udp_socket();
00054    return 0;
00055 }
00056 
00057 Socket::~Socket() {
00058     close(); //Don't want to leak
00059 }
00060 
00061 TimeInterval::TimeInterval(unsigned int ms) {
00062     _time.tv_sec = ms / 1000;
00063     _time.tv_usec = (ms - (_time.tv_sec * 1000)) * 1000;
00064 }