Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tansiv
TANSIV
Commits
12781f3d
Verified
Commit
12781f3d
authored
Apr 21, 2020
by
SIMONIN Matthieu
Browse files
capi: remove src argument from vsg_send.
It's now taken from the context
parent
73679fd1
Changes
6
Hide whitespace changes
Inline
Side-by-side
examples/send/send.cpp
View file @
12781f3d
...
...
@@ -31,15 +31,15 @@ void make_addr(char* addr, int id)
void
recv_cb
(
uintptr_t
arg
)
{
std
::
atomic
<
bool
>*
callback_called
=
(
std
::
atomic
<
bool
>*
)
arg
;
*
callback_called
=
true
;
std
::
atomic
<
bool
>*
callback_called
=
(
std
::
atomic
<
bool
>*
)
arg
;
*
callback_called
=
true
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
// initialization phase
int
dest_id
=
std
::
atoi
(
argv
[
1
]);
int
src_id
=
1
-
dest_id
;
int
dest_id
=
std
::
atoi
(
argv
[
1
]);
int
src_id
=
1
-
dest_id
;
char
dest_str
[
INET_ADDRSTRLEN
];
make_addr
(
dest_str
,
dest_id
);
char
src_str
[
INET_ADDRSTRLEN
];
...
...
@@ -49,7 +49,7 @@ int main(int argc, char* argv[])
int
vsg_argc
=
6
;
const
char
*
const
vsg_argv
[]
=
{
"-a"
,
CONNECTION_SOCKET_NAME
,
"-n"
,
src_str
,
"-t"
,
"1970-01-01T00:00:00"
};
std
::
atomic
<
bool
>
callback_called
(
false
);
vsg_context
*
context
=
vsg_init
(
vsg_argc
,
vsg_argv
,
NULL
,
recv_cb
,
(
uintptr_t
)
&
callback_called
);
vsg_context
*
context
=
vsg_init
(
vsg_argc
,
vsg_argv
,
NULL
,
recv_cb
,
(
uintptr_t
)
&
callback_called
);
if
(
!
context
)
{
die
(
"Unable to initialize the context"
,
0
);
...
...
@@ -61,7 +61,7 @@ int main(int argc, char* argv[])
}
std
::
string
msg
=
"plop"
;
ret
=
vsg_send
(
context
,
src
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
ret
=
vsg_send
(
context
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
if
(
ret
)
{
die
(
"vsg_send() failed"
,
ret
);
}
...
...
@@ -74,7 +74,7 @@ int main(int argc, char* argv[])
uint32_t
recv_dest
;
uint32_t
buffer_len
=
msg
.
length
()
+
1
;
char
buffer
[
buffer_len
];
ret
=
vsg_recv
(
context
,
&
src
,
&
dest
,
&
buffer_len
,
(
uint8_t
*
)
buffer
);
ret
=
vsg_recv
(
context
,
&
src
,
&
dest
,
&
buffer_len
,
(
uint8_t
*
)
buffer
);
if
(
ret
)
{
die
(
"vsg_recv() failed"
,
ret
);
}
...
...
src/fake-vm/capi/src/fake_vm.h
View file @
12781f3d
...
...
@@ -15,7 +15,7 @@ int vsg_start(const struct vsg_context* context);
int
vsg_stop
(
const
struct
vsg_context
*
context
);
int
vsg_gettimeofday
(
const
struct
vsg_context
*
context
,
struct
timeval
*
timeval
,
void
*
timezone
);
int
vsg_send
(
const
struct
vsg_context
*
context
,
uint32_t
src
,
uint32_t
dest
,
uint32_t
msglen
,
const
uint8_t
*
msg
);
int
vsg_send
(
const
struct
vsg_context
*
context
,
uint32_t
dest
,
uint32_t
msglen
,
const
uint8_t
*
msg
);
int
vsg_recv
(
const
struct
vsg_context
*
context
,
uint32_t
*
src
,
uint32_t
*
dest
,
uint32_t
*
msglen
,
uint8_t
*
msg
);
int
vsg_poll
(
const
struct
vsg_context
*
context
);
...
...
src/fake-vm/capi/src/lib.rs
View file @
12781f3d
...
...
@@ -125,7 +125,7 @@ pub unsafe extern fn vsg_gettimeofday(context: *const Context, timeval: *mut lib
///
/// * Fails with `libc::ENOMEM` whenever there is no more buffers to hold the message to send.
#[no_mangle]
pub
unsafe
extern
fn
vsg_send
(
context
:
*
const
Context
,
src
:
VsgAddress
,
dest
:
VsgAddress
,
msglen
:
u32
,
msg
:
*
const
u8
)
->
c_int
{
pub
unsafe
extern
fn
vsg_send
(
context
:
*
const
Context
,
dest
:
VsgAddress
,
msglen
:
u32
,
msg
:
*
const
u8
)
->
c_int
{
if
let
Some
(
context
)
=
context
.as_ref
()
{
// We can tolerate msg.is_null() if msglen == 0 but std::slice::from_raw_parts() requires
// non null pointers.
...
...
@@ -139,7 +139,7 @@ pub unsafe extern fn vsg_send(context: *const Context, src: VsgAddress, dest: Vs
};
let
payload
=
std
::
slice
::
from_raw_parts
(
ptr
,
msglen
as
usize
);
match
(
*
context
)
.send
(
src
,
dest
,
payload
)
{
match
(
*
context
)
.send
(
dest
,
payload
)
{
Ok
(
_
)
=>
0
,
Err
(
e
)
=>
match
e
{
Error
::
NoMemoryAvailable
=>
libc
::
ENOMEM
,
...
...
@@ -545,9 +545,8 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
b"Foo msg"
;
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -569,9 +568,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_start
(
context
)
};
assert_eq!
(
0
,
res
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
0
,
std
::
ptr
::
null
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
0
,
std
::
ptr
::
null
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -593,14 +591,13 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_start
(
context
)
};
assert_eq!
(
0
,
res
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
1
,
std
::
ptr
::
null
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
1
,
std
::
ptr
::
null
())
};
assert_eq!
(
libc
::
EINVAL
,
res
);
// Terminate gracefully
let
buffer
=
b"Foo msg"
;
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -623,14 +620,13 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
[
0u8
;
fake_vm
::
MAX_PACKET_SIZE
+
1
];
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
(
&
buffer
)
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
(
&
buffer
)
.as_ptr
())
};
assert_eq!
(
libc
::
EMSGSIZE
,
res
);
// Terminate gracefully
let
buffer
=
b"Foo msg"
;
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -645,9 +641,8 @@ mod test {
init
();
let
buffer
=
b"Foo msg"
;
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
std
::
ptr
::
null
(),
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
std
::
ptr
::
null
(),
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
libc
::
EINVAL
,
res
);
}
...
...
@@ -1070,9 +1065,8 @@ mod test {
assert_ne!
(
TIMEVAL_POISON
.tv_usec
,
tv
.tv_usec
);
let
buffer
=
b"This is the end"
;
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -1098,9 +1092,8 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
b"This is the end"
;
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
src
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dest
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
src/fake-vm/capi/tests/build_test.c
View file @
12781f3d
...
...
@@ -39,9 +39,8 @@ int main(int argc, const char* argv[])
if
(
res
)
die
(
"vsg_gettimeofday() failed"
,
res
);
uint32_t
src
=
0
;
uint32_t
dest
=
1
;
res
=
vsg_send
(
context
,
src
,
dest
,
sizeof
(
msg
),
msg
);
res
=
vsg_send
(
context
,
dest
,
sizeof
(
msg
),
msg
);
if
(
res
)
die
(
"vsg_send() failed"
,
res
);
...
...
@@ -49,6 +48,7 @@ int main(int argc, const char* argv[])
if
(
res
)
die
(
"vsg_poll() failed"
,
res
);
uint32_t
src
=
0
;
uint32_t
msglen
=
sizeof
(
msg
);
res
=
vsg_recv
(
context
,
&
src
,
&
dest
,
&
msglen
,
msg
);
if
(
res
)
...
...
src/fake-vm/fake_vm/src/lib.rs
View file @
12781f3d
...
...
@@ -42,10 +42,6 @@ pub type Result<T> = std::result::Result<T, Error>;
pub
type
RecvCallback
=
Box
<
dyn
Fn
()
->
()
+
Send
+
Sync
>
;
// #[derive(Debug)]
// pub struct Destination {
// addr: u32
// }
pub
type
VsgAddress
=
u32
;
fn
vsg_address_from_str
(
ip
:
&
str
)
->
std
::
result
::
Result
<
VsgAddress
,
std
::
net
::
AddrParseError
>
{
...
...
@@ -141,7 +137,7 @@ impl InnerContext {
}
}
fn
send
(
&
self
,
src
:
VsgAddress
,
dest
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
fn
send
(
&
self
,
dest
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
let
mut
buffer
=
self
.output_buffer_pool
.allocate_buffer
(
msg
.len
())
?
;
buffer
.copy_from_slice
(
msg
);
...
...
@@ -151,7 +147,7 @@ impl InnerContext {
// This would violate the property that send times must be after the previous deadline
// (included) and (strictly) before the current deadline. To solve this, ::at_deadline()
// takes the latest time between the recorded time and the previous deadline.
self
.outgoing_messages
.insert
(
send_time
,
s
rc
,
dest
,
buffer
)
?
;
self
.outgoing_messages
.insert
(
send_time
,
s
elf
.address
,
dest
,
buffer
)
?
;
Ok
(())
}
...
...
@@ -298,8 +294,8 @@ impl Context {
self
.0
.gettimeofday
()
}
pub
fn
send
(
&
self
,
src
:
VsgAddress
,
dest
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
self
.0
.send
(
src
,
dest
,
msg
)
pub
fn
send
(
&
self
,
dest
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
self
.0
.send
(
dest
,
msg
)
}
pub
fn
recv
<
'a
,
'b
>
(
&
'a
self
,
msg
:
&
'b
mut
[
u8
])
->
Result
<
(
VsgAddress
,
VsgAddress
,
&
'b
mut
[
u8
])
>
{
...
...
@@ -540,9 +536,8 @@ mod test {
context
.start
()
.expect
(
"start failed"
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
context
.send
(
src
,
dest
,
b"Foo msg"
)
context
.send
(
dest
,
b"Foo msg"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -561,16 +556,15 @@ mod test {
context
.start
()
.expect
(
"start failed"
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
let
buffer
=
[
0u8
;
crate
::
MAX_PACKET_SIZE
+
1
];
match
context
.send
(
src
,
dest
,
&
buffer
)
.expect_err
(
"send should have failed"
)
{
match
context
.send
(
dest
,
&
buffer
)
.expect_err
(
"send should have failed"
)
{
crate
::
error
::
Error
::
SizeTooBig
=>
(),
_
=>
assert
!
(
false
),
}
// Terminate gracefully
context
.send
(
src
,
dest
,
b"Foo msg"
)
context
.send
(
dest
,
b"Foo msg"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -729,9 +723,8 @@ mod test {
assert
!
(
tv
.tv_sec
>=
0
&&
tv
.tv_sec
<
10
);
assert
!
(
tv
.tv_usec
>=
0
&&
tv
.tv_usec
<
999999
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
context
.send
(
src
,
dest
,
b"This is the end"
)
context
.send
(
dest
,
b"This is the end"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -755,9 +748,8 @@ mod test {
assert
!
(
tv
.tv_sec
>=
3600
&&
tv
.tv_sec
<
3610
);
assert
!
(
tv
.tv_usec
>=
0
&&
tv
.tv_usec
<
999999
);
let
src
=
local_vsg_address!
();
let
dest
=
remote_vsg_address!
();
context
.send
(
src
,
dest
,
b"This is the end"
)
context
.send
(
dest
,
b"This is the end"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
src/tests/tests.cpp
View file @
12781f3d
...
...
@@ -309,9 +309,8 @@ void TestTansiv::testVsgSend(void)
vsg_context
*
context
=
vsg_init
(
argc
,
argv
,
NULL
,
recv_cb
,
0
);
int
ret
=
vsg_start
(
context
);
std
::
string
msg
=
MESSAGE
;
in_addr_t
src
=
inet_addr
(
SRC
);
in_addr_t
dest
=
inet_addr
(
DEST
);
vsg_send
(
context
,
src
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
vsg_send
(
context
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
vsg_stop
(
context
);
vsg_cleanup
(
context
);
...
...
@@ -332,11 +331,10 @@ void TestTansiv::testVsgSendEnsureRaise(void)
const
char
*
const
argv
[]
=
{
"-a"
,
SOCKET_ACTOR
,
"-n"
,
SRC
,
"-t"
,
"1970-01-01T00:00:00"
};
vsg_context
*
context
=
vsg_init
(
argc
,
argv
,
NULL
,
recv_cb
,
0
);
int
ret
=
vsg_start
(
context
);
in_addr_t
src
=
inet_addr
(
SRC
);
in_addr_t
dest
=
inet_addr
(
DEST
);
/* inject an error here msg != MESSAGE*/
std
::
string
msg
=
"plop1"
;
vsg_send
(
context
,
src
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
vsg_send
(
context
,
dest
,
msg
.
length
()
+
1
,
(
uint8_t
*
)
msg
.
c_str
());
vsg_stop
(
context
);
vsg_cleanup
(
context
);
...
...
@@ -407,7 +405,6 @@ void TestTansiv::testVsgSendPiggyBackPort(void)
int
ret
=
vsg_start
(
context
);
in_port_t
port
=
5000
;
std
::
string
msg
=
MESSAGE
;
in_addr_t
src
=
inet_addr
(
SRC
);
in_addr_t
dest
=
inet_addr
(
DEST
);
int
payload_length
=
msg
.
length
()
+
sizeof
(
in_port_t
)
+
1
;
// because of str
...
...
@@ -416,7 +413,7 @@ void TestTansiv::testVsgSendPiggyBackPort(void)
vsg_pg_port
(
port
,
(
uint8_t
*
)
msg
.
c_str
(),
msg
.
length
()
+
1
,
payload
);
// fire!
vsg_send
(
context
,
src
,
dest
,
payload_length
,
payload
);
vsg_send
(
context
,
dest
,
payload_length
,
payload
);
// loop until some message arrives
// this shouldn't take long ...
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment