Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMILE FEE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Luntzer
SMILE FEE
Commits
7f27871c
Commit
7f27871c
authored
4 years ago
by
Armin Luntzer
Browse files
Options
Downloads
Patches
Plain Diff
improve handling of disconnected sockets
parent
a894cf85
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
GRESB/gresb_bridge.c
+29
-16
29 additions, 16 deletions
GRESB/gresb_bridge.c
with
29 additions
and
16 deletions
GRESB/gresb_bridge.c
+
29
−
16
View file @
7f27871c
...
...
@@ -16,6 +16,7 @@
#include
<gresb.h>
#define DEBUG 1
#define DEFAULT_LINK 0
#define DEFAULT_PORT 1234
...
...
@@ -60,7 +61,6 @@ static int send_all(int sock_fd, const unsigned char *buf, int len)
while
(
len
)
{
printf
(
"len: %d
\n
"
,
len
);
n
=
send
(
sock_fd
,
buf
,
len
,
0
);
if
(
n
==
-
1
)
{
...
...
@@ -242,11 +242,16 @@ static int usr_pkt_to_gresb(int fd, struct bridge_cfg *cfg)
recv_bytes
=
recv
(
fd
,
recv_buffer
,
GRESB_PKT_SIZE_MAX
,
0
);
#if 1
if
(
recv_bytes
<=
0
)
goto
cleanup
;
#if DEBUG
{
printf
(
"usr to gresb [%lu]: "
,
recv_bytes
);
int
i
;
for
(
i
=
0
;
i
<
recv_bytes
;
i
++
)
printf
(
"%c"
,
recv_buffer
[
i
]);
printf
(
"%x:"
,
recv_buffer
[
i
]);
printf
(
"
\n
"
);
}
#endif
gresb_pkt
=
gresb_create_host_data_pkt
(
recv_buffer
,
recv_bytes
);
...
...
@@ -262,7 +267,11 @@ static int usr_pkt_to_gresb(int fd, struct bridge_cfg *cfg)
if
(
ret
==
-
1
)
perror
(
"send"
);
gresb_destroy_host_data_pkt
((
struct
host_to_gresb_pkt
*
)
gresb_pkt
);
cleanup:
free
(
recv_buffer
);
return
recv_bytes
;
...
...
@@ -334,13 +343,9 @@ static int gresb_pkt_to_usr(int fd, struct bridge_cfg *cfg)
recv_bytes
=
recv
(
fd
,
recv_buffer
,
GRESB_PKT_SIZE_MAX
,
0
);
#if 1
{
int
i
;
for
(
i
=
0
;
i
<
recv_bytes
;
i
++
)
printf
(
"%c"
,
recv_buffer
[
i
]);
}
#endif
if
(
recv_bytes
<=
0
)
goto
cleanup
;
for
(
fdc
=
0
;
fdc
<=
cfg
->
bridge
->
n_fd
;
fdc
++
)
{
...
...
@@ -351,16 +356,24 @@ static int gresb_pkt_to_usr(int fd, struct bridge_cfg *cfg)
gresb_get_spw_data
(
recv_buffer
),
gresb_get_spw_data_size
(
recv_buffer
));
printf
(
"size: %ld
\n
"
,
gresb_get_spw_data_size
(
recv_buffer
));
if
(
ret
==
-
1
)
{
perror
(
"send"
);
close
(
fdc
);
FD_CLR
(
fdc
,
&
cfg
->
bridge
->
set
);
}
#if DEBUG
{
printf
(
"gresb to usr [%lu]: "
,
gresb_get_spw_data_size
(
recv_buffer
));
size_t
i
;
for
(
i
=
0
;
i
<
gresb_get_spw_data_size
(
recv_buffer
);
i
++
)
printf
(
"%x:"
,
gresb_get_spw_data
(
recv_buffer
)[
i
]);
printf
(
"
\n
"
);
}
#endif
}
cleanup:
free
(
recv_buffer
);
...
...
@@ -408,9 +421,9 @@ static void *poll_socket_gresb(void *data)
if
(
!
FD_ISSET
(
fd
,
&
r_set
))
continue
;
/* clean up disconnected socket */
if
(
gresb_pkt_to_usr
(
fd
,
cfg
)
<
=
0
)
{
FD_CLR
(
fd
,
&
cfg
->
set
);
/* clean up disconnected
gresb
socket */
if
(
gresb_pkt_to_usr
(
fd
,
cfg
)
<
0
)
{
FD_CLR
(
fd
,
&
r_
set
);
close
(
fd
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment