Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org,
	vdavydov.dev@gmail.com, kostja@tarantool.org
Subject: [PATCH v4 1/5] box: move port to src/
Date: Fri, 30 Nov 2018 22:01:09 +0300	[thread overview]
Message-ID: <ad5ff047982704f20636b157aab104ea8a7e333d.1543604148.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1543604148.git.imeevma@gmail.com>

Basic port structure does not depend on anything but
standard types. It just gives an interface and calls
virtual functions.

Its location in box/ was ok since it was not used
anywhere in src/. But next commits will add a new
method to mpstream so as to dump port. Mpstream is
implemented in src/, so lets move port over here.

Needed for #3505
---
 src/CMakeLists.txt |   1 +
 src/box/port.c     |  30 -------------
 src/box/port.h     | 103 +------------------------------------------
 src/port.c         |  37 ++++++++++++++++
 src/port.h         | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 166 insertions(+), 132 deletions(-)
 create mode 100644 src/port.c
 create mode 100644 src/port.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b854265..e8554a8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -108,6 +108,7 @@ set (core_sources
      coll.c
      coll_def.c
      mpstream.c
+     port.c
  )
 
 if (TARGET_OS_NETBSD)
diff --git a/src/box/port.c b/src/box/port.c
index 853d24c..ef511ea 100644
--- a/src/box/port.c
+++ b/src/box/port.c
@@ -125,36 +125,6 @@ extern void
 port_tuple_dump_lua(struct port *base, struct lua_State *L);
 
 void
-port_destroy(struct port *port)
-{
-	return port->vtab->destroy(port);
-}
-
-int
-port_dump_msgpack(struct port *port, struct obuf *out)
-{
-	return port->vtab->dump_msgpack(port, out);
-}
-
-int
-port_dump_msgpack_16(struct port *port, struct obuf *out)
-{
-	return port->vtab->dump_msgpack_16(port, out);
-}
-
-void
-port_dump_lua(struct port *port, struct lua_State *L)
-{
-	port->vtab->dump_lua(port, L);
-}
-
-const char *
-port_dump_plain(struct port *port, uint32_t *size)
-{
-	return port->vtab->dump_plain(port, size);
-}
-
-void
 port_init(void)
 {
 	mempool_create(&port_tuple_entry_pool, &cord()->slabc,
diff --git a/src/box/port.h b/src/box/port.h
index 751e44e..ad1b349 100644
--- a/src/box/port.h
+++ b/src/box/port.h
@@ -31,78 +31,13 @@
  * SUCH DAMAGE.
  */
 #include "trivia/util.h"
+#include <port.h>
 
 #if defined(__cplusplus)
 extern "C" {
 #endif /* defined(__cplusplus) */
 
 struct tuple;
-struct obuf;
-struct lua_State;
-
-/**
- * A single port represents a destination of box_process output.
- * One such destination can be a Lua stack, or the binary
- * protocol.
- * An instance of a port is usually short lived, as it is created
- * for every server request. State of the instance is represented
- * by the tuples added to it. E.g.:
- *
- * struct port port;
- * port_tuple_create(&port);
- * for (tuple in tuples)
- *	port_tuple_add(tuple);
- *
- * port_dump(&port, obuf);
- * port_destroy(&port);
- *
- * Beginning with Tarantool 1.5, tuple can have different internal
- * structure and port_tuple_add() requires a double
- * dispatch: first, by the type of the port the tuple is being
- * added to, second, by the type of the tuple format, since the
- * format defines the internal structure of the tuple.
- */
-
-struct port;
-
-struct port_vtab {
-	/**
-	 * Dump the content of a port to an output buffer.
-	 * On success returns number of entries dumped.
-	 * On failure sets diag and returns -1.
-	 */
-	int (*dump_msgpack)(struct port *port, struct obuf *out);
-	/**
-	 * Same as dump_msgpack(), but use the legacy Tarantool
-	 * 1.6 format.
-	 */
-	int (*dump_msgpack_16)(struct port *port, struct obuf *out);
-	/** Dump the content of a port to Lua stack. */
-	void (*dump_lua)(struct port *port, struct lua_State *L);
-	/**
-	 * Dump a port content as a plain text into a buffer,
-	 * allocated inside.
-	 */
-	const char *(*dump_plain)(struct port *port, uint32_t *size);
-	/**
-	 * Destroy a port and release associated resources.
-	 */
-	void (*destroy)(struct port *port);
-};
-
-/**
- * Abstract port instance. It is supposed to be converted to
- * a concrete port realization, e.g. port_tuple.
- */
-struct port {
-	/** Virtual method table. */
-	const struct port_vtab *vtab;
-	/**
-	 * Implementation dependent content. Needed to declare
-	 * an abstract port instance on stack.
-	 */
-	char pad[48];
-};
 
 struct port_tuple_entry {
 	struct port_tuple_entry *next;
@@ -166,42 +101,6 @@ static_assert(sizeof(struct port_lua) <= sizeof(struct port),
 void
 port_lua_create(struct port *port, struct lua_State *L);
 
-/**
- * Destroy an abstract port instance.
- */
-void
-port_destroy(struct port *port);
-
-/**
- * Dump an abstract port instance to an output buffer.
- * Return number of entries dumped on success, -1 on error.
- */
-int
-port_dump_msgpack(struct port *port, struct obuf *out);
-
-/**
- * Same as port_dump(), but use the legacy Tarantool 1.6
- * format.
- */
-int
-port_dump_msgpack_16(struct port *port, struct obuf *out);
-
-/** Dump port content to Lua stack. */
-void
-port_dump_lua(struct port *port, struct lua_State *L);
-
-/**
- * Dump a port content as a plain text into a buffer,
- * allocated inside.
- * @param port Port with data to dump.
- * @param[out] size Length of a result plain text.
- *
- * @retval nil Error.
- * @retval not nil Plain text.
- */
-const char *
-port_dump_plain(struct port *port, uint32_t *size);
-
 void
 port_init(void);
 
diff --git a/src/port.c b/src/port.c
new file mode 100644
index 0000000..03694b4
--- /dev/null
+++ b/src/port.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010-2018, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include "port.h"
+
+void
+port_destroy(struct port *port)
+{
+	port->vtab->destroy(port);
+}
diff --git a/src/port.h b/src/port.h
new file mode 100644
index 0000000..9266ae5
--- /dev/null
+++ b/src/port.h
@@ -0,0 +1,127 @@
+#ifndef INCLUDES_TARANTOOL_PORT_H
+#define INCLUDES_TARANTOOL_PORT_H
+/*
+ * Copyright 2010-2018, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <stdint.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+struct obuf;
+struct lua_State;
+struct port;
+
+/**
+ * A single port represents a destination of any output. One such
+ * destination can be a Lua stack, or the binary protocol. An
+ * instance of a port is usually short lived, as it is created
+ * per request. Used to virtualize functions which can return
+ * directly into Lua or into network.
+ */
+struct port_vtab {
+	/**
+	 * Dump the content of a port to an output buffer.
+	 * @param port Port to dump.
+	 * @param out Buffer to dump to.
+	 *
+	 * @retval >= 0 Number of entries dumped.
+	 * @retval < 0 Error.
+	 */
+	int (*dump_msgpack)(struct port *port, struct obuf *out);
+	/**
+	 * Same as dump_msgpack(), but do not add MsgPack array
+	 * header. Used by the legacy Tarantool 1.6 format.
+	 */
+	int (*dump_msgpack_16)(struct port *port, struct obuf *out);
+	/** Dump the content of a port to Lua stack. */
+	void (*dump_lua)(struct port *port, struct lua_State *L);
+	/**
+	 * Dump a port content as a plain text into a buffer,
+	 * allocated inside.
+	 * @param port Port with data to dump.
+	 * @param[out] size Length of a result plain text.
+	 *
+	 * @retval nil Error.
+	 * @retval not nil Plain text.
+	 */
+	const char *(*dump_plain)(struct port *port, uint32_t *size);
+	/** Destroy a port and release associated resources. */
+	void (*destroy)(struct port *port);
+};
+
+/**
+ * Abstract port instance. It is supposed to be converted to
+ * a concrete port realization, e.g. port_tuple.
+ */
+struct port {
+	/** Virtual method table. */
+	const struct port_vtab *vtab;
+	/**
+	 * Implementation dependent content. Needed to declare
+	 * an abstract port instance on stack.
+	 */
+	char pad[48];
+};
+
+/** Is not inlined just to be exported. */
+void
+port_destroy(struct port *port);
+
+static inline int
+port_dump_msgpack(struct port *port, struct obuf *out)
+{
+	return port->vtab->dump_msgpack(port, out);
+}
+
+static inline int
+port_dump_msgpack_16(struct port *port, struct obuf *out)
+{
+	return port->vtab->dump_msgpack_16(port, out);
+}
+
+static inline void
+port_dump_lua(struct port *port, struct lua_State *L)
+{
+	port->vtab->dump_lua(port, L);
+}
+
+static inline const char *
+port_dump_plain(struct port *port, uint32_t *size)
+{
+	return port->vtab->dump_plain(port, size);
+}
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif /* defined __cplusplus */
+
+#endif /* INCLUDES_TARANTOOL_PORT_H */
-- 
2.7.4

  reply	other threads:[~2018-11-30 19:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-30 19:00 [PATCH v4 0/5] Remove box.sql.execute() imeevma
2018-11-30 19:01 ` imeevma [this message]
2018-12-03  9:22   ` [PATCH v4 1/5] box: move port to src/ Vladimir Davydov
2018-11-30 19:01 ` [tarantool-patches] [PATCH v4 2/5] iproto: replace obuf by mpstream in execute.c imeevma
2018-11-30 19:01 ` [tarantool-patches] [PATCH v4 3/5] sql: create interface vstream imeevma
2018-11-30 19:01 ` [tarantool-patches] [PATCH v4 4/5] lua: create vstream implementation for Lua imeevma
2018-11-30 19:01 ` [tarantool-patches] [PATCH v4 5/5] sql: check new box.sql.execute() imeevma
2018-12-02 11:03 ` [PATCH v4 2/5] iproto: replace obuf by mpstream in execute.c imeevma
2018-12-03 15:21   ` Vladimir Davydov
2018-12-03 20:48     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04  8:26       ` Vladimir Davydov
2018-12-04 11:28         ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad5ff047982704f20636b157aab104ea8a7e333d.1543604148.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v4 1/5] box: move port to src/' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox