Skip to content

Commit

Permalink
Adds SO_RCVBUF and SO_KEEPALIVETIME support for cc32xx setsockopt. (#367
Browse files Browse the repository at this point in the history
)

* Adds support for SO_RCVBUF.
Adds logging for the TX failed socket async event.

* fix whitespace
  • Loading branch information
balazsracz authored Mar 21, 2020
1 parent 9199e80 commit c54ec6d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
12 changes: 9 additions & 3 deletions include/freertos_select/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,22 @@ extern "C" {
#define PF_INET6 AF_INET6

/** socket option category */
#define SOL_SOCKET (1)
#define SOL_SOCKET (1)

/** socket option to reuse address */
#define SO_REUSEADDR (2)

/** socket option receive timout */
#define SO_RCVTIMEO (3)
#define SO_RCVTIMEO (3)

/** socket option send timeout */
#define SO_SNDTIMEO (4)
#define SO_SNDTIMEO (4)

/** socket option for receive buffer size */
#define SO_RCVBUF (8)

/** socket option to set TCP keepalive timeout */
#define SO_KEEPALIVETIME (1001)

/** IPv4 socket address */
struct sockaddr
Expand Down
39 changes: 38 additions & 1 deletion src/freertos_drivers/net_cc32xx/CC32xxSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <ifaddrs.h>
#include <sys/socket.h>

// Simplelink includes
#include <ti/drivers/net/wifi/simplelink.h>

#include "utils/format_utils.hxx"
#include "utils/logging.h"

/// @todo (Stuart Baker) since there is only a max of 16 sockets, would it be
/// more memory efficient to just allocate all the memory statically as an
Expand Down Expand Up @@ -502,6 +504,7 @@ ssize_t CC32xxSocket::send(int socket, const void *buffer, size_t length, int fl

if (result < 0)
{
LOG_ERROR("sl socket write return error %d", result);
switch (result)
{
case SL_ERROR_BSD_SOC_ERROR:
Expand Down Expand Up @@ -569,6 +572,22 @@ int CC32xxSocket::setsockopt(int socket, int level, int option_name,
sizeof(timeval));
break;
}
case SO_RCVBUF:
{
SlSocklen_t sl_option_len = option_len;

result = sl_SetSockOpt(s->sd, SL_SOL_SOCKET, SL_SO_RCVBUF,
option_value, sl_option_len);
break;
}
case SO_KEEPALIVETIME:
{
SlSocklen_t sl_option_len = option_len;

result = sl_SetSockOpt(s->sd, SL_SOL_SOCKET,
SL_SO_KEEPALIVETIME, option_value, sl_option_len);
break;
}
}
break;
case IPPROTO_TCP:
Expand All @@ -578,7 +597,7 @@ int CC32xxSocket::setsockopt(int socket, int level, int option_name,
errno = EINVAL;
return -1;
case TCP_NODELAY:
/* CC32xx does not care about Nagel algorithm, ignore it */
/* CC32xx does not care about Nagle algorithm, ignore it */
result = 0;
break;
}
Expand Down Expand Up @@ -651,6 +670,24 @@ int CC32xxSocket::getsockopt(int socket, int level, int option_name,
*option_len = sizeof(struct timeval);
break;
}
case SO_RCVBUF:
{
SlSocklen_t sl_option_len = *option_len;

result = sl_GetSockOpt(s->sd, SL_SOL_SOCKET, SL_SO_RCVBUF,
option_value, &sl_option_len);
*option_len = sl_option_len;
break;
}
case SO_KEEPALIVETIME:
{
SlSocklen_t sl_option_len = *option_len;

result = sl_GetSockOpt(s->sd, SL_SOL_SOCKET,
SL_SO_KEEPALIVETIME, option_value, &sl_option_len);
*option_len = sl_option_len;
break;
}
}
break;
case IPPROTO_TCP:
Expand Down
3 changes: 3 additions & 0 deletions src/freertos_drivers/net_cc32xx/CC32xxWiFi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,9 @@ void CC32xxWiFi::sock_event_handler(SockEvent *event)
switch (event->Event)
{
case SL_SOCKET_TX_FAILED_EVENT:
LOG(ALWAYS, "Socket tx fail status %d, sd %u",
(int)event->SocketAsyncEvent.SockTxFailData.Status,
(unsigned)event->SocketAsyncEvent.SockTxFailData.Sd);
switch (event->SocketAsyncEvent.SockTxFailData.Status)
{
case SL_ERROR_BSD_ECLOSE:
Expand Down

0 comments on commit c54ec6d

Please sign in to comment.