fb11e647
vrobic
reseau statique a...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* Copyright (C) 2013 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @addtogroup posix
* @{
*/
/**
* @file
* @brief Unifies diverse identifiers of RIOT to POSIX like file descriptors.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
*/
#ifndef FD_H
#define FD_H
#include <stdlib.h>
#include <sys/types.h>
#include "kernel_types.h"
#include "cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* File descriptor table.
*/
typedef struct {
/** private status of this fd_t */
int internal_active;
/** Stores the RIOT internal value for the file descriptor (not POSIX). */
int internal_fd;
/**
* Read *n* bytes into *buf* from *fd*. Return the
* number read, -1 for errors or 0 for EOF.
*/
ssize_t (*read)(int fd, void *buf, size_t n);
/** Write *n* bytes of *buf* to *fd*. Return the number written, or -1. */
ssize_t (*write)(int fd, const void *buf, size_t n);
/** Close the file descriptor *fd*. */
int (*close)(int fd);
} fd_t;
/**
* @brief Initializes file descriptors
*
* @return maximum number of available file descriptors.
*/
int fd_init(void);
/**
* @brief Creates a new file descriptor.
*
* @param[in] internal_fd RIOT-internal identifier for the new FD.
* @param[in] internal_read Function to read from new FD.
* @param[in] internal_write Function to write into new FD.
* @param[in] internal_close Function to close new FD.
*
* @return 0 on success, -1 otherwise. *errno* is set accordingly.
*/
int fd_new(int internal_fd, ssize_t (*internal_read)(int, void *, size_t),
ssize_t (*internal_write)(int, const void *, size_t),
int (*internal_close)(int));
/**
* @brief Gets the file descriptor table entry associated with file
* descriptor *fd*.
*
* @param[in] fd A POSIX-like file descriptor.
*
* @return The file descriptor table entry associated with file descriptor
*fd* or NULL if there is non.
*/
fd_t *fd_get(int fd);
/**
* @brief Removes file descriptor table entry associated with *fd* from table.
*
* @param[in] fd A POSIX-like file descriptor.
*/
void fd_destroy(int fd);
#ifdef __cplusplus
}
#endif
#endif /* FD_H */
/** @} */
|