duplicate code in source3/lib/ctdb_conn.c
Richard Sharpe
realrichardsharpe at gmail.com
Wed Nov 19 15:46:46 MST 2014
Hi folks,
In reading through the above code I have found about six copies of the
following code:
r.hdr.length = offsetof(struct ctdb_req_message, data) + buflen;
r.hdr.ctdb_magic = CTDB_MAGIC;
r.hdr.ctdb_version = CTDB_PROTOCOL;
r.hdr.generation = 1;
r.hdr.operation = CTDB_REQ_MESSAGE;
r.hdr.destnode = dst_vnn;
r.hdr.srcnode = conn->our_vnn;
r.hdr.reqid = 0;
r.srvid = dst_srvid;
r.datalen = buflen;
DEBUG(10, ("ctdbd_messaging_send: Sending ctdb packet\n"));
ctdb_packet_dump(&r.hdr);
iov[0].iov_base = &r;
iov[0].iov_len = offsetof(struct ctdb_req_message, data);
iov[1].iov_base = discard_const_p(uint8_t, buf);
iov[1].iov_len = buflen;
nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
if (nwritten == -1) {
DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
cluster_fatal("cluster dispatch daemon msg write error\n");
}
Sure, there are some minor differences, and in only one of them we set
the generation number, but surely we could use a function or a macro
to initialize the hdr and send the message rather than duplicating so
much code?
--
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)
More information about the samba-technical
mailing list