Revised stack specific configurations

Adds the following functions for direct configuration of interface
- (set|get)stackopt
- (set|get)sockopt
pull/2216/head^2
Christopher Haster 2016-03-13 18:47:41 -05:00
parent 63725d653c
commit 3fa1bb6469
4 changed files with 77 additions and 40 deletions

View File

@ -28,3 +28,23 @@ int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
address->set_ip_address(buffer);
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;
}

View File

@ -36,12 +36,6 @@ enum nsapi_error_t {
NSAPI_ERROR_AUTH_FAILURE = -3009, /*!< connection to access point faield */
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 protocol_t
@ -93,6 +87,24 @@ public:
*/
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:
friend class Socket;
friend class UDPSocket;
@ -114,24 +126,6 @@ protected:
*/
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
* @param handle Socket handle
* @param address Local address to listen for incoming connections on
@ -220,6 +214,26 @@ protected:
* @note Callback may be called in an interrupt context.
*/
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

View File

@ -89,22 +89,23 @@ void Socket::set_timeout(unsigned 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) {
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) {
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)

View File

@ -33,6 +33,10 @@ public:
*/
virtual int open(NetworkInterface *iface) = 0;
/** Close the socket
*/
int close();
/** Bind a socket to a specific port
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
@ -63,24 +67,22 @@ public:
void set_timeout(unsigned int timeout);
/* Set socket options
* @param optname Option ID
* @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
*/
int set_option(int optname, const void *optval, unsigned optlen);
*/
int setsockopt(int level, int optname, const void *optval, unsigned optlen);
/* Get socket options
* @param optname Option ID
* @param optval Buffer pointer where to write the option value
* @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
*/
int get_option(int optname, void *optval, unsigned *optlen);
/** Close the socket
*/
int close();
*/
int getsockopt(int level, int optname, void *optval, unsigned *optlen);
/** Register a callback on state change of the socket
* @param callback Function to call on state change