summaryrefslogtreecommitdiffstats
path: root/src/vlib/unix/unix.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-09-08 19:52:02 +0200
committerFlorin Coras <florin.coras@gmail.com>2017-09-09 20:11:03 +0000
commit56dd5438b04b869065d8e901c315496bb6777455 (patch)
tree517190c53cfd2725d716eda6dddf9a64ad814084 /src/vlib/unix/unix.h
parent816122e303efb5012f6897bd53ff8fe28cd8fa1c (diff)
move unix_file_* code to vppinfra
This will allow us to use this code in client libraries without vlib. Change-Id: I8557b752496841ba588aa36b6082cbe2cd1867fe Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/unix/unix.h')
-rw-r--r--src/vlib/unix/unix.h76
1 files changed, 2 insertions, 74 deletions
diff --git a/src/vlib/unix/unix.h b/src/vlib/unix/unix.h
index 1b0d8b9d384..4c8566b7ee8 100644
--- a/src/vlib/unix/unix.h
+++ b/src/vlib/unix/unix.h
@@ -40,42 +40,16 @@
#ifndef included_unix_unix_h
#define included_unix_unix_h
+#include <vppinfra/file.h>
#include <vppinfra/socket.h>
#include <termios.h>
-
-struct unix_file;
-typedef clib_error_t *(unix_file_function_t) (struct unix_file * f);
-
-typedef struct unix_file
-{
- /* Unix file descriptor from open/socket. */
- u32 file_descriptor;
-
- u32 flags;
-#define UNIX_FILE_DATA_AVAILABLE_TO_WRITE (1 << 0)
-#define UNIX_FILE_EVENT_EDGE_TRIGGERED (1 << 1)
-
- /* Data available for function's use. */
- uword private_data;
-
- /* Functions to be called when read/write data becomes ready. */
- unix_file_function_t *read_function, *write_function, *error_function;
-} unix_file_t;
-
typedef struct
{
f64 time;
clib_error_t *error;
} unix_error_history_t;
-typedef enum
-{
- UNIX_FILE_UPDATE_ADD,
- UNIX_FILE_UPDATE_MODIFY,
- UNIX_FILE_UPDATE_DELETE,
-} unix_file_update_type_t;
-
typedef struct
{
/* Back pointer to main structure. */
@@ -86,15 +60,9 @@ typedef struct
#define UNIX_FLAG_INTERACTIVE (1 << 0)
#define UNIX_FLAG_NODAEMON (1 << 1)
- /* Pool of files to poll for input/output. */
- unix_file_t *file_pool;
-
/* CLI listen socket. */
clib_socket_t cli_listen_socket;
- void (*file_update) (unix_file_t * file,
- unix_file_update_type_t update_type);
-
/* Circular buffer of last unix errors. */
unix_error_history_t error_history[128];
u32 error_history_index;
@@ -138,47 +106,7 @@ typedef struct
/* Global main structure. */
extern unix_main_t unix_main;
-
-always_inline uword
-unix_file_add (unix_main_t * um, unix_file_t * template)
-{
- unix_file_t *f;
- pool_get (um->file_pool, f);
- f[0] = template[0];
- um->file_update (f, UNIX_FILE_UPDATE_ADD);
- return f - um->file_pool;
-}
-
-always_inline void
-unix_file_del (unix_main_t * um, unix_file_t * f)
-{
- um->file_update (f, UNIX_FILE_UPDATE_DELETE);
- close (f->file_descriptor);
- f->file_descriptor = ~0;
- pool_put (um->file_pool, f);
-}
-
-always_inline void
-unix_file_del_by_index (unix_main_t * um, uword index)
-{
- unix_file_t *uf;
- uf = pool_elt_at_index (um->file_pool, index);
- unix_file_del (um, uf);
-}
-
-always_inline uword
-unix_file_set_data_available_to_write (u32 unix_file_index,
- uword is_available)
-{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool, unix_file_index);
- uword was_available = (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
- if ((was_available != 0) != (is_available != 0))
- {
- uf->flags ^= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
- unix_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
- }
- return was_available != 0;
-}
+extern clib_file_main_t file_main;
always_inline void
unix_save_error (unix_main_t * um, clib_error_t * error)