Skip to content

Commit 41ae59d

Browse files
committed
Merge pull request #474 from BernardXiong/master
Update for dfs_lwip and completion.
2 parents 8330ee5 + 77b5098 commit 41ae59d

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

components/dfs/filesystems/lwip/lwip_sockets.c

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,48 @@
3232

3333
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
3434
{
35+
int new_client = -1;
3536
int sock = dfs_lwip_getsocket(s);
3637

37-
return lwip_accept(sock, addr, addrlen);
38+
new_client = lwip_accept(sock, addr, addrlen);
39+
if (new_client != -1)
40+
{
41+
/* this is a new socket, create it in file system fd */
42+
int fd;
43+
struct dfs_fd *d;
44+
45+
/* allocate a fd */
46+
fd = fd_new();
47+
if (fd < 0)
48+
{
49+
rt_set_errno(-DFS_STATUS_ENOMEM);
50+
lwip_close(sock);
51+
52+
printf("no fd yet!\n");
53+
return -1;
54+
}
55+
d = fd_get(fd);
56+
57+
/* this is a socket fd */
58+
d->type = FT_SOCKET;
59+
d->path = RT_NULL;
60+
61+
d->fs = dfs_lwip_get_fs();
62+
63+
d->flags = DFS_O_RDWR; /* set flags as read and write */
64+
d->size = 0;
65+
d->pos = 0;
66+
67+
/* set socket to the data of dfs_fd */
68+
d->data = (void*) new_client;
69+
70+
/* release the ref-count of fd */
71+
fd_put(d);
72+
73+
return fd;
74+
}
75+
76+
return new_client;
3877
}
3978

4079
int bind(int s, const struct sockaddr *name, socklen_t namelen)
@@ -46,9 +85,28 @@ int bind(int s, const struct sockaddr *name, socklen_t namelen)
4685

4786
int shutdown(int s, int how)
4887
{
49-
int sock = dfs_lwip_getsocket(s);
88+
int sock;
89+
struct dfs_fd *d;
90+
91+
d = fd_get(s);
92+
if (d == RT_NULL)
93+
{
94+
rt_set_errno(-DFS_STATUS_EBADF);
95+
96+
return -1;
97+
}
98+
99+
sock = dfs_lwip_getsocket(s);
100+
if (lwip_shutdown(sock, how) == 0)
101+
{
102+
/* socket has been closed, delete it from file system fd */
103+
fd_put(d);
104+
fd_put(d);
105+
106+
return 0;
107+
}
50108

51-
return lwip_shutdown(s, how);
109+
return -1;
52110
}
53111

54112
int getpeername (int s, struct sockaddr *name, socklen_t *namelen)
@@ -163,3 +221,4 @@ int socket(int domain, int type, int protocol)
163221

164222
return fd;
165223
}
224+

components/drivers/src/completion.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void rt_completion_init(struct rt_completion *completion)
3939
rt_list_init(&completion->suspended_list);
4040
rt_hw_interrupt_enable(level);
4141
}
42+
RTM_EXPORT(rt_completion_init);
4243

4344
rt_err_t rt_completion_wait(struct rt_completion *completion,
4445
rt_int32_t timeout)
@@ -105,6 +106,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
105106

106107
return result;
107108
}
109+
RTM_EXPORT(rt_completion_wait);
108110

109111
void rt_completion_done(struct rt_completion *completion)
110112
{
@@ -139,3 +141,5 @@ void rt_completion_done(struct rt_completion *completion)
139141
rt_hw_interrupt_enable(level);
140142
}
141143
}
144+
RTM_EXPORT(rt_completion_done);
145+

components/libc/armlibc/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "sys/unistd.h"

0 commit comments

Comments
 (0)