Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
d22c15e7
A
ascs
项目概览
youngwolf
/
ascs
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ascs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d22c15e7
编写于
8月 29, 2022
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Decouple the id and index for client_socket in file_client.
上级
606eb881
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
16 deletion
+17
-16
examples/file_client/file_client.h
examples/file_client/file_client.h
+16
-15
include/ascs/ext/ext.h
include/ascs/ext/ext.h
+1
-1
未找到文件。
examples/file_client/file_client.h
浏览文件 @
d22c15e7
...
...
@@ -33,14 +33,15 @@ public:
bool
is_idle
()
const
{
return
TRANS_IDLE
==
state
;}
void
set_index
(
int
index_
)
{
index
=
index_
;}
bool
get_file
(
const
std
::
string
&
file_name
)
bool
get_file
(
const
std
::
string
&
file_name
,
bool
master_only
)
{
assert
(
!
file_name
.
empty
());
if
(
TRANS_IDLE
!=
state
)
if
((
master_only
&&
0
!=
index
)
||
(
!
master_only
&&
0
==
index
))
return
true
;
else
if
(
TRANS_IDLE
!=
state
)
return
false
;
if
(
0
==
index
)
else
if
(
master_only
)
file
=
fopen
(
file_name
.
data
(),
"w+b"
);
else
file
=
fopen
(
file_name
.
data
(),
"r+b"
);
...
...
@@ -60,13 +61,15 @@ public:
return
true
;
}
bool
truncate_file
(
const
std
::
string
&
file_name
)
bool
truncate_file
(
const
std
::
string
&
file_name
,
bool
master_only
)
{
assert
(
!
file_name
.
empty
());
if
(
TRANS_IDLE
!=
state
)
if
((
master_only
&&
0
!=
index
)
||
(
!
master_only
&&
0
==
index
))
return
true
;
else
if
(
TRANS_IDLE
!=
state
)
return
false
;
else
if
(
0
==
index
)
else
if
(
master_only
)
{
std
::
string
order
(
ORDER_LEN
,
(
char
)
10
);
order
+=
file_name
;
...
...
@@ -296,13 +299,13 @@ private:
auto
file_name
=
std
::
next
(
msg
.
data
(),
ORDER_LEN
+
1
);
if
(
'\0'
!=
*
std
::
next
(
msg
.
data
(),
ORDER_LEN
))
{
if
(
link_num
-
1
==
index
)
if
(
0
==
index
)
printf
(
"cannot create or truncated file %s on the server
\n
"
,
file_name
);
trans_end
();
}
else
{
if
(
link_num
-
1
==
index
)
if
(
0
==
index
)
printf
(
"prepare to send file %s
\n
"
,
file_name
);
get_matrix
()
->
put_file
(
std
::
next
(
msg
.
data
(),
ORDER_LEN
+
1
));
}
...
...
@@ -397,16 +400,14 @@ private:
transmit_size
=
0
;
printf
(
"transmit %s begin.
\n
"
,
file_name
.
data
());
auto
re
=
fals
e
;
auto
re
=
tru
e
;
if
(
0
==
type
)
{
if
((
re
=
find
(
0
)
->
get_file
(
file_name
)))
//do_something_to_all([&](object_ctype& item) {if (0 != item->id()) item->get_file(file_name);});
//if you always return false, do_something_to_one will be equal to do_something_to_all.
do_something_to_one
([
&
](
object_ctype
&
item
)
{
if
(
0
!=
item
->
id
())
item
->
get_file
(
file_name
);
return
false
;});
do_something_to_all
([
&
](
object_ctype
&
item
)
{
if
(
!
item
->
get_file
(
file_name
,
true
))
re
=
false
;});
do_something_to_all
([
&
](
object_ctype
&
item
)
{
if
(
!
item
->
get_file
(
file_name
,
false
))
re
=
false
;});
}
else
re
=
find
(
0
)
->
truncate_file
(
file_name
);
do_something_to_all
([
&
](
object_ctype
&
item
)
{
if
(
!
item
->
truncate_file
(
file_name
,
true
))
re
=
false
;}
);
if
(
re
)
{
...
...
include/ascs/ext/ext.h
浏览文件 @
d22c15e7
...
...
@@ -135,7 +135,7 @@ public:
return
*
this
;
}
template
<
size_t
size
>
basic_buffer
&
append
(
char
(
&
buff
)[
size
],
size_t
len
)
{
return
append
((
const
char
*
)
buff
,
std
::
min
(
size
,
len
));}
template
<
size_t
size
>
basic_buffer
&
append
(
const
char
(
&
buff
)[
size
],
size_t
len
)
{
return
append
((
const
char
*
)
buff
,
std
::
min
(
size
,
len
));}
template
<
size_t
size
>
basic_buffer
&
append
(
const
char
(
&
buff
)[
size
],
size_t
len
)
{
return
append
((
const
char
*
)
buff
,
std
::
min
(
size
,
len
));}
//nonstandard function append2 -- delete the last character if it's '\0' before appending another string.
//this feature makes basic_buffer to be able to works as std::string, which will append '\0' automatically.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录