From 1c617a495fdc6bb91e29bf00df4c837f63d63199 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 28 Oct 2009 11:06:31 -0700 Subject: [PATCH] byteq: Move from extras/ezio into lib and export some private functions. The upcoming JSON-RPC library wants to use this library, and it needs some functions that are currently declared static. --- extras/ezio/automake.mk | 2 -- extras/ezio/ezio-term.c | 2 +- lib/automake.mk | 2 ++ {extras/ezio => lib}/byteq.c | 57 ++++++++++++++++-------------------- {extras/ezio => lib}/byteq.h | 7 +++++ 5 files changed, 35 insertions(+), 35 deletions(-) rename {extras/ezio => lib}/byteq.c (81%) rename {extras/ezio => lib}/byteq.h (83%) diff --git a/extras/ezio/automake.mk b/extras/ezio/automake.mk index 7c7db241..eae11cd1 100644 --- a/extras/ezio/automake.mk +++ b/extras/ezio/automake.mk @@ -25,8 +25,6 @@ install-data-hook: bin_PROGRAMS += extras/ezio/ezio-term extras_ezio_ezio_term_SOURCES = \ - extras/ezio/byteq.c \ - extras/ezio/byteq.h \ extras/ezio/ezio-term.c \ extras/ezio/ezio.c \ extras/ezio/ezio.h \ diff --git a/extras/ezio/ezio-term.c b/extras/ezio/ezio-term.c index 846ccfde..8f12a7bc 100644 --- a/extras/ezio/ezio-term.c +++ b/extras/ezio/ezio-term.c @@ -26,8 +26,8 @@ #include #include #include +#include "byteq.h" #include "command-line.h" -#include "extras/ezio/byteq.h" #include "extras/ezio/tty.h" #include "extras/ezio/vt.h" #include "daemon.h" diff --git a/lib/automake.mk b/lib/automake.mk index fd791c28..8dc28990 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -14,6 +14,8 @@ lib_libopenvswitch_a_SOURCES = \ lib/backtrace.h \ lib/bitmap.c \ lib/bitmap.h \ + lib/byteq.c \ + lib/byteq.h \ lib/cfg.c \ lib/cfg.h \ lib/classifier.c \ diff --git a/extras/ezio/byteq.c b/lib/byteq.c similarity index 81% rename from extras/ezio/byteq.c rename to lib/byteq.c index b7df400f..aa1e06f7 100644 --- a/extras/ezio/byteq.c +++ b/lib/byteq.c @@ -14,7 +14,7 @@ */ #include -#include "extras/ezio/byteq.h" +#include "byteq.h" #include #include #include @@ -24,13 +24,6 @@ /* The queue size must be a power of 2. */ BUILD_ASSERT_DECL(!(BYTEQ_SIZE & (BYTEQ_SIZE - 1))); -static uint8_t *head(struct byteq *); -static int headroom(const struct byteq *); -static void advance_head(struct byteq *, unsigned int n); -static int tailroom(const struct byteq *); -static const uint8_t *tail(const struct byteq *); -static void advance_tail(struct byteq *, unsigned int n); - /* Initializes 'q' as empty. */ void byteq_init(struct byteq *q) @@ -73,7 +66,7 @@ void byteq_put(struct byteq *q, uint8_t c) { assert(!byteq_is_full(q)); - *head(q) = c; + *byteq_head(q) = c; q->head++; } @@ -85,9 +78,9 @@ byteq_putn(struct byteq *q, const void *p_, size_t n) const uint8_t *p = p_; assert(byteq_avail(q) >= n); while (n > 0) { - size_t chunk = MIN(n, headroom(q)); - memcpy(head(q), p, chunk); - advance_head(q, chunk); + size_t chunk = MIN(n, byteq_headroom(q)); + memcpy(byteq_head(q), p, chunk); + byteq_advance_head(q, chunk); p += chunk; n -= chunk; } @@ -108,7 +101,7 @@ byteq_get(struct byteq *q) { uint8_t c; assert(!byteq_is_empty(q)); - c = *tail(q); + c = *byteq_tail(q); q->tail++; return c; } @@ -120,9 +113,9 @@ int byteq_write(struct byteq *q, int fd) { while (!byteq_is_empty(q)) { - ssize_t n = write(fd, tail(q), tailroom(q)); + ssize_t n = write(fd, byteq_tail(q), byteq_tailroom(q)); if (n > 0) { - advance_tail(q, n); + byteq_advance_tail(q, n); } else { assert(n < 0); return errno; @@ -139,20 +132,20 @@ int byteq_read(struct byteq *q, int fd) { while (!byteq_is_full(q)) { - ssize_t n = read(fd, head(q), headroom(q)); + ssize_t n = read(fd, byteq_head(q), byteq_headroom(q)); if (n > 0) { - advance_head(q, n); + byteq_advance_head(q, n); } else { return !n ? EOF : errno; } } return 0; } - + /* Returns the number of contiguous bytes of in-use space starting at the tail * of 'q'. */ -static int -tailroom(const struct byteq *q) +int +byteq_tailroom(const struct byteq *q) { int used = byteq_used(q); int tail_to_end = BYTEQ_SIZE - (q->tail & (BYTEQ_SIZE - 1)); @@ -161,33 +154,33 @@ tailroom(const struct byteq *q) /* Returns the first in-use byte of 'q', the point at which data is removed * from 'q'. */ -static const uint8_t * -tail(const struct byteq *q) +const uint8_t * +byteq_tail(const struct byteq *q) { return &q->buffer[q->tail & (BYTEQ_SIZE - 1)]; } /* Removes 'n' bytes from the tail of 'q', which must have at least 'n' bytes * of tailroom. */ -static void -advance_tail(struct byteq *q, unsigned int n) +void +byteq_advance_tail(struct byteq *q, unsigned int n) { - assert(tailroom(q) >= n); + assert(byteq_tailroom(q) >= n); q->tail += n; } /* Returns the byte after the last in-use byte of 'q', the point at which new * data will be added to 'q'. */ -static uint8_t * -head(struct byteq *q) +uint8_t * +byteq_head(struct byteq *q) { return &q->buffer[q->head & (BYTEQ_SIZE - 1)]; } /* Returns the number of contiguous bytes of free space starting at the head * of 'q'. */ -static int -headroom(const struct byteq *q) +int +byteq_headroom(const struct byteq *q) { int avail = byteq_avail(q); int head_to_end = BYTEQ_SIZE - (q->head & (BYTEQ_SIZE - 1)); @@ -196,9 +189,9 @@ headroom(const struct byteq *q) /* Adds to 'q' the 'n' bytes after the last currently in-use byte of 'q'. 'q' * must have at least 'n' bytes of headroom. */ -static void -advance_head(struct byteq *q, unsigned int n) +void +byteq_advance_head(struct byteq *q, unsigned int n) { - assert(headroom(q) >= n); + assert(byteq_headroom(q) >= n); q->head += n; } diff --git a/extras/ezio/byteq.h b/lib/byteq.h similarity index 83% rename from extras/ezio/byteq.h rename to lib/byteq.h index 0a016cd5..84d8696f 100644 --- a/extras/ezio/byteq.h +++ b/lib/byteq.h @@ -42,4 +42,11 @@ uint8_t byteq_get(struct byteq *); int byteq_write(struct byteq *, int fd); int byteq_read(struct byteq *, int fd); +uint8_t *byteq_head(struct byteq *); +int byteq_headroom(const struct byteq *); +void byteq_advance_head(struct byteq *, unsigned int n); +int byteq_tailroom(const struct byteq *); +const uint8_t *byteq_tail(const struct byteq *); +void byteq_advance_tail(struct byteq *, unsigned int n); + #endif /* byteq.h */ -- 2.30.2