summaryrefslogtreecommitdiffstats
path: root/ctdb/protocol/protocol_sock.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:29 +0000
commit4f5791ebd03eaec1c7da0865a383175b05102712 (patch)
tree8ce7b00f7a76baa386372422adebbe64510812d4 /ctdb/protocol/protocol_sock.c
parentInitial commit. (diff)
downloadsamba-upstream.tar.xz
samba-upstream.zip
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ctdb/protocol/protocol_sock.c')
-rw-r--r--ctdb/protocol/protocol_sock.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_sock.c b/ctdb/protocol/protocol_sock.c
new file mode 100644
index 0000000..e32f087
--- /dev/null
+++ b/ctdb/protocol/protocol_sock.c
@@ -0,0 +1,81 @@
+/*
+ CTDB generic sock packet marshalling
+
+ Copyright (C) Amitay Isaacs 2017
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/network.h"
+
+#include <talloc.h>
+
+#include "protocol.h"
+#include "protocol_private.h"
+#include "protocol_api.h"
+
+size_t sock_packet_header_len(struct sock_packet_header *in)
+{
+ return ctdb_uint32_len(&in->length) +
+ ctdb_uint32_len(&in->reqid);
+}
+
+void sock_packet_header_push(struct sock_packet_header *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->length, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int sock_packet_header_pull(uint8_t *buf, size_t buflen,
+ struct sock_packet_header *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->length, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reqid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+void sock_packet_header_set_reqid(struct sock_packet_header *h,
+ uint32_t reqid)
+{
+ h->reqid = reqid;
+}
+
+void sock_packet_header_set_length(struct sock_packet_header *h,
+ uint32_t length)
+{
+ h->length = length;
+}