aboutsummaryrefslogtreecommitdiff
path: root/lzo.c
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-10-02 03:41:35 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-10-02 03:41:35 +0000
commit537073fd55b3e35720e759c5c13e9da128a2b0bb (patch)
treef4d544e3e85bc2a32b33f6400ff74ec8d3826302 /lzo.c
parentRenamed sample-keys/tmp-ca.crt to ca.crt. (diff)
downloadopenvpn-537073fd55b3e35720e759c5c13e9da128a2b0bb.tar.xz
version 2.1_beta1
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@588 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to '')
-rw-r--r--lzo.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/lzo.c b/lzo.c
index 085ad11..85bfea2 100644
--- a/lzo.c
+++ b/lzo.c
@@ -44,9 +44,6 @@ lzo_adaptive_compress_test (struct lzo_adaptive_compress *ac)
const bool save = ac->compress_state;
const time_t local_now = now;
- if (!ac->enabled)
- return true;
-
if (!ac->compress_state)
{
if (local_now >= ac->next)
@@ -84,11 +81,8 @@ lzo_adaptive_compress_test (struct lzo_adaptive_compress *ac)
inline static void
lzo_adaptive_compress_data (struct lzo_adaptive_compress *ac, int n_total, int n_comp)
{
- if (ac->enabled)
- {
- ac->n_total += n_total;
- ac->n_comp += n_comp;
- }
+ ac->n_total += n_total;
+ ac->n_comp += n_comp;
}
void lzo_adjust_frame_parameters (struct frame *frame)
@@ -102,18 +96,19 @@ void lzo_adjust_frame_parameters (struct frame *frame)
}
void
-lzo_compress_init (struct lzo_compress_workspace *lzowork, bool adaptive)
+lzo_compress_init (struct lzo_compress_workspace *lzowork, unsigned int flags)
{
CLEAR (*lzowork);
lzowork->wmem_size = LZO_WORKSPACE;
- lzowork->ac.enabled = adaptive;
+ lzowork->flags = flags;
if (lzo_init () != LZO_E_OK)
msg (M_FATAL, "Cannot initialize LZO compression library");
lzowork->wmem = (lzo_voidp) lzo_malloc (lzowork->wmem_size);
check_malloc_return (lzowork->wmem);
msg (M_INFO, "LZO compression initialized");
+ lzowork->defined = true;
}
void
@@ -121,9 +116,24 @@ lzo_compress_uninit (struct lzo_compress_workspace *lzowork)
{
if (lzowork)
{
+ ASSERT (lzowork->defined);
lzo_free (lzowork->wmem);
lzowork->wmem = NULL;
+ lzowork->defined = false;
+ }
+}
+
+static inline bool
+lzo_compression_enabled (struct lzo_compress_workspace *lzowork)
+{
+ if ((lzowork->flags & (LZO_SELECTED|LZO_ON)) == (LZO_SELECTED|LZO_ON))
+ {
+ if (lzowork->flags & LZO_ADAPTIVE)
+ return lzo_adaptive_compress_test (&lzowork->ac);
+ else
+ return true;
}
+ return false;
}
/* Magic numbers to tell our peer if we compressed or not */
@@ -139,6 +149,8 @@ lzo_compress (struct buffer *buf, struct buffer work,
int err;
bool compressed = false;
+ ASSERT (lzowork->defined);
+
if (buf->len <= 0)
return;
@@ -146,7 +158,7 @@ lzo_compress (struct buffer *buf, struct buffer work,
* In order to attempt compression, length must be at least COMPRESS_THRESHOLD,
* and our adaptive level must give the OK.
*/
- if (buf->len >= COMPRESS_THRESHOLD && lzo_adaptive_compress_test (&lzowork->ac))
+ if (buf->len >= COMPRESS_THRESHOLD && lzo_compression_enabled (lzowork))
{
ASSERT (buf_init (&work, FRAME_HEADROOM (frame)));
ASSERT (buf_safe (&work, LZO_EXTRA_BUFFER (PAYLOAD_SIZE (frame))));
@@ -169,7 +181,8 @@ lzo_compress (struct buffer *buf, struct buffer work,
lzowork->post_compress += work.len;
/* tell adaptive level about our success or lack thereof in getting any size reduction */
- lzo_adaptive_compress_data(&lzowork->ac, buf->len, work.len);
+ if (lzowork->flags & LZO_ADAPTIVE)
+ lzo_adaptive_compress_data (&lzowork->ac, buf->len, work.len);
}
/* did compression save us anything ? */
@@ -195,6 +208,8 @@ lzo_decompress (struct buffer *buf, struct buffer work,
uint8_t c; /* flag indicating whether or not our peer compressed */
int err;
+ ASSERT (lzowork->defined);
+
if (buf->len <= 0)
return;
@@ -235,11 +250,20 @@ lzo_decompress (struct buffer *buf, struct buffer work,
}
}
+void
+lzo_modify_flags (struct lzo_compress_workspace *lzowork, unsigned int flags)
+{
+ ASSERT (lzowork->defined);
+ lzowork->flags = flags;
+}
+
/*
* Print statistics
*/
void lzo_print_stats (const struct lzo_compress_workspace *lzo_compwork, struct status_output *so)
{
+ ASSERT (lzo_compwork->defined);
+
status_printf (so, "pre-compress bytes," counter_format, lzo_compwork->pre_compress);
status_printf (so, "post-compress bytes," counter_format, lzo_compwork->post_compress);
status_printf (so, "pre-decompress bytes," counter_format, lzo_compwork->pre_decompress);