summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2015-05-11 12:35:36 +0800
committerBernard Xiong <[email protected]>2015-05-11 12:35:36 +0800
commit41ae59d3348f190ac6352299e4759acf4f887bab (patch)
treee28c6db1bd01b735995d4dc31ac6afd1dd143ecf
parent8330ee5f563a4419b764d24b500aa79dcc34746d (diff)
parent77b5098ae23d9071911878e908cd4f8353f64dcd (diff)
Merge pull request #474 from BernardXiong/master
Update for dfs_lwip and completion.
-rw-r--r--components/dfs/filesystems/lwip/lwip_sockets.c65
-rw-r--r--components/drivers/src/completion.c4
-rw-r--r--components/libc/armlibc/unistd.h1
3 files changed, 67 insertions, 3 deletions
diff --git a/components/dfs/filesystems/lwip/lwip_sockets.c b/components/dfs/filesystems/lwip/lwip_sockets.c
index 153f4444bd..346ef7b266 100644
--- a/components/dfs/filesystems/lwip/lwip_sockets.c
+++ b/components/dfs/filesystems/lwip/lwip_sockets.c
@@ -32,9 +32,48 @@
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
+ int new_client = -1;
int sock = dfs_lwip_getsocket(s);
- return lwip_accept(sock, addr, addrlen);
+ new_client = lwip_accept(sock, addr, addrlen);
+ if (new_client != -1)
+ {
+ /* this is a new socket, create it in file system fd */
+ int fd;
+ struct dfs_fd *d;
+
+ /* allocate a fd */
+ fd = fd_new();
+ if (fd < 0)
+ {
+ rt_set_errno(-DFS_STATUS_ENOMEM);
+ lwip_close(sock);
+
+ printf("no fd yet!\n");
+ return -1;
+ }
+ d = fd_get(fd);
+
+ /* this is a socket fd */
+ d->type = FT_SOCKET;
+ d->path = RT_NULL;
+
+ d->fs = dfs_lwip_get_fs();
+
+ d->flags = DFS_O_RDWR; /* set flags as read and write */
+ d->size = 0;
+ d->pos = 0;
+
+ /* set socket to the data of dfs_fd */
+ d->data = (void*) new_client;
+
+ /* release the ref-count of fd */
+ fd_put(d);
+
+ return fd;
+ }
+
+ return new_client;
}
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)
int shutdown(int s, int how)
{
- int sock = dfs_lwip_getsocket(s);
+ int sock;
+ struct dfs_fd *d;
+
+ d = fd_get(s);
+ if (d == RT_NULL)
+ {
+ rt_set_errno(-DFS_STATUS_EBADF);
+
+ return -1;
+ }
+
+ sock = dfs_lwip_getsocket(s);
+ if (lwip_shutdown(sock, how) == 0)
+ {
+ /* socket has been closed, delete it from file system fd */
+ fd_put(d);
+ fd_put(d);
+
+ return 0;
+ }
- return lwip_shutdown(s, how);
+ return -1;
}
int getpeername (int s, struct sockaddr *name, socklen_t *namelen)
@@ -163,3 +221,4 @@ int socket(int domain, int type, int protocol)
return fd;
}
+
diff --git a/components/drivers/src/completion.c b/components/drivers/src/completion.c
index 48afc2ee34..ef0b2911a7 100644
--- a/components/drivers/src/completion.c
+++ b/components/drivers/src/completion.c
@@ -39,6 +39,7 @@ void rt_completion_init(struct rt_completion *completion)
rt_list_init(&completion->suspended_list);
rt_hw_interrupt_enable(level);
}
+RTM_EXPORT(rt_completion_init);
rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_int32_t timeout)
@@ -105,6 +106,7 @@ __exit:
return result;
}
+RTM_EXPORT(rt_completion_wait);
void rt_completion_done(struct rt_completion *completion)
{
@@ -139,3 +141,5 @@ void rt_completion_done(struct rt_completion *completion)
rt_hw_interrupt_enable(level);
}
}
+RTM_EXPORT(rt_completion_done);
+
diff --git a/components/libc/armlibc/unistd.h b/components/libc/armlibc/unistd.h
new file mode 100644
index 0000000000..3de0eaf398
--- /dev/null
+++ b/components/libc/armlibc/unistd.h
@@ -0,0 +1 @@
+#include "sys/unistd.h"