Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
659b6c09
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
提交
659b6c09
编写于
2月 23, 2022
作者:
羽飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use readline if available
上级
ad4a1c38
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
20 deletion
+62
-20
src/obclient/CMakeLists.txt
src/obclient/CMakeLists.txt
+27
-11
src/obclient/client.cpp
src/obclient/client.cpp
+35
-9
未找到文件。
src/obclient/CMakeLists.txt
浏览文件 @
659b6c09
PROJECT
(
obclient
)
MESSAGE
(
"Begin to build "
${
PROJECT_NAME
}
)
MESSAGE
(
STATUS
"This is PROJECT_BINARY_DIR dir "
${
PROJECT_BINARY_DIR
}
)
MESSAGE
(
STATUS
"This is PROJECT_SOURCE_DIR dir "
${
PROJECT_SOURCE_DIR
}
)
ADD_EXECUTABLE
(
obclient
)
MESSAGE
(
"Begin to build "
obclient
)
INCLUDE
(
CheckCSourceCompiles
)
MESSAGE
(
STATUS
"source dir is "
${
PROJECT_SOURCE_DIR
}
)
#INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
INCLUDE_DIRECTORIES
(
.
${
PROJECT_SOURCE_DIR
}
/../../deps /usr/local/include SYSTEM
)
TARGET_INCLUDE_DIRECTORIES
(
obclient PRIVATE .
${
PROJECT_SOURCE_DIR
}
/../deps /usr/local/include /usr/include
)
# 父cmake 设置的include_directories 和link_directories并不传导到子cmake里面
#INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include)
LINK_DIRECTORIES
(
/usr/local/lib
${
PROJECT_BINARY_DIR
}
/../../lib
)
TARGET_LINK_DIRECTORIES
(
obclient PRIVATE /usr/local/lib
${
PROJECT_BINARY_DIR
}
/../../lib
)
CHECK_C_SOURCE_COMPILES
(
"
#include <stdio.h>
#include <readline/readline.h>
int main(int argc, char **argv)
{
return 0;
}"
HAVE_READLINE_HEADER
)
FIND_LIBRARY
(
READLINE_LIBRARY readline
)
IF
(
HAVE_READLINE_HEADER AND READLINE_LIBRARY
)
TARGET_LINK_LIBRARIES
(
obclient
${
READLINE_LIBRARY
}
)
ADD_DEFINITIONS
(
-DUSE_READLINE
)
ELSE
()
MESSAGE
(
"readline is not found"
)
ENDIF
()
FILE
(
GLOB_RECURSE ALL_SRC *.cpp
)
FOREACH
(
F
${
ALL_SRC
}
)
...
...
@@ -19,15 +36,14 @@ FOREACH (F ${ALL_SRC})
ENDFOREACH
(
F
)
# 指定目标文件位置
SET
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_BINARY_DIR
}
/../
../
bin
)
SET
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_BINARY_DIR
}
/../bin
)
MESSAGE
(
"Binary directory:"
${
EXECUTABLE_OUTPUT_PATH
}
)
ADD_EXECUTABLE
(
${
PROJECT_NAME
}
${
PRJ_SRC
}
)
TARGET_LINK_LIBRARIES
(
${
PROJECT_NAME
}
common pthread dl
)
TARGET_SOURCES
(
obclient PRIVATE
${
PRJ_SRC
}
)
TARGET_LINK_LIBRARIES
(
obclient
common pthread dl
)
# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制
# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类
# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog
INSTALL
(
TARGETS
${
PROJECT_NAME
}
RUNTIME DESTINATION bin
)
\ No newline at end of file
INSTALL
(
TARGETS obclient RUNTIME DESTINATION bin
)
src/obclient/client.cpp
浏览文件 @
659b6c09
...
...
@@ -29,11 +29,38 @@ See the Mulan PSL v2 for more details. */
#include "common/defs.h"
#include "common/lang/string.h"
#ifdef USE_READLINE
#include "readline/readline.h"
#endif
#define MAX_MEM_BUFFER_SIZE 8192
#define PORT_DEFAULT 6789
using
namespace
common
;
#ifdef USE_READLINE
char
*
my_readline
(
const
char
*
prompt
)
{
return
readline
(
prompt
);
}
#else // USE_READLINE
char
*
my_readline
(
const
char
*
prompt
)
{
char
*
buffer
=
(
char
*
)
malloc
(
MAX_MEM_BUFFER_SIZE
);
if
(
nullptr
==
buffer
)
{
fprintf
(
stderr
,
"failed to alloc line buffer"
);
return
nullptr
;
}
char
*
s
=
fgets
(
buffer
,
MAX_MEM_BUFFER_SIZE
,
stdin
);
if
(
nullptr
==
s
)
{
fprintf
(
stderr
,
"failed to read message from console"
);
free
(
buffer
);
return
nullptr
;
}
return
buffer
;
}
#endif // USE_READLINE
bool
is_exit_command
(
const
char
*
cmd
)
{
return
0
==
strncasecmp
(
"exit"
,
cmd
,
4
)
||
0
==
strncasecmp
(
"bye"
,
cmd
,
3
);
...
...
@@ -141,7 +168,6 @@ int main(int argc, char *argv[]) {
const
char
*
prompt_str
=
"miniob > "
;
int
sockfd
,
send_bytes
;
// char send[MAXLINE];
if
(
unix_socket_path
!=
nullptr
)
{
sockfd
=
init_unix_sock
(
unix_socket_path
);
...
...
@@ -153,23 +179,24 @@ int main(int argc, char *argv[]) {
}
char
send_buf
[
MAX_MEM_BUFFER_SIZE
];
// char buf[MAXDATASIZE];
fputs
(
prompt_str
,
stdout
)
;
while
(
fgets
(
send_buf
,
MAX_MEM_BUFFER_SIZE
,
stdin
)
!=
NULL
)
{
if
(
common
::
is_blank
(
send_buf
))
{
f
puts
(
prompt_str
,
stdout
);
char
*
input_command
=
nullptr
;
while
(
(
input_command
=
my_readline
(
prompt_str
))
!=
nullptr
)
{
if
(
common
::
is_blank
(
input_command
))
{
f
ree
(
input_command
);
continue
;
}
if
(
is_exit_command
(
send_buf
))
{
if
(
is_exit_command
(
input_command
))
{
free
(
input_command
);
break
;
}
if
((
send_bytes
=
write
(
sockfd
,
send_buf
,
strlen
(
send_buf
)
+
1
))
==
-
1
)
{
if
((
send_bytes
=
write
(
sockfd
,
input_command
,
strlen
(
input_command
)
+
1
))
==
-
1
)
{
// TODO writen
fprintf
(
stderr
,
"send error: %d:%s
\n
"
,
errno
,
strerror
(
errno
));
exit
(
1
);
}
free
(
input_command
);
memset
(
send_buf
,
0
,
sizeof
(
send_buf
));
int
len
=
0
;
...
...
@@ -196,7 +223,6 @@ int main(int argc, char *argv[]) {
printf
(
"Connection has been closed
\n
"
);
break
;
}
fputs
(
prompt_str
,
stdout
);
}
close
(
sockfd
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录