along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include "io_elem.h"
#include <tdb.h>
+#include <netinet/in.h>
#include <ctdb_protocol.h> // For CTDB_DS_ALIGNMENT and ctdb_req_header
struct io_elem {
struct io_elem *new_io_elem(size_t len)
{
struct io_elem *elem;
+ size_t ask = len;
+
len = (len + (CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
elem = malloc(sizeof(*elem));
return NULL;
}
+ /* stamp out any padding to keep valgrind happy */
+ if (ask != len) {
+ memset(elem->data + ask, 0, len-ask);
+ }
elem->len = len;
elem->off = 0;
return elem;
/* Finished. But maybe this was just header? */
if (io->len == sizeof(*hdr) && hdr->length > io->len) {
int reret;
+ void *newdata;
/* Enlarge and re-read. */
io->len = hdr->length;
- io->data = realloc(io->data, io->len);
- if (!io->data)
+ newdata = realloc(io->data, io->len);
+ if (!newdata)
return -1;
+ io->data = newdata;
/* Try reading again immediately. */
reret = read_io_elem(fd, io);
if (reret >= 0)
io->off += ret;
return ret;
}
+
+void io_elem_reset(struct io_elem *io)
+{
+ io->off = 0;
+}