Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/net/sal/impl/af_inet_at.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static int at_poll(struct dfs_file *file, struct rt_pollreq *req)
}

sock = at_get_socket((int)sal_sock->user_data);
sal_socket_put(sal_sock);
if (sock != NULL)
{
rt_base_t level;
Expand Down
1 change: 1 addition & 0 deletions components/net/sal/impl/af_inet_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
}

sock = lwip_tryget_socket((int)(size_t)sal_sock->user_data);
sal_socket_put(sal_sock);
if (sock != NULL)
{
rt_base_t level;
Expand Down
13 changes: 2 additions & 11 deletions components/net/sal/impl/proto_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ int mbedtls_net_send_cb(void *ctx, const unsigned char *buf, size_t len)

/* Register scoket sendto option to TLS send data callback */
ret = pf->skt_ops->sendto((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL);
sal_socket_put(sock);
if (ret < 0)
{
#ifdef RT_USING_DFS
Expand Down Expand Up @@ -133,6 +134,7 @@ int mbedtls_net_recv_cb( void *ctx, unsigned char *buf, size_t len)

/* Register scoket recvfrom option to TLS recv data callback */
ret = pf->skt_ops->recvfrom((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL);
sal_socket_put(sock);
if (ret < 0)
{
#ifdef RT_USING_DFS
Expand Down Expand Up @@ -199,24 +201,13 @@ static int mbedtls_connect(void *sock)

static int mbedtls_closesocket(void *sock)
{
struct sal_socket *ssock;
int socket;

if (sock == RT_NULL)
{
return 0;
}

socket = ((MbedTLSSession *) sock)->server_fd.fd;
ssock = sal_get_socket(socket);
if (ssock == RT_NULL)
{
return -1;
}

/* Close TLS client session, and clean user-data in SAL socket */
mbedtls_client_close((MbedTLSSession *) sock);
ssock->user_data_tls = RT_NULL;

return 0;
}
Expand Down
15 changes: 14 additions & 1 deletion components/net/sal/include/sal_low_lvl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SAL_LOW_LEVEL_H__

#include <rtdevice.h>
#include <ipc/completion.h>

#ifdef SAL_USING_POSIX
#include <dfs_file.h>
Expand All @@ -30,6 +31,14 @@ typedef uint32_t socklen_t;
/* SAL socket magic word */
#define SAL_SOCKET_MAGIC 0x5A10

enum sal_socket_state
{
SAL_SOCKET_STATE_INIT = 0,
SAL_SOCKET_STATE_OPEN, /* visible in socket table */
SAL_SOCKET_STATE_CLOSING, /* detached, waiting refcnt drop */
SAL_SOCKET_STATE_CLOSED, /* ready for cache reuse */
};

/* The maximum number of sockets structure */
#ifndef SAL_SOCKETS_NUM
#define SAL_SOCKETS_NUM DFS_FD_MAX
Expand Down Expand Up @@ -63,6 +72,10 @@ struct sal_socket
#ifdef SAL_USING_TLS
void *user_data_tls; /* user-specific TLS data */
#endif
rt_atomic_t refcnt; /* in-flight SAL references */
rt_uint8_t state; /* socket lifecycle state */
struct rt_completion close_completion; /* wake close waiter */
struct sal_socket *next_free; /* internal cache link */
};

/* network interface socket opreations */
Expand Down Expand Up @@ -109,8 +122,8 @@ struct sal_proto_family

/* SAL(Socket Abstraction Layer) initialize */
int sal_init(void);
/* Get SAL socket object by socket descriptor */
struct sal_socket *sal_get_socket(int sock);
void sal_socket_put(struct sal_socket *sock);

/* check SAL socket netweork interface device internet status */
int sal_check_netdev_internet_up(struct netdev *netdev);
Expand Down
Loading
Loading