mirror of https://github.com/ARMmbed/mbed-os.git
Revised stack specific configurations
Adds the following functions for direct configuration of interface - (set|get)stackopt - (set|get)sockopt
parent
c4506dc1c0
commit
525c7b361c
|
@ -128,16 +128,6 @@ int ESP8266Interface::socket_close(void *handle)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266Interface::socket_set_option(void *handle, int optname, const void *optval, unsigned optlen)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ESP8266Interface::socket_get_option(void *handle, int optname, void *optval, unsigned *optlen)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ESP8266Interface::socket_bind(void *handle, const SocketAddress &address)
|
int ESP8266Interface::socket_bind(void *handle, const SocketAddress &address)
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
|
|
@ -77,24 +77,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual int socket_close(void *handle);
|
virtual int socket_close(void *handle);
|
||||||
|
|
||||||
/** Set socket options
|
|
||||||
\param handle Socket handle
|
|
||||||
\param optname Option ID
|
|
||||||
\param optval Option value
|
|
||||||
\param optlen Length of the option value
|
|
||||||
\return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen);
|
|
||||||
|
|
||||||
/** Get socket options
|
|
||||||
\param handle Socket handle
|
|
||||||
\param optname Option ID
|
|
||||||
\param optval Buffer pointer where to write the option value
|
|
||||||
\param optlen Length of the option value
|
|
||||||
\return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen);
|
|
||||||
|
|
||||||
/** Bind a server socket to a specific port
|
/** Bind a server socket to a specific port
|
||||||
* @param handle Socket handle
|
* @param handle Socket handle
|
||||||
* @param address Local address to listen for incoming connections on
|
* @param address Local address to listen for incoming connections on
|
||||||
|
|
|
@ -213,16 +213,6 @@ int LWIPInterface::socket_close(void *handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LWIPInterface::socket_set_option(void *handle, int optname, const void *optval, unsigned optlen)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LWIPInterface::socket_get_option(void *handle, int optname, void *optval, unsigned *optlen)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LWIPInterface::socket_bind(void *handle, const SocketAddress &address)
|
int LWIPInterface::socket_bind(void *handle, const SocketAddress &address)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
|
|
|
@ -64,24 +64,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual int socket_close(void *handle);
|
virtual int socket_close(void *handle);
|
||||||
|
|
||||||
/** Set socket options
|
|
||||||
\param handle Socket handle
|
|
||||||
\param optname Option ID
|
|
||||||
\param optval Option value
|
|
||||||
\param optlen Length of the option value
|
|
||||||
\return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen);
|
|
||||||
|
|
||||||
/** Get socket options
|
|
||||||
\param handle Socket handle
|
|
||||||
\param optname Option ID
|
|
||||||
\param optval Buffer pointer where to write the option value
|
|
||||||
\param optlen Length of the option value
|
|
||||||
\return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen);
|
|
||||||
|
|
||||||
/** Bind a server socket to a specific port
|
/** Bind a server socket to a specific port
|
||||||
* @param handle Socket handle
|
* @param handle Socket handle
|
||||||
* @param address Local address to listen for incoming connections on
|
* @param address Local address to listen for incoming connections on
|
||||||
|
|
|
@ -28,3 +28,23 @@ int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
|
||||||
address->set_ip_address(buffer);
|
address->set_ip_address(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NetworkInterface::setstackopt(int level, int optname, const void *optval, unsigned optlen)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NetworkInterface::getstackopt(int level, int optname, void *optval, unsigned *optlen)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NetworkInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NetworkInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
|
@ -37,12 +37,6 @@ enum nsapi_error_t {
|
||||||
NSAPI_ERROR_DEVICE_ERROR = -3010, /*!< failure interfacing with the network procesor */
|
NSAPI_ERROR_DEVICE_ERROR = -3010, /*!< failure interfacing with the network procesor */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Enum of available options
|
|
||||||
* @enum nsapi_opt_t
|
|
||||||
*/
|
|
||||||
enum nsapi_opt_t {
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Enum of socket protocols
|
/** Enum of socket protocols
|
||||||
* @enum protocol_t
|
* @enum protocol_t
|
||||||
*/
|
*/
|
||||||
|
@ -93,6 +87,24 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int gethostbyname(SocketAddress *address, const char *name);
|
virtual int gethostbyname(SocketAddress *address, const char *name);
|
||||||
|
|
||||||
|
/* Set stack options
|
||||||
|
* @param level Option level
|
||||||
|
* @param optname Option identifier
|
||||||
|
* @param optval Option value
|
||||||
|
* @param optlen Length of the option value
|
||||||
|
* @return 0 on success, negative on failure
|
||||||
|
*/
|
||||||
|
virtual int setstackopt(int level, int optname, const void *optval, unsigned optlen);
|
||||||
|
|
||||||
|
/* Get stack options
|
||||||
|
* @param level Option level
|
||||||
|
* @param optname Option identifier
|
||||||
|
* @param optval Buffer where to write option value
|
||||||
|
* @param optlen Length of the option value
|
||||||
|
* @return 0 on success, negative on failure
|
||||||
|
*/
|
||||||
|
virtual int getstackopt(int level, int optname, void *optval, unsigned *optlen);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Socket;
|
friend class Socket;
|
||||||
friend class UDPSocket;
|
friend class UDPSocket;
|
||||||
|
@ -114,24 +126,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual int socket_close(void *handle) = 0;
|
virtual int socket_close(void *handle) = 0;
|
||||||
|
|
||||||
/** Set socket options
|
|
||||||
* @param handle Socket handle
|
|
||||||
* @param optname Option ID
|
|
||||||
* @param optval Option value
|
|
||||||
* @param optlen Length of the option value
|
|
||||||
* @return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen) = 0;
|
|
||||||
|
|
||||||
/** Get socket options
|
|
||||||
* @param handle Socket handle
|
|
||||||
* @param optname Option ID
|
|
||||||
* @param optval Buffer pointer where to write the option value
|
|
||||||
* @param optlen Length of the option value
|
|
||||||
* @return 0 on success, negative on failure
|
|
||||||
*/
|
|
||||||
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen) = 0;
|
|
||||||
|
|
||||||
/** Bind a server socket to a specific port
|
/** Bind a server socket to a specific port
|
||||||
* @param handle Socket handle
|
* @param handle Socket handle
|
||||||
* @param address Local address to listen for incoming connections on
|
* @param address Local address to listen for incoming connections on
|
||||||
|
@ -220,6 +214,26 @@ protected:
|
||||||
* @note Callback may be called in an interrupt context.
|
* @note Callback may be called in an interrupt context.
|
||||||
*/
|
*/
|
||||||
virtual void socket_attach(void *handle, void (*callback)(void *), void *data) = 0;
|
virtual void socket_attach(void *handle, void (*callback)(void *), void *data) = 0;
|
||||||
|
|
||||||
|
/* Set socket options
|
||||||
|
* @param handle Socket handle
|
||||||
|
* @param level Option level
|
||||||
|
* @param optname Option identifier
|
||||||
|
* @param optval Option value
|
||||||
|
* @param optlen Length of the option value
|
||||||
|
* @return 0 on success, negative on failure
|
||||||
|
*/
|
||||||
|
virtual int setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen);
|
||||||
|
|
||||||
|
/* Get socket options
|
||||||
|
* @param handle Socket handle
|
||||||
|
* @param level Option level
|
||||||
|
* @param optname Option identifier
|
||||||
|
* @param optval Buffer where to write option value
|
||||||
|
* @param optlen Length of the option value
|
||||||
|
* @return 0 on success, negative on failure
|
||||||
|
*/
|
||||||
|
virtual int getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -89,22 +89,23 @@ void Socket::set_timeout(unsigned timeout)
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::set_option(int optname, const void *optval, unsigned int optlen)
|
int Socket::setsockopt(int level, int optname, const void *optval, unsigned optlen)
|
||||||
{
|
{
|
||||||
if (!_socket) {
|
if (!_socket) {
|
||||||
return NSAPI_ERROR_NO_SOCKET;
|
return NSAPI_ERROR_NO_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _iface->socket_set_option(_socket, optname, optval, optlen);
|
return _iface->setsockopt(_socket, level, optname, optval, optlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::get_option(int optname, void *optval, unsigned int *optlen)
|
int Socket::getsockopt(int level, int optname, void *optval, unsigned *optlen)
|
||||||
{
|
{
|
||||||
if (!_socket) {
|
if (!_socket) {
|
||||||
return NSAPI_ERROR_NO_SOCKET;
|
return NSAPI_ERROR_NO_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _iface->socket_get_option(_socket, optname, optval, optlen);
|
return _iface->getsockopt(_socket, level, optname, optval, optlen);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::thunk(void *data)
|
void Socket::thunk(void *data)
|
||||||
|
|
|
@ -33,6 +33,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int open(NetworkInterface *iface) = 0;
|
virtual int open(NetworkInterface *iface) = 0;
|
||||||
|
|
||||||
|
/** Close the socket
|
||||||
|
*/
|
||||||
|
int close();
|
||||||
|
|
||||||
/** Bind a socket to a specific port
|
/** Bind a socket to a specific port
|
||||||
* @param port The port to listen for incoming connections on
|
* @param port The port to listen for incoming connections on
|
||||||
* @return 0 on success, negative on failure.
|
* @return 0 on success, negative on failure.
|
||||||
|
@ -63,24 +67,22 @@ public:
|
||||||
void set_timeout(unsigned int timeout);
|
void set_timeout(unsigned int timeout);
|
||||||
|
|
||||||
/* Set socket options
|
/* Set socket options
|
||||||
* @param optname Option ID
|
* @param level Option level
|
||||||
|
* @param optname Option identifier
|
||||||
* @param optval Option value
|
* @param optval Option value
|
||||||
* @param optlen Length of the option value
|
* @param optlen Length of the option value
|
||||||
* @return 0 on success, negative on failure
|
* @return 0 on success, negative on failure
|
||||||
*/
|
*/
|
||||||
int set_option(int optname, const void *optval, unsigned optlen);
|
int setsockopt(int level, int optname, const void *optval, unsigned optlen);
|
||||||
|
|
||||||
/* Get socket options
|
/* Get socket options
|
||||||
* @param optname Option ID
|
* @param level Option level
|
||||||
* @param optval Buffer pointer where to write the option value
|
* @param optname Option identifier
|
||||||
|
* @param optval Buffer where to write option value
|
||||||
* @param optlen Length of the option value
|
* @param optlen Length of the option value
|
||||||
* @return 0 on success, negative on failure
|
* @return 0 on success, negative on failure
|
||||||
*/
|
*/
|
||||||
int get_option(int optname, void *optval, unsigned *optlen);
|
int getsockopt(int level, int optname, void *optval, unsigned *optlen);
|
||||||
|
|
||||||
/** Close the socket
|
|
||||||
*/
|
|
||||||
int close();
|
|
||||||
|
|
||||||
/** Register a callback on state change of the socket
|
/** Register a callback on state change of the socket
|
||||||
* @param callback Function to call on state change
|
* @param callback Function to call on state change
|
||||||
|
|
Loading…
Reference in New Issue