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
12ab5564
Commit
12ab5564
authored
Oct 15, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/BufferedSocket: pass writable pointer to OnSocketInput()
Remove the const_cast from HttpdClient.cxx, and avoid one allocation in ClientRead.cxx.
parent
509f8dab
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
20 deletions
+23
-20
ClientInternal.hxx
src/ClientInternal.hxx
+1
-2
ClientRead.cxx
src/ClientRead.cxx
+7
-9
BufferedSocket.hxx
src/event/BufferedSocket.hxx
+9
-1
HttpdClient.cxx
src/output/HttpdClient.cxx
+5
-6
HttpdClient.hxx
src/output/HttpdClient.hxx
+1
-2
No files found.
src/ClientInternal.hxx
View file @
12ab5564
...
@@ -111,8 +111,7 @@ public:
...
@@ -111,8 +111,7 @@ public:
private
:
private
:
/* virtual methods from class BufferedSocket */
/* virtual methods from class BufferedSocket */
virtual
InputResult
OnSocketInput
(
const
void
*
data
,
virtual
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
override
;
size_t
length
)
override
;
virtual
void
OnSocketError
(
Error
&&
error
)
override
;
virtual
void
OnSocketError
(
Error
&&
error
)
override
;
virtual
void
OnSocketClosed
()
override
;
virtual
void
OnSocketClosed
()
override
;
...
...
src/ClientRead.cxx
View file @
12ab5564
...
@@ -22,27 +22,25 @@
...
@@ -22,27 +22,25 @@
#include "Main.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include "event/Loop.hxx"
#include <glib.h>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
BufferedSocket
::
InputResult
BufferedSocket
::
InputResult
Client
::
OnSocketInput
(
const
void
*
data
,
size_t
length
)
Client
::
OnSocketInput
(
void
*
data
,
size_t
length
)
{
{
c
onst
char
*
p
=
(
const
char
*
)
data
;
c
har
*
p
=
(
char
*
)
data
;
c
onst
char
*
newline
=
(
const
char
*
)
memchr
(
p
,
'\n'
,
length
);
c
har
*
newline
=
(
char
*
)
memchr
(
p
,
'\n'
,
length
);
if
(
newline
==
NULL
)
if
(
newline
==
NULL
)
return
InputResult
::
MORE
;
return
InputResult
::
MORE
;
TimeoutMonitor
::
ScheduleSeconds
(
client_timeout
);
TimeoutMonitor
::
ScheduleSeconds
(
client_timeout
);
char
*
line
=
g_strndup
(
p
,
newline
-
p
);
/* terminate the string at the end of the line */
BufferedSocket
::
ConsumeInput
(
newline
+
1
-
p
)
;
*
newline
=
0
;
enum
command_return
result
=
client_process_line
(
this
,
line
);
BufferedSocket
::
ConsumeInput
(
newline
+
1
-
p
);
g_free
(
line
);
enum
command_return
result
=
client_process_line
(
this
,
p
);
switch
(
result
)
{
switch
(
result
)
{
case
COMMAND_RETURN_OK
:
case
COMMAND_RETURN_OK
:
case
COMMAND_RETURN_IDLE
:
case
COMMAND_RETURN_IDLE
:
...
...
src/event/BufferedSocket.hxx
View file @
12ab5564
...
@@ -101,7 +101,15 @@ protected:
...
@@ -101,7 +101,15 @@ protected:
CLOSED
,
CLOSED
,
};
};
virtual
InputResult
OnSocketInput
(
const
void
*
data
,
size_t
length
)
=
0
;
/**
* Data has been received on the socket.
*
* @param data a pointer to the beginning of the buffer; the
* buffer may be modified by the method while it processes the
* data
*/
virtual
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
=
0
;
virtual
void
OnSocketError
(
Error
&&
error
)
=
0
;
virtual
void
OnSocketError
(
Error
&&
error
)
=
0
;
virtual
void
OnSocketClosed
()
=
0
;
virtual
void
OnSocketClosed
()
=
0
;
...
...
src/output/HttpdClient.cxx
View file @
12ab5564
...
@@ -402,7 +402,7 @@ HttpdClient::OnSocketReady(unsigned flags)
...
@@ -402,7 +402,7 @@ HttpdClient::OnSocketReady(unsigned flags)
}
}
BufferedSocket
::
InputResult
BufferedSocket
::
InputResult
HttpdClient
::
OnSocketInput
(
const
void
*
data
,
size_t
length
)
HttpdClient
::
OnSocketInput
(
void
*
data
,
size_t
length
)
{
{
if
(
state
==
RESPONSE
)
{
if
(
state
==
RESPONSE
)
{
LogWarning
(
httpd_output_domain
,
LogWarning
(
httpd_output_domain
,
...
@@ -411,8 +411,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
...
@@ -411,8 +411,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
return
InputResult
::
CLOSED
;
return
InputResult
::
CLOSED
;
}
}
c
onst
char
*
line
=
(
const
char
*
)
data
;
c
har
*
line
=
(
char
*
)
data
;
c
onst
char
*
newline
=
(
const
char
*
)
memchr
(
line
,
'\n'
,
length
);
c
har
*
newline
=
(
char
*
)
memchr
(
line
,
'\n'
,
length
);
if
(
newline
==
nullptr
)
if
(
newline
==
nullptr
)
return
InputResult
::
MORE
;
return
InputResult
::
MORE
;
...
@@ -421,9 +421,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
...
@@ -421,9 +421,8 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
if
(
newline
>
line
&&
newline
[
-
1
]
==
'\r'
)
if
(
newline
>
line
&&
newline
[
-
1
]
==
'\r'
)
--
newline
;
--
newline
;
/* terminate the string at the end of the line; the const_cast
/* terminate the string at the end of the line */
is a dirty hack */
*
newline
=
0
;
*
const_cast
<
char
*>
(
newline
)
=
0
;
if
(
!
HandleLine
(
line
))
{
if
(
!
HandleLine
(
line
))
{
assert
(
state
==
RESPONSE
);
assert
(
state
==
RESPONSE
);
...
...
src/output/HttpdClient.hxx
View file @
12ab5564
...
@@ -177,8 +177,7 @@ public:
...
@@ -177,8 +177,7 @@ public:
protected
:
protected
:
virtual
bool
OnSocketReady
(
unsigned
flags
)
override
;
virtual
bool
OnSocketReady
(
unsigned
flags
)
override
;
virtual
InputResult
OnSocketInput
(
const
void
*
data
,
virtual
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
override
;
size_t
length
)
override
;
virtual
void
OnSocketError
(
Error
&&
error
)
override
;
virtual
void
OnSocketError
(
Error
&&
error
)
override
;
virtual
void
OnSocketClosed
()
override
;
virtual
void
OnSocketClosed
()
override
;
};
};
...
...
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