Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
fdeec030
Commit
fdeec030
authored
Jul 22, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/ServerSocket: use AllocatedSocketAddress for OneServerSocket::address
Manages memory automatically.
parent
f084bbbf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
ServerSocket.cxx
src/event/ServerSocket.cxx
+14
-9
ServerSocket.hxx
src/event/ServerSocket.hxx
+2
-0
No files found.
src/event/ServerSocket.cxx
View file @
fdeec030
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "config.h"
#include "ServerSocket.hxx"
#include "ServerSocket.hxx"
#include "net/StaticSocketAddress.hxx"
#include "net/StaticSocketAddress.hxx"
#include "net/AllocatedSocketAddress.hxx"
#include "net/SocketAddress.hxx"
#include "net/SocketAddress.hxx"
#include "net/SocketUtil.hxx"
#include "net/SocketUtil.hxx"
#include "net/SocketError.hxx"
#include "net/SocketError.hxx"
...
@@ -64,31 +65,26 @@ class OneServerSocket final : private SocketMonitor {
...
@@ -64,31 +65,26 @@ class OneServerSocket final : private SocketMonitor {
AllocatedPath
path
;
AllocatedPath
path
;
#endif
#endif
SocketAddress
address
;
const
Allocated
SocketAddress
address
;
public
:
public
:
template
<
typename
A
>
OneServerSocket
(
EventLoop
&
_loop
,
ServerSocket
&
_parent
,
OneServerSocket
(
EventLoop
&
_loop
,
ServerSocket
&
_parent
,
unsigned
_serial
,
unsigned
_serial
,
SocketAddress
_address
)
A
&&
_address
)
:
SocketMonitor
(
_loop
),
:
SocketMonitor
(
_loop
),
parent
(
_parent
),
serial
(
_serial
),
parent
(
_parent
),
serial
(
_serial
),
#ifdef HAVE_UN
#ifdef HAVE_UN
path
(
AllocatedPath
::
Null
()),
path
(
AllocatedPath
::
Null
()),
#endif
#endif
address
((
sockaddr
*
)
xmemdup
(
_address
.
GetAddress
(),
address
(
std
::
forward
<
A
>
(
_address
))
_address
.
GetSize
()),
_address
.
GetSize
())
{
{
assert
(
!
_address
.
IsNull
());
assert
(
_address
.
GetSize
()
>
0
);
}
}
OneServerSocket
(
const
OneServerSocket
&
other
)
=
delete
;
OneServerSocket
(
const
OneServerSocket
&
other
)
=
delete
;
OneServerSocket
&
operator
=
(
const
OneServerSocket
&
other
)
=
delete
;
OneServerSocket
&
operator
=
(
const
OneServerSocket
&
other
)
=
delete
;
~
OneServerSocket
()
{
~
OneServerSocket
()
{
free
(
const_cast
<
struct
sockaddr
*>
(
address
.
GetAddress
()));
if
(
IsDefined
())
if
(
IsDefined
())
Close
();
Close
();
}
}
...
@@ -299,6 +295,15 @@ ServerSocket::AddAddress(SocketAddress address)
...
@@ -299,6 +295,15 @@ ServerSocket::AddAddress(SocketAddress address)
return
sockets
.
back
();
return
sockets
.
back
();
}
}
OneServerSocket
&
ServerSocket
::
AddAddress
(
AllocatedSocketAddress
&&
address
)
{
sockets
.
emplace_back
(
loop
,
*
this
,
next_serial
,
std
::
move
(
address
));
return
sockets
.
back
();
}
bool
bool
ServerSocket
::
AddFD
(
int
fd
,
Error
&
error
)
ServerSocket
::
AddFD
(
int
fd
,
Error
&
error
)
{
{
...
...
src/event/ServerSocket.hxx
View file @
fdeec030
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include <stddef.h>
#include <stddef.h>
class
SocketAddress
;
class
SocketAddress
;
class
AllocatedSocketAddress
;
class
EventLoop
;
class
EventLoop
;
class
Error
;
class
Error
;
class
AllocatedPath
;
class
AllocatedPath
;
...
@@ -52,6 +53,7 @@ public:
...
@@ -52,6 +53,7 @@ public:
private
:
private
:
OneServerSocket
&
AddAddress
(
SocketAddress
address
);
OneServerSocket
&
AddAddress
(
SocketAddress
address
);
OneServerSocket
&
AddAddress
(
AllocatedSocketAddress
&&
address
);
/**
/**
* Add a listener on a port on all IPv4 interfaces.
* Add a listener on a port on all IPv4 interfaces.
...
...
Write
Preview
Markdown
is supported
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