Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
0eec80af
Commit
0eec80af
authored
10 years ago
by
Dmitry E. Oboukhov
Browse files
Options
Downloads
Patches
Plain Diff
socket.tcp_server removes old socket if it exists and dead. closes #414
parent
3ee859f0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lua/bsdsocket.lua
+34
-1
34 additions, 1 deletion
src/lua/bsdsocket.lua
test/box/bsdsocket.result
+35
-1
35 additions, 1 deletion
test/box/bsdsocket.result
test/box/bsdsocket.test
+15
-0
15 additions, 0 deletions
test/box/bsdsocket.test
with
84 additions
and
2 deletions
src/lua/bsdsocket.lua
+
34
−
1
View file @
0eec80af
...
...
@@ -6,6 +6,7 @@ local TIMEOUT_INFINITY = 500 * 365 * 86400
local
ffi
=
require
'ffi'
local
os_remove
=
os.remove
local
boxerrno
=
box
.
errno
local
internal
=
box
.
socket
.
internal
box
.
socket
.
internal
=
nil
package.loaded
[
'box.socket.internal'
]
=
nil
...
...
@@ -1003,6 +1004,38 @@ local function tcp_server_usage()
error
(
'Usage: socket.tcp_server(host, port, handler | opts)'
)
end
local
function
tcp_server_bind
(
s
,
addr
)
if
s
:
bind
(
addr
.
host
,
addr
.
port
)
then
return
true
end
if
addr
.
family
~=
'AF_UNIX'
then
return
false
end
if
boxerrno
()
~=
boxerrno
.
EADDRINUSE
then
return
false
end
local
save_errno
=
boxerrno
()
local
sc
=
tcp_connect
(
addr
.
host
,
addr
.
port
)
if
sc
~=
nil
then
sc
:
close
()
boxerrno
(
save_errno
)
return
false
end
if
boxerrno
()
~=
boxerrno
.
ECONNREFUSED
then
boxerrno
(
save_errno
)
return
false
end
os_remove
(
addr
.
port
)
return
s
:
bind
(
addr
.
host
,
addr
.
port
)
end
local
function
tcp_server
(
host
,
port
,
opts
,
timeout
)
local
server
=
{}
if
type
(
opts
)
==
'function'
then
...
...
@@ -1040,7 +1073,7 @@ local function tcp_server(host, port, opts, timeout)
else
s
:
setsockopt
(
'SOL_SOCKET'
,
'SO_REUSEADDR'
,
1
)
-- ignore error
end
if
not
s
:
bind
(
addr
.
host
,
addr
.
port
)
or
not
s
:
listen
(
backlog
)
then
if
not
tcp_server_bind
(
s
,
addr
)
or
not
s
:
listen
(
backlog
)
then
local
save_errno
=
box
.
errno
()
s
:
close
()
box
.
errno
(
save_errno
)
...
...
This diff is collapsed.
Click to expand it.
test/box/bsdsocket.result
+
35
−
1
View file @
0eec80af
...
...
@@ -222,7 +222,7 @@ lua s:getsockopt('SOL_SOCKET', 'SO_DEBUG')
...
lua s:setsockopt('SOL_SOCKET', 'SO_ACCEPTCONN', 1)
---
error: '[string "-- bsdsocket.lua (internal file)..."]:34
7
: Socket option SO_ACCEPTCONN is read only'
error: '[string "-- bsdsocket.lua (internal file)..."]:34
8
: Socket option SO_ACCEPTCONN is read only'
...
lua s:getsockopt('SOL_SOCKET', 'SO_RCVBUF') > 32
---
...
...
@@ -1149,3 +1149,37 @@ lua errno == box.errno.ECONNREFUSED
---
- true
...
test bind unix socket if old socket is exists
lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)
---
...
lua s:bind('unix/', '/tmp/tarantool-test-socket')
---
- true
...
lua s:listen()
---
- true
...
lua s:close()
---
- true
...
lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)
---
...
lua s:bind('unix/', '/tmp/tarantool-test-socket')
---
- false
...
lua s = box.socket.tcp_server('unix/', '/tmp/tarantool-test-socket', function() end)
---
...
lua s ~= nil
---
- true
...
lua s:close()
---
- true
...
This diff is collapsed.
Click to expand it.
test/box/bsdsocket.test
+
15
−
0
View file @
0eec80af
...
...
@@ -370,3 +370,18 @@ exec admin "lua collectgarbage('collect')"
exec
admin
"lua client, errno = box.socket.tcp_connect('unix/', '{}'), box.errno()"
.
format
(
path
)
exec
admin
"lua errno == box.errno.ECONNREFUSED"
os
.
unlink
(
path
)
print
'test bind unix socket if old socket is exists'
exec
admin
"lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)"
exec
admin
"lua s:bind('unix/', '{}')"
.
format
(
path
)
exec
admin
"lua s:listen()"
exec
admin
"lua s:close()"
if
not
os
.
path
.
exists
(
path
)
:
print
'unix socket was removed: test failed'
exec
admin
"lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)"
exec
admin
"lua s:bind('unix/', '{}')"
.
format
(
path
)
exec
admin
"lua s = box.socket.tcp_server('unix/', '{}', function() end)"
.
format
(
path
)
exec
admin
"lua s ~= nil"
exec
admin
"lua s:close()"
if
os
.
path
.
exists
(
path
)
:
print
'unix socket was not removed: test failed'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment