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
3ecd9184
Commit
3ecd9184
authored
Feb 24, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zeroconf/Bonjour: move the DNSServiceRegister() call to the constructor
parent
4fbdb3a2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
24 deletions
+39
-24
Bonjour.cxx
src/zeroconf/Bonjour.cxx
+36
-24
Bonjour.hxx
src/zeroconf/Bonjour.hxx
+3
-0
No files found.
src/zeroconf/Bonjour.cxx
View file @
3ecd9184
...
...
@@ -26,6 +26,8 @@
#include <dns_sd.h>
#include <stdexcept>
#include <arpa/inet.h>
static
constexpr
Domain
bonjour_domain
(
"bonjour"
);
...
...
@@ -36,14 +38,7 @@ class BonjourHelper final {
SocketEvent
socket_event
;
public
:
BonjourHelper
(
EventLoop
&
_loop
,
DNSServiceRef
_service_ref
)
:
service_ref
(
_service_ref
),
socket_event
(
_loop
,
BIND_THIS_METHOD
(
OnSocketReady
),
SocketDescriptor
(
DNSServiceRefSockFD
(
service_ref
)))
{
socket_event
.
ScheduleRead
();
}
BonjourHelper
(
EventLoop
&
_loop
,
const
char
*
name
,
unsigned
port
);
~
BonjourHelper
()
{
DNSServiceRefDeallocate
(
service_ref
);
...
...
@@ -69,6 +64,38 @@ protected:
}
};
/**
* A wrapper for DNSServiceRegister() which returns the DNSServiceRef
* and throws on error.
*/
static
DNSServiceRef
RegisterBonjour
(
const
char
*
name
,
const
char
*
type
,
unsigned
port
,
DNSServiceRegisterReply
callback
,
void
*
ctx
)
{
DNSServiceRef
ref
;
DNSServiceErrorType
error
=
DNSServiceRegister
(
&
ref
,
0
,
0
,
name
,
type
,
nullptr
,
nullptr
,
htons
(
port
),
0
,
nullptr
,
callback
,
ctx
);
if
(
error
!=
kDNSServiceErr_NoError
)
throw
std
::
runtime_error
(
"DNSServiceRegister() failed"
);
return
ref
;
}
BonjourHelper
::
BonjourHelper
(
EventLoop
&
_loop
,
const
char
*
name
,
unsigned
port
)
:
service_ref
(
RegisterBonjour
(
name
,
SERVICE_TYPE
,
port
,
Callback
,
nullptr
)),
socket_event
(
_loop
,
BIND_THIS_METHOD
(
OnSocketReady
),
SocketDescriptor
(
DNSServiceRefSockFD
(
service_ref
)))
{
socket_event
.
ScheduleRead
();
}
static
BonjourHelper
*
bonjour_monitor
;
void
...
...
@@ -94,22 +121,7 @@ BonjourHelper::Callback([[maybe_unused]] DNSServiceRef sdRef,
void
BonjourInit
(
EventLoop
&
loop
,
const
char
*
service_name
,
unsigned
port
)
{
DNSServiceRef
dnsReference
;
DNSServiceErrorType
error
=
DNSServiceRegister
(
&
dnsReference
,
0
,
0
,
service_name
,
SERVICE_TYPE
,
nullptr
,
nullptr
,
htons
(
port
),
0
,
nullptr
,
BonjourHelper
::
Callback
,
nullptr
);
if
(
error
!=
kDNSServiceErr_NoError
)
{
LogError
(
bonjour_domain
,
"Failed to register zeroconf service"
);
return
;
}
bonjour_monitor
=
new
BonjourHelper
(
loop
,
dnsReference
);
bonjour_monitor
=
new
BonjourHelper
(
loop
,
service_name
,
port
);
}
void
...
...
src/zeroconf/Bonjour.hxx
View file @
3ecd9184
...
...
@@ -22,6 +22,9 @@
class
EventLoop
;
/**
* Throws on error.
*/
void
BonjourInit
(
EventLoop
&
loop
,
const
char
*
service_name
,
unsigned
port
);
...
...
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