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
86afc13c
Commit
86afc13c
authored
Nov 14, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimized read() on clients, should be much, much faster now
git-svn-id:
https://svn.musicpd.org/mpd/trunk@2649
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
2c08fa61
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
126 deletions
+123
-126
TODO
TODO
+0
-2
command.c
src/command.c
+3
-3
interface.c
src/interface.c
+120
-121
No files found.
TODO
View file @
86afc13c
...
@@ -34,8 +34,6 @@
...
@@ -34,8 +34,6 @@
*) Cleanup Config File Code
*) Cleanup Config File Code
*) Optimize read() on clients
*) Handle mp1 and mp2 files (including mp2's that are disguised as mp3's with
*) Handle mp1 and mp2 files (including mp2's that are disguised as mp3's with
a mp3 suffix)
a mp3 suffix)
...
...
src/command.c
View file @
86afc13c
...
@@ -83,9 +83,9 @@
...
@@ -83,9 +83,9 @@
#define COMMAND_URL_HANDLERS "urlhandlers"
#define COMMAND_URL_HANDLERS "urlhandlers"
#define COMMAND_PLCHANGES "plchanges"
#define COMMAND_PLCHANGES "plchanges"
#define COMMAND_CURRENTSONG "currentsong"
#define COMMAND_CURRENTSONG "currentsong"
#define COMMAND_ENABLE_DEV "enable
device
"
#define COMMAND_ENABLE_DEV "enable
output
"
#define COMMAND_DISABLE_DEV "disable
device
"
#define COMMAND_DISABLE_DEV "disable
output
"
#define COMMAND_DEVICES "
device
s"
#define COMMAND_DEVICES "
output
s"
#define COMMAND_COMMANDS "commands"
#define COMMAND_COMMANDS "commands"
#define COMMAND_STATUS_VOLUME "volume"
#define COMMAND_STATUS_VOLUME "volume"
...
...
src/interface.c
View file @
86afc13c
...
@@ -62,8 +62,9 @@ static size_t interface_max_output_buffer_size =
...
@@ -62,8 +62,9 @@ static size_t interface_max_output_buffer_size =
INTERFACE_MAX_OUTPUT_BUFFER_SIZE_DEFAULT
;
INTERFACE_MAX_OUTPUT_BUFFER_SIZE_DEFAULT
;
typedef
struct
_Interface
{
typedef
struct
_Interface
{
char
buffer
[
INTERFACE_MAX_BUFFER_LENGTH
+
2
];
char
buffer
[
INTERFACE_MAX_BUFFER_LENGTH
];
int
bufferLength
;
int
bufferLength
;
int
bufferPos
;
int
fd
;
/* file descriptor */
int
fd
;
/* file descriptor */
FILE
*
fp
;
/* file pointer */
FILE
*
fp
;
/* file pointer */
int
open
;
/* open/used */
int
open
;
/* open/used */
...
@@ -94,6 +95,7 @@ void openInterface(Interface * interface, int fd) {
...
@@ -94,6 +95,7 @@ void openInterface(Interface * interface, int fd) {
assert
(
interface
->
open
==
0
);
assert
(
interface
->
open
==
0
);
interface
->
bufferLength
=
0
;
interface
->
bufferLength
=
0
;
interface
->
bufferPos
=
0
;
interface
->
fd
=
fd
;
interface
->
fd
=
fd
;
/* fcntl(interface->fd,F_SETOWN,(int)getpid()); */
/* fcntl(interface->fd,F_SETOWN,(int)getpid()); */
while
((
flags
=
fcntl
(
fd
,
F_GETFL
))
<
0
&&
errno
==
EINTR
);
while
((
flags
=
fcntl
(
fd
,
F_GETFL
))
<
0
&&
errno
==
EINTR
);
...
@@ -200,138 +202,135 @@ void openAInterface(int fd, struct sockaddr * addr) {
...
@@ -200,138 +202,135 @@ void openAInterface(int fd, struct sockaddr * addr) {
}
}
}
}
int
interfaceReadInput
(
Interface
*
interface
)
{
static
int
proccessLineOfInput
(
Interface
*
interface
)
{
blockSignals
();
int
ret
=
1
;
if
(
read
(
interface
->
fd
,
interface
->
buffer
+
interface
->
bufferLength
,
1
)
>
0
)
{
char
*
line
=
interface
->
buffer
+
interface
->
bufferPos
;
int
ret
=
1
;
int
bytesRead
=
1
;
if
(
interface
->
bufferLength
-
interface
->
bufferPos
>
1
)
{
while
(
bytesRead
>
0
)
{
if
(
interface
->
buffer
[
interface
->
bufferLength
-
2
]
==
'\r'
)
{
interface
->
buffer
[
interface
->
bufferLength
+
1
]
=
'\0'
;
interface
->
buffer
[
interface
->
bufferLength
-
2
]
=
'\0'
;
if
(
interface
->
buffer
[
interface
->
bufferLength
]
!=
'\r'
)
{
interface
->
bufferLength
++
;
}
if
(
interface
->
bufferLength
>=
INTERFACE_MAX_BUFFER_LENGTH
)
{
break
;
}
if
(
interface
->
buffer
[
interface
->
bufferLength
-
1
]
==
'\n'
)
{
break
;
}
bytesRead
=
read
(
interface
->
fd
,
interface
->
buffer
+
interface
->
bufferLength
,
1
);
}
unblockSignals
();
if
(
interface
->
bufferLength
>=
INTERFACE_MAX_BUFFER_LENGTH
)
{
ERROR
(
"interface %i: buffer overflow
\n
"
,
interface
->
num
);
closeInterface
(
interface
);
}
}
else
if
(
interface
->
buffer
[
interface
->
bufferLength
-
1
]
==
'\n'
)
{
}
interface
->
buffer
[
interface
->
bufferLength
-
1
]
=
'\0'
;
interface
->
bufferLength
=
0
;
if
(
interface
->
commandList
)
{
if
(
interface
->
commandList
)
{
if
(
strcmp
(
interface
->
buffer
,
if
(
strcmp
(
line
,
INTERFACE_LIST_MODE_END
)
==
0
)
{
INTERFACE_LIST_MODE_END
)
==
0
)
DEBUG
(
"interface %i: process command "
{
"list
\n
"
,
interface
->
num
);
DEBUG
(
"interface %i: process command "
ret
=
proccessListOfCommands
(
"list
\n
"
,
interface
->
num
);
interface
->
fp
,
ret
=
proccessListOfCommands
(
&
(
interface
->
permission
),
interface
->
fp
,
&
(
interface
->
expired
),
&
(
interface
->
permission
),
interface
->
commandListOK
,
&
(
interface
->
expired
),
interface
->
commandList
);
interface
->
commandListOK
,
DEBUG
(
"interface %i: process command "
interface
->
commandList
);
"list returned %i
\n
"
,
DEBUG
(
"interface %i: process command "
interface
->
num
,
"list returned %i
\n
"
,
ret
);
if
(
ret
==
0
)
commandSuccess
(
interface
->
fp
);
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
interface
->
expired
)
{
closeInterface
(
interface
);
}
printInterfaceOutBuffer
(
interface
);
freeList
(
interface
->
commandList
);
interface
->
commandList
=
NULL
;
}
else
{
interface
->
commandListSize
+=
sizeof
(
ListNode
);
interface
->
commandListSize
+=
strlen
(
line
)
+
1
;
if
(
interface
->
commandListSize
>
interface_max_command_list_size
)
{
ERROR
(
"interface %i: command "
"list size (%lli) is "
"larger than the max "
"(%lli)
\n
"
,
interface
->
num
,
interface
->
num
,
ret
);
interface
->
if
(
ret
==
0
)
{
commandListSize
,
commandSuccess
(
interface
->
fp
);
}
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
interface
->
expired
)
{
closeInterface
(
interface
);
}
printInterfaceOutBuffer
(
interface
);
freeList
(
interface
->
commandList
);
interface
->
commandList
=
NULL
;
}
else
{
interface
->
commandListSize
+=
sizeof
(
ListNode
);
interface
->
commandListSize
+=
strlen
(
interface
->
buffer
)
+
1
;
if
(
interface
->
commandListSize
>
interface_max_command_list_size
)
interface_max_command_list_size
)
{
;
ERROR
(
"interface %i: command "
closeInterface
(
interface
);
"list size (%lli) is "
"larger than the max "
"(%lli)
\n
"
,
interface
->
num
,
interface
->
commandListSize
,
interface_max_command_list_size
);
closeInterface
(
interface
);
}
else
{
insertInListWithoutKey
(
interface
->
commandList
,
strdup
(
interface
->
buffer
));
}
}
}
}
else
{
else
{
if
(
strcmp
(
interface
->
buffer
,
insertInListWithoutKey
(
interface
->
commandList
,
INTERFACE_LIST_MODE_BEGIN
)
==
0
)
strdup
(
line
));
{
interface
->
commandList
=
makeList
(
free
,
1
);
interface
->
commandListSize
=
sizeof
(
List
);
interface
->
commandListOK
=
0
;
ret
=
1
;
}
else
if
(
strcmp
(
interface
->
buffer
,
INTERFACE_LIST_OK_MODE_BEGIN
)
==
0
)
{
interface
->
commandList
=
makeList
(
free
,
1
);
interface
->
commandListSize
=
sizeof
(
List
);
interface
->
commandListOK
=
1
;
ret
=
1
;
}
else
{
DEBUG
(
"interface %i: process command
\"
%s
\"\n
"
,
interface
->
num
,
interface
->
buffer
);
ret
=
processCommand
(
interface
->
fp
,
&
(
interface
->
permission
),
interface
->
buffer
);
DEBUG
(
"interface %i: command returned %i
\n
"
,
interface
->
num
,
ret
);
if
(
ret
==
0
)
{
commandSuccess
(
interface
->
fp
);
}
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
interface
->
expired
)
{
closeInterface
(
interface
);
}
printInterfaceOutBuffer
(
interface
);
}
}
}
}
}
return
ret
;
}
}
else
{
else
{
unblockSignals
();
if
(
strcmp
(
line
,
INTERFACE_LIST_MODE_BEGIN
)
==
0
)
{
closeInterface
(
interface
);
interface
->
commandList
=
makeList
(
free
,
1
);
interface
->
commandListSize
=
sizeof
(
List
);
interface
->
commandListOK
=
0
;
ret
=
1
;
}
else
if
(
strcmp
(
line
,
INTERFACE_LIST_OK_MODE_BEGIN
)
==
0
)
{
interface
->
commandList
=
makeList
(
free
,
1
);
interface
->
commandListSize
=
sizeof
(
List
);
interface
->
commandListOK
=
1
;
ret
=
1
;
}
else
{
DEBUG
(
"interface %i: process command
\"
%s
\"\n
"
,
interface
->
num
,
line
);
ret
=
processCommand
(
interface
->
fp
,
&
(
interface
->
permission
),
line
);
DEBUG
(
"interface %i: command returned %i
\n
"
,
interface
->
num
,
ret
);
if
(
ret
==
0
)
commandSuccess
(
interface
->
fp
);
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
interface
->
expired
)
{
closeInterface
(
interface
);
}
printInterfaceOutBuffer
(
interface
);
}
}
}
return
ret
;
}
static
int
processBytesRead
(
Interface
*
interface
,
int
bytesRead
)
{
int
ret
=
1
;
while
(
bytesRead
>
0
)
{
interface
->
bufferLength
++
;
bytesRead
--
;
if
(
interface
->
buffer
[
interface
->
bufferLength
-
1
]
==
'\n'
)
{
interface
->
buffer
[
interface
->
bufferLength
-
1
]
=
'\0'
;
ret
=
proccessLineOfInput
(
interface
);
interface
->
bufferPos
=
interface
->
bufferLength
;
}
if
(
interface
->
bufferLength
==
INTERFACE_MAX_BUFFER_LENGTH
)
{
if
(
interface
->
bufferPos
==
0
)
{
ERROR
(
"interface %i: buffer overflow
\n
"
,
interface
->
num
);
return
1
;
}
interface
->
bufferLength
-=
interface
->
bufferPos
;
memmove
(
interface
->
buffer
,
interface
->
buffer
+
interface
->
bufferPos
,
interface
->
bufferLength
);
interface
->
bufferPos
=
0
;
}
}
return
0
;
}
int
interfaceReadInput
(
Interface
*
interface
)
{
int
bytesRead
=
read
(
interface
->
fd
,
interface
->
buffer
+
interface
->
bufferLength
,
INTERFACE_MAX_BUFFER_LENGTH
-
interface
->
bufferLength
+
1
);
if
(
bytesRead
>
0
)
return
processBytesRead
(
interface
,
bytesRead
);
else
if
(
bytesRead
==
0
&&
errno
!=
EINTR
)
closeInterface
(
interface
);
else
return
0
;
return
1
;
return
1
;
}
}
...
...
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