Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
PRRT
Commits
0edece32
Commit
0edece32
authored
Sep 04, 2018
by
Andreas Schmidt
Browse files
Use select() + send().
parent
ed5f17c9
Pipeline
#2967
passed with stages
in 1 minute and 41 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
prrt/time-protocol.h
View file @
0edece32
...
...
@@ -113,15 +113,39 @@ static inline ssize_t _send(socket_t conn, const char *buf, size_t size)
int
written
=
0
;
ssize_t
n
=
0
;
while
(
written
<
size
)
{
n
=
send
(
conn
,
buf
,
size
-
written
,
0
);
if
(
n
<
0
)
{
_time
();
printf
(
"WRITE FAILED: %ld, errno: %d
\n
"
,
n
,
errno
);
printf
(
"%s
\n
"
,
buf
-
written
);
return
written
;
fd_set
wfds
;
struct
timeval
tv
;
int
retval
;
FD_ZERO
(
&
wfds
);
FD_SET
(
conn
,
&
wfds
);
tv
.
tv_sec
=
1
;
tv
.
tv_usec
=
0
;
retval
=
select
(
conn
+
1
,
NULL
,
&
wfds
,
NULL
,
&
tv
);
if
(
!
FD_ISSET
(
conn
,
&
wfds
))
{
continue
;
}
if
(
retval
==
-
1
)
{
printf
(
"Select failed: %d.
\n
"
,
errno
);
return
-
1
;
}
else
if
(
retval
>
0
)
{
n
=
send
(
conn
,
buf
,
size
-
written
,
0
);
if
(
n
<
0
)
{
_time
();
printf
(
"RECEIVE FAILED: %ld, errno: %d
\n
, written %ld / %ld"
,
n
,
errno
,
written
,
size
);
printf
(
"%s
\n
"
,
buf
-
written
);
return
written
;
}
if
(
n
==
0
)
{
break
;
}
written
+=
n
;
buf
+=
n
;
}
else
{
continue
;
}
written
+=
n
;
buf
+=
n
;
}
return
written
;
}
...
...
Write
Preview
Supports
Markdown
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