Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
code
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ReadMailReallyFast
code
Commits
a38639b2
Verified
Commit
a38639b2
authored
4 years ago
by
Benny Baumann
Browse files
Options
Downloads
Patches
Plain Diff
Basic work on async socket interface
parent
1f70cee2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/net/async_fd.hpp
+85
-0
85 additions, 0 deletions
src/net/async_fd.hpp
src/net/async_server.hpp
+40
-0
40 additions, 0 deletions
src/net/async_server.hpp
with
125 additions
and
0 deletions
src/net/async_fd.hpp
0 → 100644
+
85
−
0
View file @
a38639b2
#pragma once
#include
<unistd.h>
namespace
rmrf
::
net
{
class
null_fd
{
public:
constexpr
explicit
null_fd
()
{}
constexpr
explicit
null_fd
(
int
)
{}
constexpr
operator
int
()
const
{
return
-
1
;
}
};
constexpr
null_fd
nullfd
{};
class
auto_fd
{
private:
int
_fd
;
public:
inline
auto_fd
(
null_fd
nfd
=
nullfd
)
noexcept
:
_fd
{
nfd
}
{}
explicit
inline
auto_fd
(
int
fd
)
noexcept
:
_fd
{
fd
}
{}
inline
auto_fd
(
auto_fd
&&
fd
)
noexcept
:
_fd
{
fd
.
release
()}
{}
inline
auto_fd
&
operator
=
(
auto_fd
&&
fd
)
noexcept
{
reset
(
fd
.
release
());
return
*
this
;
}
auto_fd
(
const
auto_fd
&
)
=
delete
;
auto_fd
&
operator
=
(
const
auto_fd
&
)
=
delete
;
inline
~
auto_fd
()
noexcept
{
reset
();
}
inline
int
get
()
const
noexcept
{
return
_fd
;
}
int
release
()
noexcept
{
int
r
(
_fd
);
_fd
=
-
1
;
return
r
;
}
// Close an open file descriptor. Reset the descriptor to -1.
inline
void
close
()
noexcept
{
if
(
_fd
>=
0
)
{
::
close
(
_fd
);
// If fdclose() failed then no reason to expect it to succeed the next time.
_fd
=
-
1
;
}
}
inline
void
reset
(
int
fd
=
-
1
)
noexcept
{
if
(
_fd
>=
0
)
close
();
// Don't check for an error as not much we can do here.
_fd
=
fd
;
}
};
inline
bool
operator
==
(
const
auto_fd
&
x
,
const
auto_fd
&
y
)
{
return
x
.
get
()
==
y
.
get
();
}
inline
bool
operator
!=
(
const
auto_fd
&
x
,
const
auto_fd
&
y
)
{
return
!
(
x
==
y
);
}
inline
bool
operator
==
(
const
auto_fd
&
x
,
null_fd
)
{
return
x
.
get
()
==
-
1
;
}
inline
bool
operator
!=
(
const
auto_fd
&
x
,
null_fd
y
)
{
return
!
(
x
==
y
);
}
}
This diff is collapsed.
Click to expand it.
src/net/async_server.hpp
0 → 100644
+
40
−
0
View file @
a38639b2
#pragma once
#include
<functional>
#include
<memory>
#include
<net/async_fd.hpp>
namespace
rmrf
::
net
::
asio
{
class
async_server_socket
:
public
std
::
enable_shared_from_this
<
async_server_socket
>
{
public:
typedef
std
::
shared_ptr
<
async_server_socket
>
self_ptr_type
;
typedef
std
::
function
<
void
(
self_ptr_type
&
,
const
auto_fd
&
)
>
accept_handler_type
;
typedef
std
::
function
<
void
(
self_ptr_type
&
)
>
error_handler_type
;
private:
auto_fd
socket
;
accept_handler_type
on_accept
;
error_handler_type
on_error
;
public:
async_server_socket
(
auto_fd
&&
fd
)
:
socket
(
std
::
forward
(
fd
))
{
// Add this socket to libev ...
}
~
async_server_socket
()
{
// Remove this socket from libev ...
}
public
:
accept_handler_type
get_accept_handler
()
const
{
return
on_accept
;
}
void
set_accept_handler
(
const
accept_handler_type
&
value
)
{
on_accept
=
value
;
}
};
}
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