Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
nat_traversal
Commits
f4a0e4e3
Commit
f4a0e4e3
authored
May 16, 2017
by
Fong
Browse files
set timeout for enroll and fix protocol error
parent
55760254
Changes
1
Hide whitespace changes
Inline
Side-by-side
nat_traversal.c
View file @
f4a0e4e3
...
...
@@ -23,7 +23,7 @@
static
int
nums
[
MAX_PORT
-
MIN_PORT
];
static
int
send_to_punch_server
(
client
*
c
,
int
flags
)
{
int
n
=
send
(
c
->
sfd
,
c
->
msg_
buf
,
c
->
msg_buf
-
c
->
buf
,
flags
);
int
n
=
send
(
c
->
sfd
,
c
->
buf
,
c
->
msg_buf
-
c
->
buf
,
flags
);
c
->
msg_buf
=
c
->
buf
;
return
n
;
...
...
@@ -215,8 +215,10 @@ static void* server_notify_handler(void* data) {
// wait for notification
printf
(
"waiting for notification...
\n
"
);
if
(
recv
(
server_sock
,
&
peer
,
sizeof
peer
,
0
)
<=
0
)
{
return
NULL
;
for
(;
;)
{
if
(
recv
(
server_sock
,
&
peer
,
sizeof
peer
,
0
)
>
0
)
{
break
;
}
}
peer
.
port
=
ntohs
(
peer
.
port
);
peer
.
type
=
ntohs
(
peer
.
type
);
...
...
@@ -310,13 +312,17 @@ int init(struct peer_info self, struct sockaddr_in punch_server, client* c) {
// wait for server reply to get own ID
uint32_t
peer_id
=
0
;
struct
timeval
tv
;
tv
.
tv_sec
=
5
;
tv
.
tv_usec
=
0
;
setsockopt
(
server_sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
char
*
)
&
tv
,
sizeof
(
tv
));
int
n
=
recv
(
server_sock
,
&
peer_id
,
sizeof
(
uint32_t
),
0
);
if
(
n
!=
4
)
{
if
(
n
!=
sizeof
(
uint32_t
)
)
{
printf
(
"failed to enroll
\n
"
);
return
-
1
;
}
printf
(
"enroll successfully, ID: %d"
,
ntohl
(
peer_id
));
printf
(
"enroll successfully, ID: %d
\n
"
,
ntohl
(
peer_id
));
// wait for message from punch server in another thread
pthread_t
thread_id
;
...
...
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