Added support for NSAPI_KEEPALIVE in LWIPInterface

pull/2231/head
Christopher Haster 2016-06-07 10:52:39 -05:00
parent 05b21d7b2d
commit b251c59ffe
2 changed files with 33 additions and 0 deletions

View File

@ -545,6 +545,24 @@ int LWIPInterface::socket_recvfrom(void *handle, SocketAddress *addr, void *buf,
return copied;
}
int LWIPInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) {
struct lwip_socket *s = (struct lwip_socket *)handle;
switch (optname) {
case NSAPI_KEEPALIVE:
if (optlen != sizeof(int) || s->proto != NSAPI_TCP) {
return NSAPI_ERROR_UNSUPPORTED;
}
s->tcp->so_options |= SOF_KEEPALIVE;
s->tcp->keep_intvl = *(int*)optval;
return 0;
default:
return NSAPI_ERROR_UNSUPPORTED;
}
}
void LWIPInterface::socket_attach(void *handle, void (*callback)(void *), void *data)
{
struct lwip_socket *s = (struct lwip_socket *)handle;

View File

@ -139,6 +139,21 @@ protected:
*/
virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
/* Set stack-specific socket options
*
* The setsockopt allow an application to pass stack-specific hints
* to the underlying stack. For unsupported options,
* NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
*
* @param handle Socket handle
* @param level Stack-specific protocol level
* @param optname Stack-specific option identifier
* @param optval Option value
* @param optlen Length of the option value
* @return 0 on success, negative error code on failure
*/
virtual int setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen);
/** Register a callback on state change of the socket
* @param handle Socket handle
* @param callback Function to call on state change