1- =====================================================================
2- C
3- =====================================================================
1+ C
2+ =
43
54Here follow two examples of using Tarantool's high-level C API.
65
7- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8- Example 1
9- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+ Example 1
7+ ---------
108
119Here is a complete C program that inserts :code: `[99999,'B'] ` into
1210space :code: `examples ` via the high-level C API.
1311
14- .. code-block :: c
12+ .. code-block :: c
1513
1614 #include <stdio.h>
1715 #include <stdlib.h>
@@ -44,7 +42,7 @@ space :code:`examples` via the high-level C API.
4442 Paste the code into a file named :file: `example.c ` and install ``tarantool-c ``.
4543One way to install ``tarantool-c `` (using Ubuntu) is:
4644
47- .. code-block :: console
45+ .. code-block :: console
4846
4947 $ git clone git://github.com/tarantool/tarantool-c.git ~/tarantool-c
5048 $ cd ~/tarantool-c
@@ -54,9 +52,9 @@ One way to install ``tarantool-c`` (using Ubuntu) is:
5452 $ make
5553 $ make install
5654
57- To compile and link the program, say :
55+ To compile and link the program, run :
5856
59- .. code-block :: console
57+ .. code-block :: console
6058
6159 $ # sometimes this is necessary:
6260 $ export LD_LIBRARY_PATH=/usr/local/lib
@@ -72,11 +70,14 @@ If Tarantool is not running on localhost with listen address = 3301, the program
7270will print “Connection refused”.
7371If the insert fails, the program will print "Insert failed" and an error number
7472(see all error codes in the source file
75- `/src/box/errcode.h <https://github.com/tarantool/tarantool/blob/2.1/src/box/errcode.h >`_ ).
73+ `/src/box/errcode.h <https://github.com/tarantool/tarantool/blob/2.1/src/box/errcode.h >`__ ).
7674
7775Here are notes corresponding to comments in the example program.
7876
79- **SETUP: ** The setup begins by creating a stream.
77+ SETUP
78+ ~~~~~
79+
80+ The setup begins by creating a stream.
8081
8182.. code-block :: c
8283
@@ -96,28 +97,34 @@ Function description:
9697 struct tnt_stream *tnt_net(struct tnt_stream *s)
9798 int tnt_set(struct tnt_stream *s, int option, variant option-value)
9899
99- **CONNECT: ** Now that the stream named ``tnt `` exists and is associated with a
100+ CONNECT
101+ ~~~~~~~
102+
103+ Now that the stream named ``tnt `` exists and is associated with a
100104URI, this example program can connect to a server instance.
101105
102- .. code-block :: c
106+ .. code-block :: c
103107
104108 if (tnt_connect(tnt) < 0)
105109 { printf("Connection refused\n"); exit(-1); }
106110
107111 Function description:
108112
109- .. code-block :: text
113+ .. code-block :: text
110114
111115 int tnt_connect(struct tnt_stream *s)
112116
113117 The connection might fail for a variety of reasons, such as:
114118the server is not running, or the URI contains an invalid :ref: `password<authentication-passwords> `.
115119If the connection fails, the return value will be -1.
116120
117- **MAKE REQUEST: ** Most requests require passing a structured value, such as
121+ MAKE REQUEST
122+ ~~~~~~~~~~~~
123+
124+ Most requests require passing a structured value, such as
118125the contents of a tuple.
119126
120- .. code-block :: c
127+ .. code-block :: c
121128
122129 struct tnt_stream *tuple = tnt_object(NULL);
123130 tnt_object_format(tuple, "[%d%s]", 99999, "B");
@@ -133,14 +140,17 @@ then the integer value, then a pointer to the string value.
133140
134141Function description:
135142
136- .. code-block :: text
143+ .. code-block :: text
137144
138145 ssize_t tnt_object_format(struct tnt_stream *s, const char *fmt, ...)
139146
140- **SEND REQUEST: ** The database-manipulation requests are analogous to the
147+ SEND REQUEST
148+ ~~~~~~~~~~~~
149+
150+ The database-manipulation requests are analogous to the
141151requests in the box library.
142152
143- .. code-block :: c
153+ .. code-block :: c
144154
145155 tnt_insert(tnt, 999, tuple);
146156 tnt_flush(tnt);
@@ -152,7 +162,7 @@ the program passes the ``tnt_stream`` that was used for connection
152162
153163Function description:
154164
155- .. code-block :: text
165+ .. code-block :: text
156166
157167 ssize_t tnt_insert(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple)
158168 ssize_t tnt_replace(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple)
@@ -162,10 +172,13 @@ Function description:
162172 ssize_t tnt_update(struct tnt_stream *s, uint32_t space, uint32_t index,
163173 struct tnt_stream *key, struct tnt_stream *ops)
164174
165- **GET REPLY: ** For most requests, the client will receive a reply containing some
175+ GET REPLY
176+ ~~~~~~~~~
177+
178+ For most requests, the client will receive a reply containing some
166179indication whether the result was successful, and a set of tuples.
167180
168- .. code-block :: c
181+ .. code-block :: c
169182
170183 struct tnt_reply reply; tnt_reply_init(&reply);
171184 tnt->read_reply(tnt, &reply);
@@ -176,40 +189,42 @@ This program checks for success but does not decode the rest of the reply.
176189
177190Function description:
178191
179- .. code-block :: text
192+ .. code-block :: text
180193
181194 struct tnt_reply *tnt_reply_init(struct tnt_reply *r)
182195 tnt->read_reply(struct tnt_stream *s, struct tnt_reply *r)
183196 void tnt_reply_free(struct tnt_reply *r)
184197
185- **TEARDOWN: ** When a session ends, the connection that was made with
198+ TEARDOWN
199+ ~~~~~~~~
200+
201+ When a session ends, the connection that was made with
186202:c:func: `tarantoolc:tnt_connect() ` should be closed, and the objects that were
187203made in the setup should be destroyed.
188204
189- .. code-block :: c
205+ .. code-block :: c
190206
191207 tnt_close(tnt);
192208 tnt_stream_free(tuple);
193209 tnt_stream_free(tnt);
194210
195211 Function description:
196212
197- .. code-block :: text
213+ .. code-block :: text
198214
199215 void tnt_close(struct tnt_stream *s)
200216 void tnt_stream_free(struct tnt_stream *s)
201217
202- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203- Example 2
204- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218+ Example 2
219+ ---------
205220
206221Here is a complete C program that selects, using index key ``[99999] ``, from
207222space ``examples `` via the high-level C API.
208223To display the results, the program uses functions in the
209- `MsgPuck <https://github.com/tarantool/msgpuck >`_ library which allow decoding of
210- `MessagePack <https://en.wikipedia.org/wiki/MessagePack >`_ arrays.
224+ `MsgPuck <https://github.com/tarantool/msgpuck >`__ library which allow decoding of
225+ `MessagePack <https://en.wikipedia.org/wiki/MessagePack >`__ arrays.
211226
212- .. code-block :: c
227+ .. code-block :: c
213228
214229 #include <stdio.h>
215230 #include <stdlib.h>
@@ -281,13 +296,13 @@ Similarly to the first example, paste the code into a file named
281296
282297To compile and link the program, say:
283298
284- .. code-block :: console
299+ .. code-block :: console
285300
286301 $ gcc -o example2 example2.c -ltarantool
287302
288303 To run the program, say :samp: `./example2 `.
289304
290305The two example programs only show a few requests and do not show all that's
291306necessary for good practice. See more in the
292- `tarantool-c documentation at GitHub <http://github.com/tarantool/tarantool-c >`_ .
307+ `tarantool-c documentation at GitHub <http://github.com/tarantool/tarantool-c >`__ .
293308
0 commit comments