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
3274bb54
Commit
3274bb54
authored
Oct 19, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/ServerSocket: pass AllocatedPath to AddPath()
parent
7db12406
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
16 deletions
+21
-16
Listen.cxx
src/Listen.cxx
+3
-2
ServerSocket.cxx
src/event/ServerSocket.cxx
+16
-13
ServerSocket.hxx
src/event/ServerSocket.hxx
+2
-1
No files found.
src/Listen.cxx
View file @
3274bb54
...
...
@@ -67,8 +67,9 @@ listen_add_config_param(unsigned int port,
if
(
0
==
strcmp
(
param
->
value
.
c_str
(),
"any"
))
{
return
listen_socket
->
AddPort
(
port
,
error_r
);
}
else
if
(
param
->
value
[
0
]
==
'/'
||
param
->
value
[
0
]
==
'~'
)
{
const
auto
path
=
config_parse_path
(
param
,
error_r
);
return
!
path
.
IsNull
()
&&
listen_socket
->
AddPath
(
path
.
c_str
(),
error_r
);
auto
path
=
config_parse_path
(
param
,
error_r
);
return
!
path
.
IsNull
()
&&
listen_socket
->
AddPath
(
std
::
move
(
path
),
error_r
);
}
else
{
return
listen_socket
->
AddHost
(
param
->
value
.
c_str
(),
port
,
error_r
);
...
...
src/event/ServerSocket.cxx
View file @
3274bb54
...
...
@@ -29,12 +29,16 @@
#include "event/SocketMonitor.hxx"
#include "system/Resolver.hxx"
#include "system/fd_util.h"
#include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
...
...
@@ -60,7 +64,7 @@ class OneServerSocket final : private SocketMonitor {
const
unsigned
serial
;
char
*
path
;
AllocatedPath
path
;
size_t
address_length
;
struct
sockaddr
*
address
;
...
...
@@ -72,7 +76,7 @@ public:
size_t
_address_length
)
:
SocketMonitor
(
_loop
),
parent
(
_parent
),
serial
(
_serial
),
path
(
nullptr
),
path
(
AllocatedPath
::
Null
()
),
address_length
(
_address_length
),
address
((
sockaddr
*
)
g_memdup
(
_address
,
_address_length
))
{
...
...
@@ -84,7 +88,6 @@ public:
OneServerSocket
&
operator
=
(
const
OneServerSocket
&
other
)
=
delete
;
~
OneServerSocket
()
{
g_free
(
path
);
g_free
(
address
);
}
...
...
@@ -92,10 +95,10 @@ public:
return
serial
;
}
void
SetPath
(
const
char
*
_path
)
{
assert
(
path
==
nullptr
);
void
SetPath
(
AllocatedPath
&&
_path
)
{
assert
(
path
.
IsNull
()
);
path
=
g_strdup
(
_path
);
path
=
std
::
move
(
_path
);
}
bool
Open
(
Error
&
error
);
...
...
@@ -203,8 +206,8 @@ OneServerSocket::Open(Error &error)
/* allow everybody to connect */
if
(
path
!=
nullptr
)
chmod
(
path
,
0666
);
if
(
!
path
.
IsNull
()
)
chmod
(
path
.
c_str
()
,
0666
);
/* register in the GLib main loop */
...
...
@@ -403,25 +406,25 @@ ServerSocket::AddHost(const char *hostname, unsigned port, Error &error)
}
bool
ServerSocket
::
AddPath
(
const
char
*
path
,
Error
&
error
)
ServerSocket
::
AddPath
(
AllocatedPath
&&
path
,
Error
&
error
)
{
#ifdef HAVE_UN
struct
sockaddr_un
s_un
;
size_t
path_length
=
strlen
(
path
);
const
size_t
path_length
=
path
.
length
(
);
if
(
path_length
>=
sizeof
(
s_un
.
sun_path
))
{
error
.
Set
(
server_socket_domain
,
"UNIX socket path is too long"
);
return
false
;
}
unlink
(
path
);
RemoveFile
(
path
);
s_un
.
sun_family
=
AF_UNIX
;
memcpy
(
s_un
.
sun_path
,
path
,
path_length
+
1
);
memcpy
(
s_un
.
sun_path
,
path
.
c_str
()
,
path_length
+
1
);
OneServerSocket
&
s
=
AddAddress
((
const
sockaddr
&
)
s_un
,
sizeof
(
s_un
));
s
.
SetPath
(
path
);
s
.
SetPath
(
std
::
move
(
path
)
);
return
true
;
#else
/* !HAVE_UN */
...
...
src/event/ServerSocket.hxx
View file @
3274bb54
...
...
@@ -27,6 +27,7 @@
struct
sockaddr
;
class
EventLoop
;
class
Error
;
class
AllocatedPath
;
typedef
void
(
*
server_socket_callback_t
)(
int
fd
,
const
struct
sockaddr
*
address
,
...
...
@@ -100,7 +101,7 @@ public:
* ignore errors
* @return true on success
*/
bool
AddPath
(
const
char
*
path
,
Error
&
error
);
bool
AddPath
(
AllocatedPath
&&
path
,
Error
&
error
);
/**
* Add a socket descriptor that is accepting connections. After this
...
...
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