Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Larry Price
gmsh
Commits
7005dedd
Commit
7005dedd
authored
19 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
handle connections from machines with different byte ordering
parent
09b12c2f
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
Fltk/GmshServer.h
+23
-1
23 additions, 1 deletion
Fltk/GmshServer.h
with
23 additions
and
1 deletion
Fltk/GmshServer.h
+
23
−
1
View file @
7005dedd
...
...
@@ -69,7 +69,10 @@ int myselect(int socket, int seconds)
class
GmshServer
{
public:
// This should match what's in GmshClient.h
// This should match what's in GmshClient.h (Do not use values
// greater that 65535: if we receive types > 65535 we assume that we
// receive data from a machine with a different byte ordering, and
// we just swap the bytes)
typedef
enum
{
CLIENT_START
=
1
,
CLIENT_STOP
=
2
,
CLIENT_INFO
=
10
,
...
...
@@ -102,6 +105,17 @@ class GmshServer {
}
while
(
remaining
>
0
);
return
bytes
;
}
void
_SwapBytes
(
char
*
array
,
int
size
,
int
n
)
{
char
*
x
=
new
char
[
size
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
char
*
a
=
&
array
[
i
*
size
];
memcpy
(
x
,
a
,
size
);
for
(
int
c
=
0
;
c
<
size
;
c
++
)
a
[
size
-
1
-
c
]
=
x
[
c
];
}
delete
[]
x
;
}
int
_AcceptConnection
(
int
s
)
{
#if defined(HAVE_NO_SOCKLEN_T)
...
...
@@ -240,10 +254,18 @@ class GmshServer {
}
int
ReceiveMessageHeader
(
int
*
type
,
int
*
len
)
{
bool
swap
=
false
;
if
(
_ReceiveData
(
type
,
sizeof
(
int
))){
if
(
*
type
<
0
)
return
0
;
if
(
*
type
>
65535
){
// the data comes from a machine with different endianness and
// we must swap the bytes
swap
=
true
;
_SwapBytes
((
char
*
)
type
,
sizeof
(
int
),
1
);
}
if
(
_ReceiveData
(
len
,
sizeof
(
int
))){
if
(
*
len
<
0
)
return
0
;
if
(
swap
)
_SwapBytes
((
char
*
)
len
,
sizeof
(
int
),
1
);
return
1
;
}
}
...
...
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