mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #2566 from kushalsingh007/fd
Changed description for fd_t::fd in sys/include/fd.h
This commit is contained in:
commit
7256a1399a
@ -4,7 +4,7 @@ simple appserver (all in one shell)
|
|||||||
0. create tap devices: *./cpu/native/tapsetup.sh create 3*
|
0. create tap devices: *./cpu/native/tapsetup.sh create 3*
|
||||||
1. build ccn-lite-client: *make -B clean all-valgrind*
|
1. build ccn-lite-client: *make -B clean all-valgrind*
|
||||||
2. start: *./bin/native/ccn-lite-client.elf tap0* (valgrind support included)
|
2. start: *./bin/native/ccn-lite-client.elf tap0* (valgrind support included)
|
||||||
3. optinonal: *config 20* [enter] (this sets the content store size)
|
3. optional: *config 20* [enter] (this sets the content store size)
|
||||||
4. start appserver thread: *appserver* [enter] (this starts the userland appserver, which registers for "/riot/appserver/"
|
4. start appserver thread: *appserver* [enter] (this starts the userland appserver, which registers for "/riot/appserver/"
|
||||||
5. request content: *interest /riot/appserver/test* [enter] (ask the relay for this "file", userland code splits this up in
|
5. request content: *interest /riot/appserver/test* [enter] (ask the relay for this "file", userland code splits this up in
|
||||||
chunks and requests them from the relay. In the relay the name "/riot/appserver" is registered to the RIOT MSG face with
|
chunks and requests them from the relay. In the relay the name "/riot/appserver" is registered to the RIOT MSG face with
|
||||||
|
@ -34,13 +34,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** private status of this fd_t */
|
/** private status of this fd_t */
|
||||||
int __active;
|
int internal_active;
|
||||||
|
|
||||||
/** the internal filedescriptor */
|
/** Stores the RIOT internal value for the file descriptor (not POSIX). */
|
||||||
int fd;
|
int internal_fd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read *n* into *buf* from *fd*. Return the
|
* Read *n* bytes into *buf* from *fd*. Return the
|
||||||
* number read, -1 for errors or 0 for EOF.
|
* number read, -1 for errors or 0 for EOF.
|
||||||
*/
|
*/
|
||||||
ssize_t (*read)(int fd, void *buf, size_t n);
|
ssize_t (*read)(int fd, void *buf, size_t n);
|
||||||
|
@ -43,8 +43,8 @@ int fd_init(void)
|
|||||||
#ifdef MODULE_UART0
|
#ifdef MODULE_UART0
|
||||||
posix_open(uart0_handler_pid, 0);
|
posix_open(uart0_handler_pid, 0);
|
||||||
fd_t fd = {
|
fd_t fd = {
|
||||||
.__active = 1,
|
.internal_active = 1,
|
||||||
.fd = (int)uart0_handler_pid,
|
.internal_fd = (int)uart0_handler_pid,
|
||||||
.read = (ssize_t ( *)(int, void *, size_t))posix_read,
|
.read = (ssize_t ( *)(int, void *, size_t))posix_read,
|
||||||
.write = (ssize_t ( *)(int, const void *, size_t))posix_write,
|
.write = (ssize_t ( *)(int, const void *, size_t))posix_write,
|
||||||
.close = posix_close
|
.close = posix_close
|
||||||
@ -61,7 +61,7 @@ static int fd_get_next_free(void)
|
|||||||
for (int i = 0; i < FD_MAX; i++) {
|
for (int i = 0; i < FD_MAX; i++) {
|
||||||
fd_t *cur = &fd_table[i];
|
fd_t *cur = &fd_table[i];
|
||||||
|
|
||||||
if (!cur->__active) {
|
if (!cur->internal_active) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,8 +77,8 @@ int fd_new(int internal_fd, ssize_t (*internal_read)(int, void *, size_t),
|
|||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
fd_t *fd_s = fd_get(fd);
|
fd_t *fd_s = fd_get(fd);
|
||||||
fd_s->__active = 1;
|
fd_s->internal_active = 1;
|
||||||
fd_s->fd = internal_fd;
|
fd_s->internal_fd = internal_fd;
|
||||||
fd_s->read = internal_read;
|
fd_s->read = internal_read;
|
||||||
fd_s->write = internal_write;
|
fd_s->write = internal_write;
|
||||||
fd_s->close = internal_close;
|
fd_s->close = internal_close;
|
||||||
|
@ -45,7 +45,7 @@ int socket(int domain, int type, int protocol)
|
|||||||
|
|
||||||
#define sock_func_wrapper(func, sockfd, ...) \
|
#define sock_func_wrapper(func, sockfd, ...) \
|
||||||
((fd_get(sockfd)) ? \
|
((fd_get(sockfd)) ? \
|
||||||
func(fd_get(sockfd)->fd, __VA_ARGS__) : \
|
func(fd_get(sockfd)->internal_fd, __VA_ARGS__) : \
|
||||||
(errno = EBADF, -1))
|
(errno = EBADF, -1))
|
||||||
|
|
||||||
int accept(int socket, struct sockaddr *restrict address,
|
int accept(int socket, struct sockaddr *restrict address,
|
||||||
|
@ -27,12 +27,12 @@ int close(int fildes)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd_obj->close(fd_obj->fd) < 0) {
|
if (fd_obj->close(fd_obj->internal_fd) < 0) {
|
||||||
errno = EIO; // EINTR may not occur since RIOT has no signals yet.
|
errno = EIO; // EINTR may not occur since RIOT has no signals yet.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_destroy(fd_obj->fd);
|
fd_destroy(fd_obj->internal_fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user