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
Florian Fischer
emper-echo-server
Commits
c95cce55
Commit
c95cce55
authored
Nov 26, 2020
by
Florian Fischer
Browse files
use new emper IO interface
parent
0d20ba85
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/emper-echo-server.c
View file @
c95cce55
...
@@ -31,7 +31,7 @@ void client_func(void* arg) {
...
@@ -31,7 +31,7 @@ void client_func(void* arg) {
char
buf
[
BUF_MAX
];
char
buf
[
BUF_MAX
];
for
(;;)
{
for
(;;)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
ssize_t
bytes_recv
=
sync
_recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
ssize_t
bytes_recv
=
emper
_recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
#else
#else
ssize_t
bytes_recv
=
recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
ssize_t
bytes_recv
=
recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
#endif
#endif
...
@@ -50,7 +50,7 @@ void client_func(void* arg) {
...
@@ -50,7 +50,7 @@ void client_func(void* arg) {
ssize_t
bytes_send
=
0
;
ssize_t
bytes_send
=
0
;
while
(
bytes_send
<
bytes_recv
)
{
while
(
bytes_send
<
bytes_recv
)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
ssize_t
new_bytes_send
=
sync
_send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
ssize_t
new_bytes_send
=
emper
_send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
#else
#else
ssize_t
new_bytes_send
=
send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
ssize_t
new_bytes_send
=
send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
#endif
#endif
...
@@ -101,7 +101,7 @@ static void welcome_func() {
...
@@ -101,7 +101,7 @@ static void welcome_func() {
for
(;;)
{
for
(;;)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
int
client_fd
=
sync
_accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
sizeof
(
servaddr
)
);
int
client_fd
=
emper
_accept
(
sockfd
,
NULL
,
NULL
);
#else
#else
socklen_t
address_len
=
sizeof
(
servaddr
);
socklen_t
address_len
=
sizeof
(
servaddr
);
int
client_fd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
&
address_len
);
int
client_fd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
&
address_len
);
...
...
src/emper-echo-server.cpp
View file @
c95cce55
...
@@ -29,7 +29,7 @@ void client_func(void* arg) {
...
@@ -29,7 +29,7 @@ void client_func(void* arg) {
char
buf
[
BUF_MAX
];
char
buf
[
BUF_MAX
];
for
(;;)
{
for
(;;)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
ssize_t
bytes_recv
=
io
::
sync_recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
ssize_t
bytes_recv
=
emper
::
io
::
recv_and_wait
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
#else
#else
ssize_t
bytes_recv
=
recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
ssize_t
bytes_recv
=
recv
(
client_fd
,
(
void
*
)
&
buf
,
BUF_MAX
,
MSG_WAITALL
);
#endif
#endif
...
@@ -49,12 +49,12 @@ void client_func(void* arg) {
...
@@ -49,12 +49,12 @@ void client_func(void* arg) {
ssize_t
bytes_send
=
0
;
ssize_t
bytes_send
=
0
;
while
(
bytes_send
<
bytes_recv
)
{
while
(
bytes_send
<
bytes_recv
)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
ssize_t
new_bytes_send
=
io
::
sync_send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
ssize_t
new_bytes_send
=
emper
::
io
::
send_and_wait
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
#else
#else
ssize_t
new_bytes_send
=
send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
ssize_t
new_bytes_send
=
send
(
client_fd
,
buf
,
bytes_recv
-
bytes_send
,
MSG_NOSIGNAL
);
#endif
#endif
// socket was shutdown
// socket was shutdown
if
(
unlikely
(
bytes_send
==
0
))
{
if
(
unlikely
(
new_
bytes_send
==
0
))
{
return
;
return
;
}
}
...
@@ -102,7 +102,7 @@ static void welcome_func() {
...
@@ -102,7 +102,7 @@ static void welcome_func() {
for
(;;)
{
for
(;;)
{
#ifdef USE_ASYNC_IO
#ifdef USE_ASYNC_IO
int
client_fd
=
io
::
sync_accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
sizeof
(
servaddr
)
);
int
client_fd
=
emper
::
io
::
accept_and_wait
(
sockfd
,
nullptr
,
nullptr
);
#else
#else
socklen_t
address_len
=
sizeof
(
servaddr
);
socklen_t
address_len
=
sizeof
(
servaddr
);
int
client_fd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
&
address_len
);
int
client_fd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
&
address_len
);
...
...
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