Skip to content

Commit 35daa0a

Browse files
committed
Implement UNIX socket support
* Added uri library from tarantool * New arg-format for connect: `tcp://..` and `..@unix\:...` URIs * Spaces -> Tabs, 2xTabs -> Tabs in tests * Use ZVAL_UNDEF instead of three separate gotos * Rewrite connection algorithm for supporting unix/tcp connection URI * Changed internal tarantool_connection table (with new struct tarantool_url) * Added new flag for test-run (--unix)
1 parent e50e288 commit 35daa0a

22 files changed

+7778
-880
lines changed

config.m4

+2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ if test "$PHP_TARANTOOL" != "no"; then
1010
src/tarantool_schema.c \
1111
src/tarantool_proto.c \
1212
src/tarantool_tp.c \
13+
src/tarantool_url.c \
1314
src/tarantool_exception.c \
1415
src/utils.c \
1516
src/third_party/msgpuck.c \
1617
src/third_party/sha1.c \
18+
src/third_party/uri.c \
1719
src/third_party/PMurHash.c \
1820
, $ext_shared)
1921
PHP_ADD_BUILD_DIR([$ext_builddir/src/])

lib/tarantool_server.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,18 @@ def execute_no_reconnect(self, command):
112112

113113
class TarantoolServer(object):
114114
default_tarantool = {
115-
"bin": "tarantool",
116-
"logfile": "tarantool.log",
117-
"init": "init.lua"}
115+
"bin": "tarantool",
116+
"logfile": "tarantool.log",
117+
"init": "init.lua",
118+
"unix": "tarantool.sock"
119+
}
118120

119121
default_cfg = {
120-
"custom_proc_title": "\"tarantool-python testing\"",
121-
"slab_alloc_arena": 0.5,
122-
"pid_file": "\"box.pid\"",
123-
"rows_per_wal": 200}
122+
"custom_proc_title": "\"tarantool-python testing\"",
123+
"slab_alloc_arena": 0.5,
124+
"pid_file": "\"box.pid\"",
125+
"rows_per_wal": 200
126+
}
124127

125128
@property
126129
def logfile_path(self):
@@ -134,6 +137,10 @@ def cfgfile_path(self):
134137
def script_path(self):
135138
return os.path.join(self.vardir, self.default_tarantool['init'])
136139

140+
@property
141+
def unix_path(self):
142+
return os.path.join(self.vardir, self.default_tarantool['unix'])
143+
137144
@property
138145
def script_dst(self):
139146
return os.path.join(self.vardir, os.path.basename(self.script))
@@ -187,9 +194,9 @@ def log_des(self):
187194
def __init__(self):
188195
os.popen('ulimit -c unlimited')
189196
self.args = {}
190-
self.args['primary'] = find_port()
191-
self.args['admin'] = find_port(self.args['primary'] + 1)
192-
self._admin = self.args['admin']
197+
198+
self.use_unix = False
199+
193200
self.vardir = tempfile.mkdtemp(prefix='var_', dir=os.getcwd())
194201
self.find_exe()
195202

@@ -204,6 +211,7 @@ def find_exe(self):
204211
raise RuntimeError("Can't find server executable in " + os.environ["PATH"])
205212

206213
def generate_configuration(self):
214+
# print(self.args)
207215
os.putenv("PRIMARY_PORT", str(self.args['primary']))
208216
os.putenv("ADMIN_PORT", str(self.args['admin']))
209217

@@ -242,6 +250,14 @@ def start(self):
242250
# start Tarantool\Box --DONE(prepare_args)
243251
# * Wait unitl Tarantool\Box
244252
# started --DONE(wait_until_started)
253+
if self.use_unix:
254+
self.args['primary'] = self.unix_path
255+
self.args['admin'] = find_port()
256+
else:
257+
self.args['primary'] = find_port()
258+
self.args['admin'] = find_port(self.args['primary'] + 1)
259+
self._admin = self.args['admin']
260+
245261
self.generate_configuration()
246262
if self.script:
247263
shutil.copy(self.script, self.script_dst)
@@ -268,5 +284,4 @@ def clean(self):
268284

269285
def __del__(self):
270286
self.stop()
271-
self.clean()
272-
287+
# self.clean()

src/php_tarantool.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,16 @@ ZEND_EXTERN_MODULE_GLOBALS(tarantool);
9595

9696
typedef struct tarantool_object {
9797
struct tarantool_connection {
98-
char *host;
99-
int port;
100-
char *login;
101-
char *passwd;
98+
char *url;
99+
struct tarantool_url *url_parsed;
102100
php_stream *stream;
103101
struct tarantool_schema *schema;
104102
smart_string *value;
105103
struct tp *tps;
106104
char *greeting;
107105
char *salt;
108106
/* Only for persistent connections */
109-
char *orig_login;
107+
char *orig_user;
110108
char *suffix;
111109
int suffix_len;
112110
zend_string *persistent_id;

0 commit comments

Comments
 (0)