mirror of https://github.com/ARMmbed/mbed-os.git
Incorporate review comments from @kjbracey-arm
parent
90e188b23a
commit
ab883350a0
|
@ -235,8 +235,10 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||||
netconntype = NETCONN_TCP;
|
netconntype = NETCONN_TCP;
|
||||||
} else if (proto == NSAPI_UDP) {
|
} else if (proto == NSAPI_UDP) {
|
||||||
netconntype = NETCONN_UDP;
|
netconntype = NETCONN_UDP;
|
||||||
} else {
|
} else if (proto == NSAPI_ICMP) {
|
||||||
netconntype = NETCONN_RAW;
|
netconntype = NETCONN_RAW;
|
||||||
|
} else {
|
||||||
|
return NSAPI_ERROR_PROTO_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
|
|
|
@ -14,25 +14,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "RAWIPSocket.h"
|
#include "ICMPSocket.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "mbed_assert.h"
|
#include "mbed_assert.h"
|
||||||
|
|
||||||
RAWIPSocket::RAWIPSocket()
|
ICMPSocket::ICMPSocket()
|
||||||
{
|
{
|
||||||
_socket_stats.stats_update_proto(this, NSAPI_ICMP);
|
_socket_stats.stats_update_proto(this, NSAPI_ICMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
RAWIPSocket::~RAWIPSocket()
|
ICMPSocket::~ICMPSocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_protocol_t RAWIPSocket::get_proto()
|
nsapi_protocol_t ICMPSocket::get_proto()
|
||||||
{
|
{
|
||||||
return NSAPI_ICMP;
|
return NSAPI_ICMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t RAWIPSocket::connect(const SocketAddress &address)
|
nsapi_error_t ICMPSocket::connect(const SocketAddress &address)
|
||||||
{
|
{
|
||||||
_remote_peer = address;
|
_remote_peer = address;
|
||||||
_socket_stats.stats_update_peer(this, _remote_peer);
|
_socket_stats.stats_update_peer(this, _remote_peer);
|
||||||
|
@ -40,7 +40,7 @@ nsapi_error_t RAWIPSocket::connect(const SocketAddress &address)
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_size_or_error_t RAWIPSocket::sendto(const char *host, uint16_t port, const void *data, nsapi_size_t size)
|
nsapi_size_or_error_t ICMPSocket::sendto(const char *host, uint16_t port, const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
SocketAddress address;
|
SocketAddress address;
|
||||||
nsapi_size_or_error_t err;
|
nsapi_size_or_error_t err;
|
||||||
|
@ -61,7 +61,7 @@ nsapi_size_or_error_t RAWIPSocket::sendto(const char *host, uint16_t port, const
|
||||||
return sendto(address, data, size);
|
return sendto(address, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_size_or_error_t RAWIPSocket::sendto(const SocketAddress &address, const void *data, nsapi_size_t size)
|
nsapi_size_or_error_t ICMPSocket::sendto(const SocketAddress &address, const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
_lock.lock();
|
_lock.lock();
|
||||||
nsapi_size_or_error_t ret;
|
nsapi_size_or_error_t ret;
|
||||||
|
@ -108,7 +108,7 @@ nsapi_size_or_error_t RAWIPSocket::sendto(const SocketAddress &address, const vo
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_size_or_error_t RAWIPSocket::send(const void *data, nsapi_size_t size)
|
nsapi_size_or_error_t ICMPSocket::send(const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
if (!_remote_peer) {
|
if (!_remote_peer) {
|
||||||
return NSAPI_ERROR_NO_ADDRESS;
|
return NSAPI_ERROR_NO_ADDRESS;
|
||||||
|
@ -116,7 +116,7 @@ nsapi_size_or_error_t RAWIPSocket::send(const void *data, nsapi_size_t size)
|
||||||
return sendto(_remote_peer, data, size);
|
return sendto(_remote_peer, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_size_or_error_t RAWIPSocket::recvfrom(SocketAddress *address, void *buffer, nsapi_size_t size)
|
nsapi_size_or_error_t ICMPSocket::recvfrom(SocketAddress *address, void *buffer, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
_lock.lock();
|
_lock.lock();
|
||||||
nsapi_size_or_error_t ret;
|
nsapi_size_or_error_t ret;
|
||||||
|
@ -177,12 +177,12 @@ nsapi_size_or_error_t RAWIPSocket::recvfrom(SocketAddress *address, void *buffer
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_size_or_error_t RAWIPSocket::recv(void *buffer, nsapi_size_t size)
|
nsapi_size_or_error_t ICMPSocket::recv(void *buffer, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
return recvfrom(NULL, buffer, size);
|
return recvfrom(NULL, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket *RAWIPSocket::accept(nsapi_error_t *error)
|
Socket *ICMPSocket::accept(nsapi_error_t *error)
|
||||||
{
|
{
|
||||||
if (error) {
|
if (error) {
|
||||||
*error = NSAPI_ERROR_UNSUPPORTED;
|
*error = NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
@ -190,7 +190,7 @@ Socket *RAWIPSocket::accept(nsapi_error_t *error)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t RAWIPSocket::listen(int)
|
nsapi_error_t ICMPSocket::listen(int)
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/** \addtogroup netsocket */
|
/** \addtogroup netsocket */
|
||||||
/** @{*/
|
/** @{*/
|
||||||
/* RAWIPSocket
|
/* ICMPSocket
|
||||||
* Copyright (c) 2015 ARM Limited
|
* Copyright (c) 2015 ARM Limited
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -16,8 +16,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RAWIPSOCKET_H
|
#ifndef ICMPSOCKET_H
|
||||||
#define RAWIPSOCKET_H
|
#define ICMPSOCKET_H
|
||||||
|
|
||||||
#include "netsocket/InternetSocket.h"
|
#include "netsocket/InternetSocket.h"
|
||||||
#include "netsocket/NetworkStack.h"
|
#include "netsocket/NetworkStack.h"
|
||||||
|
@ -27,36 +27,19 @@
|
||||||
|
|
||||||
/** RAW socket implementation.
|
/** RAW socket implementation.
|
||||||
*/
|
*/
|
||||||
class RAWIPSocket : public InternetSocket {
|
class ICMPSocket : public InternetSocket {
|
||||||
public:
|
public:
|
||||||
/** Create an uninitialized socket.
|
/** Create an uninitialized socket.
|
||||||
*
|
*
|
||||||
* @note Must call open to initialize the socket on a network stack.
|
* @note Must call open to initialize the socket on a network stack.
|
||||||
*/
|
*/
|
||||||
RAWIPSocket();
|
ICMPSocket();
|
||||||
|
|
||||||
/** Create and open a socket on the network stack of the given
|
|
||||||
* network interface.
|
|
||||||
*
|
|
||||||
* @tparam S Type of the Network stack.
|
|
||||||
* @param stack Network stack as target for socket.
|
|
||||||
* @deprecated since mbed-os-5.11
|
|
||||||
*/
|
|
||||||
template <typename S>
|
|
||||||
MBED_DEPRECATED_SINCE("mbed-os-5.11",
|
|
||||||
"The RAWSocket(S *stack) constructor is deprecated"
|
|
||||||
"It discards the open() call return value."
|
|
||||||
"Use another constructor and call open() explicitly, instead.")
|
|
||||||
RAWIPSocket(S *stack)
|
|
||||||
{
|
|
||||||
open(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Destroy a socket.
|
/** Destroy a socket.
|
||||||
*
|
*
|
||||||
* @note Closes socket if the socket is still open.
|
* @note Closes socket if the socket is still open.
|
||||||
*/
|
*/
|
||||||
virtual ~RAWIPSocket();
|
virtual ~ICMPSocket();
|
||||||
|
|
||||||
/** Send data to the specified host and port.
|
/** Send data to the specified host and port.
|
||||||
*
|
*
|
||||||
|
@ -152,14 +135,14 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
|
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
|
||||||
|
|
||||||
/** Not implemented for RAWIPSocket.
|
/** Not implemented for ICMPSocket.
|
||||||
*
|
*
|
||||||
* @param error Not used.
|
* @param error Not used.
|
||||||
* @return NSAPI_ERROR_UNSUPPORTED
|
* @return NSAPI_ERROR_UNSUPPORTED
|
||||||
*/
|
*/
|
||||||
virtual Socket *accept(nsapi_error_t *error = NULL);
|
virtual Socket *accept(nsapi_error_t *error = NULL);
|
||||||
|
|
||||||
/** Not implemented for RAWIPSocket.
|
/** Not implemented for ICMPSocket.
|
||||||
*
|
*
|
||||||
* @param backlog Not used.
|
* @param backlog Not used.
|
||||||
* @return NSAPI_ERROR_UNSUPPORTED
|
* @return NSAPI_ERROR_UNSUPPORTED
|
|
@ -183,7 +183,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class InternetSocket;
|
friend class InternetSocket;
|
||||||
friend class RAWIPSocket;
|
friend class ICMPSocket;
|
||||||
friend class UDPSocket;
|
friend class UDPSocket;
|
||||||
friend class TCPSocket;
|
friend class TCPSocket;
|
||||||
friend class TCPServer;
|
friend class TCPServer;
|
||||||
|
|
|
@ -24,12 +24,12 @@
|
||||||
#include "netsocket/NetworkStack.h"
|
#include "netsocket/NetworkStack.h"
|
||||||
#include "netsocket/NetworkInterface.h"
|
#include "netsocket/NetworkInterface.h"
|
||||||
#include "rtos/EventFlags.h"
|
#include "rtos/EventFlags.h"
|
||||||
#include "RAWIPSocket.h"
|
#include "ICMPSocket.h"
|
||||||
|
|
||||||
|
|
||||||
/** UDP socket implementation.
|
/** UDP socket implementation.
|
||||||
*/
|
*/
|
||||||
class UDPSocket : public RAWIPSocket {
|
class UDPSocket : public ICMPSocket {
|
||||||
public:
|
public:
|
||||||
/** Create an uninitialized socket.
|
/** Create an uninitialized socket.
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,6 +56,7 @@ enum nsapi_error {
|
||||||
NSAPI_ERROR_ADDRESS_IN_USE = -3018, /*!< Address already in use */
|
NSAPI_ERROR_ADDRESS_IN_USE = -3018, /*!< Address already in use */
|
||||||
NSAPI_ERROR_TIMEOUT = -3019, /*!< operation timed out */
|
NSAPI_ERROR_TIMEOUT = -3019, /*!< operation timed out */
|
||||||
NSAPI_ERROR_BUSY = -3020, /*!< device is busy and cannot accept new operation */
|
NSAPI_ERROR_BUSY = -3020, /*!< device is busy and cannot accept new operation */
|
||||||
|
NSAPI_ERROR_PROTO_UNKNOWN = -3021, /*!< unknown protocol */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue