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
405ad9e5
Commit
405ad9e5
authored
Nov 03, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now one can specify multiple bind_to_addresses
git-svn-id:
https://svn.musicpd.org/mpd/trunk@2501
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
16335ba0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
97 additions
and
48 deletions
+97
-48
TODO
TODO
+0
-4
directory.c
src/directory.c
+1
-1
interface.c
src/interface.c
+2
-3
listen.c
src/listen.c
+78
-29
listen.h
src/listen.h
+13
-3
main.c
src/main.c
+2
-7
player.c
src/player.c
+1
-1
No files found.
TODO
View file @
405ad9e5
0.12
----
*) network stuff
*) allow specifying multiple bind_to_address's
*) use getaddrinfo instead of gethostbyname
*) rewrite saved playlist code
*) abstract out saved playlists from playlist.c
*) command for displaying playlist contents
...
...
src/directory.c
View file @
405ad9e5
...
...
@@ -193,7 +193,7 @@ int updateInit(FILE * fp, List * pathList) {
unblockSignals
();
finishSigHandlers
();
close
(
listenSocket
);
close
AllListenSockets
(
);
freeAllInterfaces
();
finishPlaylist
();
finishVolume
();
...
...
src/interface.c
View file @
405ad9e5
...
...
@@ -337,8 +337,7 @@ void addInterfacesReadyToReadAndListenSocketToFdSet(fd_set * fds, int * fdmax) {
int
i
;
FD_ZERO
(
fds
);
FD_SET
(
listenSocket
,
fds
);
if
(
*
fdmax
<
listenSocket
)
*
fdmax
=
listenSocket
;
addListenSocketsToFdSet
(
fds
,
fdmax
);
for
(
i
=
0
;
i
<
interface_max_connections
;
i
++
)
{
if
(
interfaces
[
i
].
open
&&
!
interfaces
[
i
].
expired
&&
!
interfaces
[
i
].
bufferList
)
{
...
...
@@ -396,7 +395,7 @@ int doIOForInterfaces() {
addInterfacesForBufferFlushToFdSet
(
&
wfds
,
&
fdmax
);
while
((
selret
=
select
(
fdmax
+
1
,
&
rfds
,
&
wfds
,
NULL
,
&
tv
)))
{
if
(
FD_ISSET
(
listenSocket
,
&
rfds
))
getConnections
(
listenSocket
);
getConnections
(
&
rfds
);
if
(
selret
<
0
&&
errno
==
EINTR
)
break
;
else
if
(
selret
<
0
)
{
closeNextErroredInterface
();
...
...
src/listen.c
View file @
405ad9e5
...
...
@@ -41,10 +41,10 @@
#define ALLOW_REUSE 1
int
listenSocket
;
int
*
listenSockets
=
NULL
;
int
numberOfListenSockets
=
0
;
int
establish
(
unsigned
short
port
)
{
ConfigParam
*
param
;
static
int
establishListen
(
unsigned
int
port
,
ConfigParam
*
param
)
{
int
allowReuse
=
ALLOW_REUSE
;
int
sock
;
struct
sockaddr
*
addrp
;
...
...
@@ -62,9 +62,8 @@ int establish(unsigned short port) {
sin
.
sin_port
=
htons
(
port
);
sin
.
sin_family
=
AF_INET
;
param
=
getConfigParam
(
CONF_BIND_TO_ADDRESS
);
if
(
!
param
||
0
==
strcmp
(
param
->
value
,
"any"
)
==
0
)
{
if
(
!
param
||
0
==
strcmp
(
param
->
value
,
"any"
))
{
DEBUG
(
"binding to any address
\n
"
);
#ifdef HAVE_IPV6
if
(
ipv6Supported
())
{
sin6
.
sin6_addr
=
in6addr_any
;
...
...
@@ -81,6 +80,7 @@ int establish(unsigned short port) {
}
else
{
struct
hostent
*
he
;
DEBUG
(
"binding to address for %s
\n
"
,
param
->
value
);
if
(
!
(
he
=
gethostbyname
(
param
->
value
)))
{
ERROR
(
"can't lookup host
\"
%s
\"
at line %i
\n
"
,
param
->
value
,
param
->
line
);
...
...
@@ -129,53 +129,102 @@ int establish(unsigned short port) {
break
;
default:
ERROR
(
"unknown address family: %i
\n
"
,
addrp
->
sa_family
);
return
-
1
;
exit
(
EXIT_FAILURE
)
;
}
if
((
sock
=
socket
(
pf
,
SOCK_STREAM
,
0
))
<
0
)
{
ERROR
(
"socket < 0
\n
"
);
return
-
1
;
exit
(
EXIT_FAILURE
);
}
if
(
fcntl
(
sock
,
F_SETFL
,
fcntl
(
sock
,
F_GETFL
)
|
O_NONBLOCK
)
<
0
)
{
ERROR
(
"problems setting nonblocking on listen socket: %s
\n
"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
if
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_REUSEADDR
,(
char
*
)
&
allowReuse
,
sizeof
(
allowReuse
))
<
0
)
{
close
(
sock
);
ERROR
(
"problems setsockopt'ing
\n
"
);
return
-
1
;
exit
(
EXIT_FAILURE
)
;
}
if
(
bind
(
sock
,
addrp
,
addrlen
)
<
0
)
{
ERROR
(
"unable to bind port %i, maybe MPD is still running?
\n
"
,
port
);
close
(
sock
);
return
-
1
;
ERROR
(
"unable to bind port %i: %s
\n
"
,
port
,
strerror
(
errno
));
ERROR
(
"maybe MPD is still running?
\n
"
);
exit
(
EXIT_FAILURE
);
}
if
(
listen
(
sock
,
5
)
<
0
)
{
close
(
sock
);
ERROR
(
"problems listen'ing
\n
"
);
return
-
1
;
ERROR
(
"problems listen'ing: %s
\n
"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
return
sock
;
}
void
getConnections
(
int
sock
)
{
fd_set
fdsr
;
void
establish
(
unsigned
int
port
)
{
ConfigParam
*
param
=
getNextConfigParam
(
CONF_BIND_TO_ADDRESS
,
NULL
);
do
{
numberOfListenSockets
++
;
listenSockets
=
realloc
(
listenSockets
,
sizeof
(
int
)
*
numberOfListenSockets
);
listenSockets
[
numberOfListenSockets
-
1
]
=
establishListen
(
port
,
param
);
}
while
((
param
=
getNextConfigParam
(
CONF_BIND_TO_ADDRESS
,
param
)));
}
void
addListenSocketsToFdSet
(
fd_set
*
fds
,
int
*
fdmax
)
{
int
i
;
for
(
i
=
0
;
i
<
numberOfListenSockets
;
i
++
)
{
FD_SET
(
listenSockets
[
i
],
fds
);
if
(
listenSockets
[
i
]
>
*
fdmax
)
*
fdmax
=
listenSockets
[
i
];
}
}
void
closeAllListenSockets
()
{
int
i
;
DEBUG
(
"closeAllListenSockets called
\n
"
);
for
(
i
=
0
;
i
<
numberOfListenSockets
;
i
++
)
{
DEBUG
(
"closing listen scoket %i
\n
"
,
i
);
while
(
close
(
listenSockets
[
i
])
<
0
&&
errno
==
EINTR
);
}
numberOfListenSockets
=
0
;
free
(
listenSockets
);
listenSockets
=
NULL
;
}
int
isAListenSocket
(
int
socket
)
{
int
i
;
for
(
i
=
0
;
listenSockets
[
i
]
!=
socket
&&
i
<
numberOfListenSockets
;
i
++
);
return
(
i
<
numberOfListenSockets
);
}
void
getConnections
(
fd_set
*
fds
)
{
int
i
;
int
fd
=
0
;
struct
timeval
tv
;
struct
sockaddr
sockAddr
;
socklen_t
socklen
=
sizeof
(
sockAddr
);
tv
.
tv_sec
=
tv
.
tv_usec
=
0
;
fflush
(
NULL
);
FD_ZERO
(
&
fdsr
);
FD_SET
(
sock
,
&
fdsr
);
if
(
select
(
sock
+
1
,
&
fdsr
,
NULL
,
NULL
,
&
tv
)
==
1
&&
((
fd
=
accept
(
sock
,
&
sockAddr
,
&
socklen
))
>=
0
))
{
openAInterface
(
fd
,
&
sockAddr
);
for
(
i
=
0
;
i
<
numberOfListenSockets
;
i
++
)
{
if
(
FD_ISSET
(
listenSockets
[
i
],
fds
))
{
if
((
fd
=
accept
(
listenSockets
[
i
],
&
sockAddr
,
&
socklen
))
>=
0
)
{
openAInterface
(
fd
,
&
sockAddr
);
}
else
if
(
fd
<
0
&&
(
errno
!=
EAGAIN
&&
errno
!=
EINTR
))
{
ERROR
(
"Problems accept()'ing
\n
"
);
}
}
}
else
if
(
fd
<
0
)
ERROR
(
"Problems accept()'ing
\n
"
);
}
src/listen.h
View file @
405ad9e5
...
...
@@ -21,10 +21,20 @@
#include "../config.h"
extern
int
listenSocket
;
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int
establish
(
unsigned
shor
t
port
);
void
establish
(
unsigned
in
t
port
);
void
getConnections
(
int
sock
);
void
getConnections
(
fd_set
*
fds
);
int
isAListenSocket
(
int
sock
);
void
closeAllListenSockets
();
/* fdmax should be initialized to something */
void
addListenSocketsToFdSet
(
fd_set
*
fds
,
int
*
fdmax
);
#endif
src/main.c
View file @
405ad9e5
...
...
@@ -226,12 +226,7 @@ void establishListen(Options * options) {
exit
(
EXIT_FAILURE
);
}
if
(
options
->
createDB
<=
0
&&
!
options
->
updateDB
&&
(
listenSocket
=
establish
(
port
))
<
0
)
{
ERROR
(
"error binding port
\n
"
);
exit
(
EXIT_FAILURE
);
}
if
(
options
->
createDB
<=
0
&&
!
options
->
updateDB
)
establish
(
port
);
}
void
changeToUser
(
Options
*
options
)
{
...
...
@@ -453,7 +448,7 @@ int main(int argc, char * argv[]) {
playerKill
();
freeAllInterfaces
();
close
(
listenSocket
);
closeAllListenSockets
(
);
closeMp3Directory
();
closeTables
();
finishPlaylist
();
...
...
src/player.c
View file @
405ad9e5
...
...
@@ -112,7 +112,7 @@ int playerInit() {
setSigHandlersForDecoder
();
while
(
close
(
listenSocket
)
<
0
&&
errno
==
EINTR
);
closeAllListenSockets
(
);
freeAllInterfaces
();
closeMp3Directory
();
finishPlaylist
();
...
...
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