Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asapo
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
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joao Alvim Oliveira Dias De Almeida
asapo
Commits
c881ccdb
Commit
c881ccdb
authored
7 years ago
by
Carsten Patzke
Browse files
Options
Downloads
Patches
Plain Diff
SystemIO: Merged windows and linux code
parent
ceb920d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/cpp/src/system_io.cpp
+58
-0
58 additions, 0 deletions
common/cpp/src/system_io.cpp
common/cpp/src/system_io_windows.cpp
+0
-59
0 additions, 59 deletions
common/cpp/src/system_io_windows.cpp
with
58 additions
and
59 deletions
common/cpp/src/system_io.cpp
+
58
−
0
View file @
c881ccdb
...
...
@@ -393,6 +393,64 @@ std::unique_ptr<std::tuple<std::string, uint16_t>> SystemIO::SplitAddressToHostA
}
}
void
hidra2
::
SystemIO
::
InetConnect
(
SocketDescriptor
socket_fd
,
const
std
::
string
&
address
,
IOErrors
*
err
)
const
{
*
err
=
IOErrors
::
kNoError
;
auto
host_port_tuple
=
SplitAddressToHostAndPort
(
address
);
if
(
!
host_port_tuple
)
{
*
err
=
IOErrors
::
kInvalidAddressFormat
;
return
;
}
std
::
string
host
;
uint16_t
port
=
0
;
std
::
tie
(
host
,
port
)
=
*
host_port_tuple
;
short
family
=
AddressFamilyToPosixFamily
(
AddressFamilies
::
INET
);
if
(
family
==
-
1
)
{
*
err
=
IOErrors
::
kUnsupportedAddressFamily
;
return
;
}
sockaddr_in
socket_address
{};
socket_address
.
sin_addr
.
s_addr
=
inet_addr
(
host
.
c_str
());
socket_address
.
sin_port
=
htons
(
port
);
socket_address
.
sin_family
=
family
;
if
(
::
connect
(
socket_fd
,
(
struct
sockaddr
*
)
&
socket_address
,
sizeof
(
socket_address
))
==
-
1
)
{
*
err
=
GetLastError
();
return
;
}
}
std
::
unique_ptr
<
std
::
tuple
<
std
::
string
,
SocketDescriptor
>>
SystemIO
::
InetAccept
(
SocketDescriptor
socket_fd
,
IOErrors
*
err
)
const
{
*
err
=
IOErrors
::
kNoError
;
static
short
family
=
AddressFamilyToPosixFamily
(
AddressFamilies
::
INET
);
if
(
family
==
-
1
)
{
*
err
=
IOErrors
::
kUnsupportedAddressFamily
;
return
nullptr
;
}
sockaddr_in
client_address
{};
static
int
client_address_size
=
sizeof
(
sockaddr_in
);
int
peer_fd
=
::
accept
(
socket_fd
,
reinterpret_cast
<
sockaddr
*>
(
&
client_address
),
&
client_address_size
);
if
(
peer_fd
==
-
1
)
{
*
err
=
GetLastError
();
return
nullptr
;
}
std
::
string
address
=
std
::
string
(
inet_ntoa
(
client_address
.
sin_addr
))
+
':'
+
std
::
to_string
(
client_address
.
sin_port
);
return
std
::
unique_ptr
<
std
::
tuple
<
std
::
string
,
SocketDescriptor
>>
(
new
std
::
tuple
<
std
::
string
,
SocketDescriptor
>
(
address
,
peer_fd
));
}
}
This diff is collapsed.
Click to expand it.
common/cpp/src/system_io_windows.cpp
+
0
−
59
View file @
c881ccdb
...
...
@@ -8,8 +8,6 @@
#include
<direct.h>
#include
<iostream>
#pragma comment(lib, "Ws2_32.lib")
using
std
::
string
;
using
std
::
vector
;
using
std
::
chrono
::
system_clock
;
...
...
@@ -144,63 +142,6 @@ void SystemIO::CollectFileInformationRecursivly(const std::string& path,
}
}
std
::
unique_ptr
<
std
::
tuple
<
std
::
string
,
SocketDescriptor
>>
SystemIO
::
InetAccept
(
SocketDescriptor
socket_fd
,
IOErrors
*
err
)
const
{
*
err
=
IOErrors
::
kNoError
;
static
short
family
=
AddressFamilyToPosixFamily
(
AddressFamilies
::
INET
);
if
(
family
==
-
1
)
{
*
err
=
IOErrors
::
kUnsupportedAddressFamily
;
return
nullptr
;
}
sockaddr_in
client_address
{};
static
int
client_address_size
=
sizeof
(
sockaddr_in
);
int
peer_fd
=
::
accept
(
socket_fd
,
reinterpret_cast
<
sockaddr
*>
(
&
client_address
),
&
client_address_size
);
if
(
peer_fd
==
-
1
)
{
*
err
=
GetLastError
();
return
nullptr
;
}
std
::
string
address
=
std
::
string
(
inet_ntoa
(
client_address
.
sin_addr
))
+
':'
+
std
::
to_string
(
client_address
.
sin_port
);
return
std
::
unique_ptr
<
std
::
tuple
<
std
::
string
,
SocketDescriptor
>>
(
new
std
::
tuple
<
std
::
string
,
SocketDescriptor
>
(
address
,
peer_fd
));
}
void
hidra2
::
SystemIO
::
InetConnect
(
SocketDescriptor
socket_fd
,
const
std
::
string
&
address
,
IOErrors
*
err
)
const
{
*
err
=
IOErrors
::
kNoError
;
auto
host_port_tuple
=
SplitAddressToHostAndPort
(
address
);
if
(
!
host_port_tuple
)
{
*
err
=
IOErrors
::
kInvalidAddressFormat
;
return
;
}
std
::
string
host
;
uint16_t
port
=
0
;
std
::
tie
(
host
,
port
)
=
*
host_port_tuple
;
short
family
=
AddressFamilyToPosixFamily
(
AddressFamilies
::
INET
);
if
(
family
==
-
1
)
{
*
err
=
IOErrors
::
kUnsupportedAddressFamily
;
return
;
}
sockaddr_in
socket_address
{};
socket_address
.
sin_addr
.
s_addr
=
inet_addr
(
host
.
c_str
());
socket_address
.
sin_port
=
htons
(
port
);
socket_address
.
sin_family
=
family
;
if
(
::
connect
(
socket_fd
,
(
struct
sockaddr
*
)
&
socket_address
,
sizeof
(
socket_address
))
==
-
1
)
{
*
err
=
GetLastError
();
return
;
}
}
FileDescriptor
SystemIO
::
_open
(
const
char
*
filename
,
int
posix_open_flags
)
const
{
int
fd
;
errno
=
_sopen_s
(
&
fd
,
filename
,
posix_open_flags
,
_SH_DENYNO
,
_S_IREAD
|
_S_IWRITE
);
...
...
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