virtual nsapi_error_t socket_listen(nsapi_socket_t socket, int backlog) { if (!_stack_api()->socket_listen) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_listen(_stack(), socket, backlog); }
virtual int socket_bind(nsapi_socket_t socket, const SocketAddress &address) { if (!_stack_api()->socket_bind) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_bind(_stack(), socket, address.get_addr(), address.get_port()); }
virtual void socket_attach(nsapi_socket_t socket, void (*callback)(void *), void *data) { if (!_stack_api()->socket_attach) { return; } return _stack_api()->socket_attach(_stack(), socket, callback, data); }
virtual nsapi_error_t getsockopt(nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen) { if (!_stack_api()->getsockopt) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->getsockopt(_stack(), socket, level, optname, optval, optlen); }
virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t socket, const SocketAddress &address, const void *data, nsapi_size_t size) { if (!_stack_api()->socket_sendto) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_sendto(_stack(), socket, address.get_addr(), address.get_port(), data, size); }
virtual int socket_recv(nsapi_socket_t socket, void *data, unsigned size) { if (!_stack_api()->socket_recv) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_recv(_stack(), socket, data, size); }
virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t socket, void *data, nsapi_size_t size) { if (!_stack_api()->socket_recv) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_recv(_stack(), socket, data, size); }
virtual nsapi_error_t socket_connect(nsapi_socket_t socket, const SocketAddress &address) { if (!_stack_api()->socket_connect) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_connect(_stack(), socket, address.get_addr(), address.get_port()); }
virtual nsapi_error_t socket_open(nsapi_socket_t *socket, nsapi_protocol_t proto) { if (!_stack_api()->socket_open) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_open(_stack(), socket, proto); }
virtual nsapi_error_t socket_close(nsapi_socket_t socket) { if (!_stack_api()->socket_close) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->socket_close(_stack(), socket); }
virtual nsapi_error_t setstackopt(int level, int optname, const void *optval, unsigned optlen) { if (!_stack_api()->setstackopt) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->setstackopt(_stack(), level, optname, optval, optlen); }
virtual nsapi_error_t add_dns_server(const SocketAddress &address) { if (!_stack_api()->add_dns_server) { return NetworkStack::add_dns_server(address); } return _stack_api()->add_dns_server(_stack(), address.get_addr()); }
virtual int getstackopt(int level, int optname, void *optval, unsigned *optlen) { if (!_stack_api()->getstackopt) { return NSAPI_ERROR_UNSUPPORTED; } return _stack_api()->getstackopt(_stack(), level, optname, optval, optlen); }
virtual const char *get_ip_address() { if (!_stack_api()->get_ip_address) { return 0; } static uint8_t buffer[sizeof(SocketAddress)]; SocketAddress *address = new (buffer) SocketAddress(_stack_api()->get_ip_address(_stack())); return address->get_ip_address(); }
virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version) { if (!_stack_api()->gethostbyname) { return NetworkStack::gethostbyname(name, address, version); } nsapi_addr_t addr = {NSAPI_UNSPEC, 0}; nsapi_error_t err = _stack_api()->gethostbyname(_stack(), name, &addr, version); address->set_addr(addr); return err; }
virtual int gethostbyname(SocketAddress *address, const char *name) { if (!_stack_api()->gethostbyname) { return NetworkStack::gethostbyname(address, name); } nsapi_addr_t addr = {NSAPI_IPv4, 0}; int err = _stack_api()->gethostbyname(_stack(), &addr, name); address->set_addr(addr); return err; }
virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t socket, SocketAddress *address, void *data, nsapi_size_t size) { if (!_stack_api()->socket_recvfrom) { return NSAPI_ERROR_UNSUPPORTED; } nsapi_addr_t addr = {NSAPI_IPv4, 0}; uint16_t port = 0; nsapi_size_or_error_t err = _stack_api()->socket_recvfrom(_stack(), socket, &addr, &port, data, size); if (address) { address->set_addr(addr); address->set_port(port); } return err; }
virtual nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *socket, SocketAddress *address) { if (!_stack_api()->socket_accept) { return NSAPI_ERROR_UNSUPPORTED; } nsapi_addr_t addr = {NSAPI_IPv4, 0}; uint16_t port = 0; nsapi_error_t err = _stack_api()->socket_accept(_stack(), server, socket, &addr, &port); if (address) { address->set_addr(addr); address->set_port(port); } return err; }