Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
4f310e05
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f310e05
编写于
8月 22, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Opening TCP listening ports refactored into a function.
上级
0f0cc885
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
38 deletion
+58
-38
src/redis.c
src/redis.c
+58
-38
未找到文件。
src/redis.c
浏览文件 @
4f310e05
...
...
@@ -1474,6 +1474,61 @@ void adjustOpenFilesLimit(void) {
}
}
/* Initialize a set of file descriptors to listen to the specified 'port'
* binding the addresses specified in the Redis server configuration.
*
* The listening file descriptors are stored in the integer array 'fds'
* and their number is set in '*count'.
*
* The addresses to bind are specified in the global server.bindaddr array
* and their number is server.bindaddr_count. If the server configuration
* contains no specific addresses to bind, this function will try to
* bind * (all addresses) for both the IPv4 and IPv6 protocols.
*
* On success the function returns REDIS_OK.
*
* On error the function returns REDIS_ERR. For the function to be on
* error, at least one of the server.bindaddr addresses was
* impossible to bind, or no bind addresses were specified in the server
* configuration but the function is not able to bind * for at least
* one of the IPv4 or IPv6 protocols. */
int
listenToPort
(
int
port
,
int
*
fds
,
int
*
count
)
{
int
j
;
/* Force binding of 0.0.0.0 if no bind address is specified, always
* entering the loop if j == 0. */
if
(
server
.
bindaddr_count
==
0
)
server
.
bindaddr
[
0
]
=
NULL
;
for
(
j
=
0
;
j
<
server
.
bindaddr_count
||
j
==
0
;
j
++
)
{
if
(
server
.
bindaddr
[
j
]
==
NULL
)
{
/* Bind * for both IPv6 and IPv4, we enter here only if
* server.bindaddr_count == 0. */
fds
[
*
count
]
=
anetTcp6Server
(
server
.
neterr
,
port
,
NULL
);
if
(
fds
[
*
count
]
!=
ANET_ERR
)
(
*
count
)
++
;
fds
[
*
count
]
=
anetTcpServer
(
server
.
neterr
,
port
,
NULL
);
if
(
fds
[
*
count
]
!=
ANET_ERR
)
(
*
count
)
++
;
/* Exit the loop if we were able to bind * on IPv4 or IPv6,
* otherwise fds[*count] will be ANET_ERR and we'll print an
* error and return to the caller with an error. */
if
(
*
count
)
break
;
}
else
if
(
strchr
(
server
.
bindaddr
[
j
],
':'
))
{
/* Bind IPv6 address. */
fds
[
*
count
]
=
anetTcp6Server
(
server
.
neterr
,
port
,
server
.
bindaddr
[
j
]);
}
else
{
/* Bind IPv4 address. */
fds
[
*
count
]
=
anetTcpServer
(
server
.
neterr
,
port
,
server
.
bindaddr
[
j
]);
}
if
(
fds
[
*
count
]
==
ANET_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Creating Server TCP listening socket %s:%d: %s"
,
server
.
bindaddr
[
j
]
?
server
.
bindaddr
[
j
]
:
"*"
,
server
.
port
,
server
.
neterr
);
return
REDIS_ERR
;
}
(
*
count
)
++
;
}
return
REDIS_OK
;
}
void
initServer
()
{
int
j
;
...
...
@@ -1500,44 +1555,9 @@ void initServer() {
server
.
el
=
aeCreateEventLoop
(
server
.
maxclients
+
REDIS_EVENTLOOP_FDSET_INCR
);
server
.
db
=
zmalloc
(
sizeof
(
redisDb
)
*
server
.
dbnum
);
/* Open the TCP listening sockets. */
if
(
server
.
port
!=
0
)
{
/* Force binding of 0.0.0.0 if no bind address is specified, always
* entering the loop if j == 0. */
if
(
server
.
bindaddr_count
==
0
)
server
.
bindaddr
[
0
]
=
NULL
;
for
(
j
=
0
;
j
<
server
.
bindaddr_count
||
j
==
0
;
j
++
)
{
if
(
server
.
bindaddr
[
j
]
==
NULL
)
{
/* Bind * for both IPv6 and IPv4, we enter here only if
* server.bindaddr_count == 0. */
server
.
ipfd
[
server
.
ipfd_count
]
=
anetTcp6Server
(
server
.
neterr
,
server
.
port
,
NULL
);
if
(
server
.
ipfd
[
server
.
ipfd_count
]
!=
ANET_ERR
)
server
.
ipfd_count
++
;
server
.
ipfd
[
server
.
ipfd_count
]
=
anetTcpServer
(
server
.
neterr
,
server
.
port
,
NULL
);
if
(
server
.
ipfd
[
server
.
ipfd_count
]
!=
ANET_ERR
)
server
.
ipfd_count
++
;
/* Exit the loop if we were able to bind * on IPv4 or IPv6,
* otherwise server.ipfd[server.ipfd_count] will be ANET_ERR
* and we'll print an error and exit. */
if
(
server
.
ipfd_count
)
break
;
}
else
if
(
strchr
(
server
.
bindaddr
[
j
],
':'
))
{
/* Bind IPv6 address. */
server
.
ipfd
[
server
.
ipfd_count
]
=
anetTcp6Server
(
server
.
neterr
,
server
.
port
,
server
.
bindaddr
[
j
]);
}
else
{
/* Bind IPv4 address. */
server
.
ipfd
[
server
.
ipfd_count
]
=
anetTcpServer
(
server
.
neterr
,
server
.
port
,
server
.
bindaddr
[
j
]);
}
if
(
server
.
ipfd
[
server
.
ipfd_count
]
==
ANET_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Creating Server TCP listening socket %s:%d: %s"
,
server
.
bindaddr
[
j
]
?
server
.
bindaddr
[
j
]
:
"*"
,
server
.
port
,
server
.
neterr
);
exit
(
1
);
}
server
.
ipfd_count
++
;
}
}
/* Open the TCP listening socket for the user commands. */
if
(
listenToPort
(
server
.
port
,
server
.
ipfd
,
&
server
.
ipfd_count
)
==
REDIS_ERR
)
exit
(
1
);
/* Open the listening Unix domain socket. */
if
(
server
.
unixsocket
!=
NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录