From: Ronnie sahlberg Date: Tue, 10 Apr 2007 03:17:15 +0000 (+1000) Subject: change the tcp code to call ctdb_read_pdu() instead of doing the partial read thing... X-Git-Tag: tevent-0.9.20~348^2~2951^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2e2d1c2f3b9c44bc9d8c6f8c1d201468f7f8f0c;p=thirdparty%2Fsamba.git change the tcp code to call ctdb_read_pdu() instead of doing the partial read thing explicitely (This used to be ctdb commit 6156bec0187df27578afd5afa3fcaadb1a202030) --- diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index d8b4859232d..ff0829ba4dc 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -340,8 +340,6 @@ struct ctdb_context *ctdb_init(struct event_context *ev) int ctdb_start(struct ctdb_context *ctdb) { - int res; - if (ctdb->flags&CTDB_FLAG_DAEMON_MODE) { return ctdbd_start(ctdb); } diff --git a/ctdb/tcp/ctdb_tcp.h b/ctdb/tcp/ctdb_tcp.h index 0f8ce300b44..5b6cd299b92 100644 --- a/ctdb/tcp/ctdb_tcp.h +++ b/ctdb/tcp/ctdb_tcp.h @@ -24,23 +24,13 @@ struct ctdb_tcp { int listen_fd; }; -/* - incoming packet structure - only used when we get a partial packet - on read -*/ -struct ctdb_tcp_partial { - uint8_t *data; - uint32_t length; -}; - - /* state associated with an incoming connection */ struct ctdb_incoming { struct ctdb_context *ctdb; int fd; - struct ctdb_tcp_partial partial; + struct ctdb_partial partial; }; /* diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c index e59f6167ff8..22771669869 100644 --- a/ctdb/tcp/tcp_io.c +++ b/ctdb/tcp/tcp_io.c @@ -98,92 +98,47 @@ void ctdb_tcp_node_write(struct event_context *ev, struct fd_event *fde, } -/* - called when an incoming connection is readable -*/ -void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private) + +static void tcp_read_cb(uint8_t *data, int cnt, void *args) { - struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming); - int num_ready = 0; - ssize_t nread; - uint8_t *data, *data_base; - - if (ioctl(in->fd, FIONREAD, &num_ready) != 0 || - num_ready == 0) { - /* we've lost the link from another node. We don't - notify the upper layers, as we only want to trigger - a full node reorganisation when a send fails - that - allows nodes to restart without penalty as long as - the network is idle */ - talloc_free(in); + struct ctdb_incoming *in = talloc_get_type(args, struct ctdb_incoming); + struct ctdb_req_header *hdr; + + if (cnt < sizeof(*hdr)) { + ctdb_set_error(in->ctdb, "Bad packet length %d\n", cnt); return; } - - in->partial.data = talloc_realloc_size(in, in->partial.data, - num_ready + in->partial.length); - if (in->partial.data == NULL) { - /* not much we can do except drop the socket */ - talloc_free(in); + hdr = (struct ctdb_req_header *)data; + if (cnt != hdr->length) { + ctdb_set_error(in->ctdb, "Bad header length %d expected %d\n", + hdr->length, cnt); return; } - nread = read(in->fd, in->partial.data+in->partial.length, num_ready); - if (nread <= 0) { - /* the connection must be dead */ - talloc_free(in); + if (hdr->ctdb_magic != CTDB_MAGIC) { + ctdb_set_error(in->ctdb, "Non CTDB packet rejected\n"); return; } - data = in->partial.data; - nread += in->partial.length; - - in->partial.data = NULL; - in->partial.length = 0; - - if (nread >= 4 && *(uint32_t *)data == nread) { - /* most common case - we got a whole packet in one go - tell the ctdb layer above that we have a packet */ - in->ctdb->upcalls->recv_pkt(in->ctdb, data, nread); + if (hdr->ctdb_version != CTDB_VERSION) { + ctdb_set_error(in->ctdb, "Bad CTDB version 0x%x rejected\n", hdr->ctdb_version); return; } - data_base = data; - - while (nread >= 4 && *(uint32_t *)data <= nread) { - /* we have at least one packet */ - uint8_t *d2; - uint32_t len; - len = *(uint32_t *)data; - d2 = talloc_memdup(in, data, len); - if (d2 == NULL) { - /* sigh */ - talloc_free(in); - return; - } - in->ctdb->upcalls->recv_pkt(in->ctdb, d2, len); - data += len; - nread -= len; - } + /* most common case - we got a whole packet in one go + tell the ctdb layer above that we have a packet */ + in->ctdb->upcalls->recv_pkt(in->ctdb, data, cnt); +} - if (nread > 0) { - /* we have only part of a packet */ - if (data_base == data) { - in->partial.data = data; - in->partial.length = nread; - } else { - in->partial.data = talloc_memdup(in, data, nread); - if (in->partial.data == NULL) { - talloc_free(in); - return; - } - in->partial.length = nread; - talloc_free(data_base); - } - return; - } +/* + called when an incoming connection is readable +*/ +void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde, + uint16_t flags, void *private) +{ + struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming); - talloc_free(data_base); + ctdb_read_pdu(in->fd, in, &in->partial, tcp_read_cb, in); } /*