Changeset View
Changeset View
Standalone View
Standalone View
dirmngr/ldap-wrapper-ce.c
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | /* We don't need a mutex for the conditions, as npth provides a | ||||
waiting on it. */ | waiting on it. */ | ||||
npth_cond_t wait_data; /* Condition that data is available. */ | npth_cond_t wait_data; /* Condition that data is available. */ | ||||
npth_cond_t wait_space; /* Condition that space is available. */ | npth_cond_t wait_space; /* Condition that space is available. */ | ||||
int eof_seen; /* EOF indicator. */ | int eof_seen; /* EOF indicator. */ | ||||
char buffer[4000]; /* Data ring buffer. */ | char buffer[4000]; /* Data ring buffer. */ | ||||
size_t buffer_len; /* The amount of data in the BUFFER. */ | size_t buffer_len; /* The amount of data in the BUFFER. */ | ||||
size_t buffer_pos; /* The next read position of the BUFFER. */ | size_t buffer_pos; /* The next read position of the BUFFER. */ | ||||
size_t buffer_read_pos; /* The next read position of the BUFFER. */ | |||||
}; | }; | ||||
#define BUFFER_EMPTY(c) ((c)->buffer_len == 0) | #define BUFFER_EMPTY(c) ((c)->buffer_len == 0) | ||||
#define BUFFER_FULL(c) ((c)->buffer_len == DIM((c)->buffer)) | #define BUFFER_FULL(c) ((c)->buffer_len == DIM((c)->buffer)) | ||||
#define BUFFER_DATA_AVAILABLE(c) ((c)->buffer_len) | #define BUFFER_DATA_AVAILABLE(c) ((c)->buffer_len) | ||||
#define BUFFER_SPACE_AVAILABLE(c) (DIM((c)->buffer) - (c)->buffer_len) | #define BUFFER_SPACE_AVAILABLE(c) (DIM((c)->buffer) - (c)->buffer_len) | ||||
#define BUFFER_INC_POS(c,n) (c)->buffer_pos = ((c)->buffer_pos + (n)) % DIM((c)->buffer) | #define BUFFER_INC_POS(c,n) (c)->buffer_pos = ((c)->buffer_pos + (n)) % DIM((c)->buffer) | ||||
#define BUFFER_CUR_POS(c) (&(c)->buffer[(c)->buffer_pos]) | #define BUFFER_CUR_POS(c) (&(c)->buffer[(c)->buffer_pos]) | ||||
#define BUFFER_INC_READ_POS(c,n) (c)->buffer_read_pos = ((c)->buffer_read_pos + (n)) % DIM((c)->buffer) | |||||
#define BUFFER_CUR_READ_POS(c) (&(c)->buffer[(c)->buffer_read_pos]) | |||||
static int | static int | ||||
buffer_get_data (struct outstream_cookie_s *cookie, char *dst, int cnt) | buffer_get_data (struct outstream_cookie_s *cookie, char *dst, int cnt) | ||||
{ | { | ||||
int amount; | int amount; | ||||
int left; | int left; | ||||
int chunk; | int chunk; | ||||
amount = cnt; | amount = cnt; | ||||
if (BUFFER_DATA_AVAILABLE (cookie) < amount) | if (BUFFER_DATA_AVAILABLE (cookie) < amount) | ||||
amount = BUFFER_DATA_AVAILABLE (cookie); | amount = BUFFER_DATA_AVAILABLE (cookie); | ||||
left = amount; | left = amount; | ||||
/* How large is the part up to the end of the buffer array? */ | /* How large is the part up to the end of the buffer array? */ | ||||
chunk = DIM(cookie->buffer) - cookie->buffer_pos; | chunk = DIM(cookie->buffer) - cookie->buffer_pos; | ||||
if (chunk > left) | if (chunk > left) | ||||
chunk = left; | chunk = left; | ||||
memcpy (dst, BUFFER_CUR_POS (cookie), chunk); | memcpy (dst, BUFFER_CUR_READ_POS (cookie), chunk); | ||||
BUFFER_INC_POS (cookie, chunk); | BUFFER_INC_READ_POS (cookie, chunk); | ||||
left -= chunk; | left -= chunk; | ||||
dst += chunk; | dst += chunk; | ||||
if (left) | if (left) | ||||
{ | { | ||||
memcpy (dst, BUFFER_CUR_POS (cookie), left); | memcpy (dst, BUFFER_CUR_READ_POS (cookie), left); | ||||
BUFFER_INC_POS (cookie, left); | BUFFER_INC_READ_POS (cookie, left); | ||||
} | } | ||||
return amount; | return amount; | ||||
} | } | ||||
static int | static int | ||||
buffer_put_data (struct outstream_cookie_s *cookie, const char *src, int cnt) | buffer_put_data (struct outstream_cookie_s *cookie, const char *src, int cnt) | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |