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
bdbccc63
Commit
bdbccc63
authored
Oct 17, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: fixed send buffer
There is no sense in using the kernel's send buffer size (SO_SNDBUF) for MPD's send buffer. Convert it into a static buffer of 4 kB.
parent
48c11c52
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
49 deletions
+4
-49
client.c
src/client.c
+4
-49
No files found.
src/client.c
View file @
bdbccc63
...
...
@@ -43,7 +43,6 @@
#define CLIENT_LIST_MODE_BEGIN "command_list_begin"
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define CLIENT_LIST_MODE_END "command_list_end"
#define CLIENT_DEFAULT_OUT_BUFFER_SIZE (4096)
#define CLIENT_TIMEOUT_DEFAULT (60)
#define CLIENT_MAX_CONNECTIONS_DEFAULT (10)
#define CLIENT_MAX_COMMAND_LIST_DEFAULT (2048*1024)
...
...
@@ -88,10 +87,8 @@ struct client {
size_t
deferred_bytes
;
/* mem deferred_send consumes */
unsigned
int
num
;
/* client number */
char
*
send_buf
;
char
send_buf
[
4096
]
;
size_t
send_buf_used
;
/* bytes used this instance */
size_t
send_buf_size
;
/* bytes usable this instance */
size_t
send_buf_alloc
;
/* bytes actually allocated */
/** is this client waiting for an "idle" response? */
bool
idle_waiting
;
...
...
@@ -108,44 +105,6 @@ static void client_write_deferred(struct client *client);
static
void
client_write_output
(
struct
client
*
client
);
#ifdef SO_SNDBUF
static
size_t
get_default_snd_buf_size
(
struct
client
*
client
)
{
int
new_size
;
socklen_t
sockOptLen
=
sizeof
(
int
);
if
(
getsockopt
(
client
->
fd
,
SOL_SOCKET
,
SO_SNDBUF
,
(
char
*
)
&
new_size
,
&
sockOptLen
)
<
0
)
{
DEBUG
(
"problem getting sockets send buffer size
\n
"
);
return
CLIENT_DEFAULT_OUT_BUFFER_SIZE
;
}
if
(
new_size
>
0
)
return
(
size_t
)
new_size
;
DEBUG
(
"sockets send buffer size is not positive
\n
"
);
return
CLIENT_DEFAULT_OUT_BUFFER_SIZE
;
}
#else
/* !SO_SNDBUF */
static
size_t
get_default_snd_buf_size
(
struct
client
*
client
)
{
return
CLIENT_DEFAULT_OUT_BUFFER_SIZE
;
}
#endif
/* !SO_SNDBUF */
static
void
set_send_buf_size
(
struct
client
*
client
)
{
size_t
new_size
=
get_default_snd_buf_size
(
client
);
if
(
client
->
send_buf_size
!=
new_size
)
{
client
->
send_buf_size
=
new_size
;
/* don't resize to get smaller, only bigger */
if
(
client
->
send_buf_alloc
<
new_size
)
{
if
(
client
->
send_buf
)
free
(
client
->
send_buf
);
client
->
send_buf
=
xmalloc
(
new_size
);
client
->
send_buf_alloc
=
new_size
;
}
}
}
int
client_is_expired
(
const
struct
client
*
client
)
{
return
client
->
fd
<
0
;
...
...
@@ -196,7 +155,6 @@ static void client_init(struct client *client, int fd)
client
->
send_buf_used
=
0
;
client
->
permission
=
getDefaultPermissions
();
set_send_buf_size
(
client
);
xwrite
(
fd
,
GREETING
,
strlen
(
GREETING
));
}
...
...
@@ -283,9 +241,6 @@ static void client_close(struct client *client)
client
->
deferred_send
=
NULL
;
}
if
(
client
->
send_buf
)
free
(
client
->
send_buf
);
SECURE
(
"client %i: closed
\n
"
,
client
->
num
);
free
(
client
);
}
...
...
@@ -813,8 +768,8 @@ void client_write(struct client *client, const char *buffer, size_t buflen)
while
(
buflen
>
0
&&
!
client_is_expired
(
client
))
{
size_t
left
;
assert
(
client
->
send_buf_
size
>=
client
->
send_buf_used
);
left
=
client
->
send_buf_size
-
client
->
send_buf_used
;
assert
(
client
->
send_buf_
used
<
sizeof
(
client
->
send_buf
)
);
left
=
sizeof
(
client
->
send_buf
)
-
client
->
send_buf_used
;
copylen
=
buflen
>
left
?
left
:
buflen
;
memcpy
(
client
->
send_buf
+
client
->
send_buf_used
,
buffer
,
...
...
@@ -822,7 +777,7 @@ void client_write(struct client *client, const char *buffer, size_t buflen)
buflen
-=
copylen
;
client
->
send_buf_used
+=
copylen
;
buffer
+=
copylen
;
if
(
client
->
send_buf_used
>=
client
->
send_buf_size
)
if
(
client
->
send_buf_used
>=
sizeof
(
client
->
send_buf
)
)
client_write_output
(
client
);
}
}
...
...
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