Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhul
criu
Commits
cc15c018
Commit
cc15c018
authored
Dec 30, 2011
by
Cyrill Gorcunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: Rewrite sockets test
Signed-off-by:
Cyrill Gorcunov
<
gorcunov@openvz.org
>
parent
eac52b60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
12 deletions
+88
-12
test-unixsocket.c
test/test-unixsocket.c
+88
-12
No files found.
test/test-unixsocket.c
View file @
cc15c018
...
...
@@ -8,25 +8,98 @@
#include <sys/wait.h>
#include <sys/un.h>
#define SK_NAME_BOUND "test-socket-bound"
#define SK_NAME_CONN "test-socket-conn"
#define SK_DATA_PAIR "data-packet-pair"
#define SK_DATA_BOUND "data-packet-bound"
#define SK_DATA_CONN "data-packet-conn"
int
main
(
void
)
{
int
sv
[
2
];
char
buf
;
struct
sockaddr_un
name_bound
;
struct
sockaddr_un
name_conn
;
int
stream_sock
[
2
];
int
sk_dgram_bound_client
;
int
sk_dgram_bound_server
;
int
sk_dgram_conn_client
;
int
sk_dgram_conn_server
;
char
buf
[
64
];
int
ret
;
if
(
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
s
v
)
==
-
1
)
{
if
(
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
s
tream_sock
)
==
-
1
)
{
perror
(
"socketpair"
);
exit
(
1
);
}
buf
=
'a'
;
write
(
sv
[
0
],
&
buf
,
1
);
printf
(
"sent '%c'
\n
"
,
buf
);
sk_dgram_bound_client
=
socket
(
AF_UNIX
,
SOCK_DGRAM
,
0
);
sk_dgram_bound_server
=
socket
(
AF_UNIX
,
SOCK_DGRAM
,
0
);
sk_dgram_conn_client
=
socket
(
AF_UNIX
,
SOCK_DGRAM
,
0
);
sk_dgram_conn_server
=
socket
(
AF_UNIX
,
SOCK_DGRAM
,
0
);
if
(
sk_dgram_conn_server
<
0
||
sk_dgram_bound_server
<
0
||
sk_dgram_conn_client
<
0
||
sk_dgram_conn_server
<
0
)
{
perror
(
"socket"
);
exit
(
1
);
}
unlink
(
SK_NAME_BOUND
);
unlink
(
SK_NAME_CONN
);
printf
(
"sk_dgram_bound_client: %d
\n
"
"sk_dgram_bound_server: %d
\n
"
"sk_dgram_conn_client: %d
\n
"
"sk_dgram_conn_server: %d
\n
"
,
sk_dgram_bound_client
,
sk_dgram_bound_server
,
sk_dgram_conn_client
,
sk_dgram_conn_server
);
name_bound
.
sun_family
=
AF_UNIX
;
strcpy
(
name_bound
.
sun_path
,
SK_NAME_BOUND
);
name_conn
.
sun_family
=
AF_UNIX
;
strcpy
(
name_conn
.
sun_path
,
SK_NAME_CONN
);
ret
=
bind
(
sk_dgram_bound_server
,
&
name_bound
,
sizeof
(
name_bound
));
if
(
ret
)
{
perror
(
"bind"
);
exit
(
1
);
}
ret
=
bind
(
sk_dgram_conn_server
,
&
name_conn
,
sizeof
(
name_conn
));
if
(
ret
)
{
perror
(
"bind"
);
exit
(
1
);
}
ret
=
connect
(
sk_dgram_conn_client
,
&
name_conn
,
sizeof
(
name_conn
));
if
(
ret
)
{
perror
(
"connect"
);
exit
(
1
);
}
/* first packets */
write
(
stream_sock
[
0
],
SK_DATA_PAIR
,
sizeof
(
SK_DATA_PAIR
));
sendto
(
sk_dgram_bound_client
,
SK_DATA_BOUND
,
sizeof
(
SK_DATA_BOUND
),
0
,
&
name_bound
,
sizeof
(
name_bound
));
write
(
sk_dgram_conn_client
,
SK_DATA_CONN
,
sizeof
(
SK_DATA_CONN
));
while
(
1
)
{
/* stream */
read
(
sv
[
1
],
&
buf
,
1
);
printf
(
"read '%c'
\n
"
,
buf
);
read
(
stream_sock
[
1
],
&
buf
,
sizeof
(
buf
));
printf
(
"stream : '%s'
\n
"
,
buf
);
read
(
sk_dgram_bound_server
,
&
buf
,
sizeof
(
buf
));
printf
(
"dgram-bound : '%s'
\n
"
,
buf
);
read
(
sk_dgram_conn_server
,
&
buf
,
sizeof
(
buf
));
printf
(
"dgram-conn : '%s'
\n
"
,
buf
);
/*
* checkpoint should be done here,
...
...
@@ -35,9 +108,12 @@ int main(void)
printf
(
"pause
\n
"
);
sleep
(
10
);
buf
=
toupper
(
buf
);
write
(
sv
[
0
],
&
buf
,
1
);
printf
(
"sent '%c'
\n
"
,
buf
);
write
(
stream_sock
[
0
],
SK_DATA_PAIR
,
sizeof
(
SK_DATA_PAIR
));
sendto
(
sk_dgram_bound_client
,
SK_DATA_BOUND
,
sizeof
(
SK_DATA_BOUND
),
0
,
&
name_bound
,
sizeof
(
name_bound
));
write
(
sk_dgram_conn_client
,
SK_DATA_CONN
,
sizeof
(
SK_DATA_CONN
));
}
return
0
;
...
...
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