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
1e2018ce
Commit
1e2018ce
authored
Jan 15, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client: move connection functions into the class
parent
3fcf17cb
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
50 additions
and
56 deletions
+50
-56
Client.cxx
src/Client.cxx
+0
-5
Client.hxx
src/Client.hxx
+0
-3
ClientEvent.cxx
src/ClientEvent.cxx
+10
-10
ClientExpire.cxx
src/ClientExpire.cxx
+11
-11
ClientGlobal.cxx
src/ClientGlobal.cxx
+1
-1
ClientIdle.cxx
src/ClientIdle.cxx
+1
-1
ClientInternal.hxx
src/ClientInternal.hxx
+9
-6
ClientNew.cxx
src/ClientNew.cxx
+5
-6
ClientProcess.cxx
src/ClientProcess.cxx
+3
-3
ClientRead.cxx
src/ClientRead.cxx
+1
-1
ClientWrite.cxx
src/ClientWrite.cxx
+9
-9
No files found.
src/Client.cxx
View file @
1e2018ce
...
@@ -20,11 +20,6 @@
...
@@ -20,11 +20,6 @@
#include "config.h"
#include "config.h"
#include "ClientInternal.hxx"
#include "ClientInternal.hxx"
bool
client_is_expired
(
const
Client
*
client
)
{
return
client
->
channel
==
NULL
;
}
int
client_get_uid
(
const
Client
*
client
)
int
client_get_uid
(
const
Client
*
client
)
{
{
return
client
->
uid
;
return
client
->
uid
;
...
...
src/Client.hxx
View file @
1e2018ce
...
@@ -37,9 +37,6 @@ void
...
@@ -37,9 +37,6 @@ void
client_new
(
Partition
&
partition
,
client_new
(
Partition
&
partition
,
int
fd
,
const
struct
sockaddr
*
sa
,
size_t
sa_length
,
int
uid
);
int
fd
,
const
struct
sockaddr
*
sa
,
size_t
sa_length
,
int
uid
);
gcc_pure
bool
client_is_expired
(
const
Client
*
client
);
/**
/**
* returns the uid of the client process, or a negative value if the
* returns the uid of the client process, or a negative value if the
* uid is unknown
* uid is unknown
...
...
src/ClientEvent.cxx
View file @
1e2018ce
...
@@ -30,17 +30,17 @@ client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
...
@@ -30,17 +30,17 @@ client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
{
{
Client
*
client
=
(
Client
*
)
data
;
Client
*
client
=
(
Client
*
)
data
;
assert
(
!
client
_is_expired
(
client
));
assert
(
!
client
->
IsExpired
(
));
if
(
condition
!=
G_IO_OUT
)
{
if
(
condition
!=
G_IO_OUT
)
{
client
_set_expired
(
client
);
client
->
SetExpired
(
);
return
false
;
return
false
;
}
}
client_write_deferred
(
client
);
client_write_deferred
(
client
);
if
(
client
_is_expired
(
client
))
{
if
(
client
->
IsExpired
(
))
{
client
_close
(
client
);
client
->
Close
(
);
return
false
;
return
false
;
}
}
...
@@ -66,10 +66,10 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
...
@@ -66,10 +66,10 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
Client
*
client
=
(
Client
*
)
data
;
Client
*
client
=
(
Client
*
)
data
;
enum
command_return
ret
;
enum
command_return
ret
;
assert
(
!
client
_is_expired
(
client
));
assert
(
!
client
->
IsExpired
(
));
if
(
condition
!=
G_IO_IN
)
{
if
(
condition
!=
G_IO_IN
)
{
client
_set_expired
(
client
);
client
->
SetExpired
(
);
return
false
;
return
false
;
}
}
...
@@ -83,17 +83,17 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
...
@@ -83,17 +83,17 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
break
;
break
;
case
COMMAND_RETURN_KILL
:
case
COMMAND_RETURN_KILL
:
client
_close
(
client
);
client
->
Close
(
);
main_loop
->
Break
();
main_loop
->
Break
();
return
false
;
return
false
;
case
COMMAND_RETURN_CLOSE
:
case
COMMAND_RETURN_CLOSE
:
client
_close
(
client
);
client
->
Close
(
);
return
false
;
return
false
;
}
}
if
(
client
_is_expired
(
client
))
{
if
(
client
->
IsExpired
(
))
{
client
_close
(
client
);
client
->
Close
(
);
return
false
;
return
false
;
}
}
...
...
src/ClientExpire.cxx
View file @
1e2018ce
...
@@ -24,34 +24,34 @@
...
@@ -24,34 +24,34 @@
static
guint
expire_source_id
;
static
guint
expire_source_id
;
void
void
client_set_expired
(
Client
*
client
)
Client
::
SetExpired
(
)
{
{
if
(
!
client_is_expired
(
client
))
if
(
!
IsExpired
(
))
client_schedule_expire
();
client_schedule_expire
();
if
(
client
->
source_id
!=
0
)
{
if
(
source_id
!=
0
)
{
g_source_remove
(
client
->
source_id
);
g_source_remove
(
source_id
);
client
->
source_id
=
0
;
source_id
=
0
;
}
}
if
(
c
lient
->
c
hannel
!=
NULL
)
{
if
(
channel
!=
NULL
)
{
g_io_channel_unref
(
c
lient
->
c
hannel
);
g_io_channel_unref
(
channel
);
c
lient
->
channel
=
NULL
;
c
hannel
=
nullptr
;
}
}
}
}
static
void
static
void
client_check_expired_callback
(
Client
*
client
,
G_GNUC_UNUSED
gpointer
user_data
)
client_check_expired_callback
(
Client
*
client
,
G_GNUC_UNUSED
gpointer
user_data
)
{
{
if
(
client
_is_expired
(
client
))
{
if
(
client
->
IsExpired
(
))
{
g_debug
(
"[%u] expired"
,
client
->
num
);
g_debug
(
"[%u] expired"
,
client
->
num
);
client
_close
(
client
);
client
->
Close
(
);
}
else
if
(
!
client
->
idle_waiting
&&
/* idle clients
}
else
if
(
!
client
->
idle_waiting
&&
/* idle clients
never expire */
never expire */
(
int
)
g_timer_elapsed
(
client
->
last_activity
,
NULL
)
>
(
int
)
g_timer_elapsed
(
client
->
last_activity
,
NULL
)
>
client_timeout
)
{
client_timeout
)
{
g_debug
(
"[%u] timeout"
,
client
->
num
);
g_debug
(
"[%u] timeout"
,
client
->
num
);
client
_close
(
client
);
client
->
Close
(
);
}
}
}
}
...
...
src/ClientGlobal.cxx
View file @
1e2018ce
...
@@ -58,7 +58,7 @@ static void client_close_all(void)
...
@@ -58,7 +58,7 @@ static void client_close_all(void)
while
(
!
client_list_is_empty
())
{
while
(
!
client_list_is_empty
())
{
Client
*
client
=
client_list_get_first
();
Client
*
client
=
client_list_get_first
();
client
_close
(
client
);
client
->
Close
(
);
}
}
assert
(
client_list_is_empty
());
assert
(
client_list_is_empty
());
...
...
src/ClientIdle.cxx
View file @
1e2018ce
...
@@ -55,7 +55,7 @@ client_idle_notify(Client *client)
...
@@ -55,7 +55,7 @@ client_idle_notify(Client *client)
void
void
client_idle_add
(
Client
*
client
,
unsigned
flags
)
client_idle_add
(
Client
*
client
,
unsigned
flags
)
{
{
if
(
client
_is_expired
(
client
))
if
(
client
->
IsExpired
(
))
return
;
return
;
client
->
idle_flags
|=
flags
;
client
->
idle_flags
|=
flags
;
...
...
src/ClientInternal.hxx
View file @
1e2018ce
...
@@ -112,6 +112,15 @@ public:
...
@@ -112,6 +112,15 @@ public:
bool
IsSubscribed
(
const
char
*
channel_name
)
const
{
bool
IsSubscribed
(
const
char
*
channel_name
)
const
{
return
subscriptions
.
find
(
channel_name
)
!=
subscriptions
.
end
();
return
subscriptions
.
find
(
channel_name
)
!=
subscriptions
.
end
();
}
}
gcc_pure
bool
IsExpired
()
const
{
return
channel
==
nullptr
;
}
void
Close
();
void
SetExpired
();
};
};
extern
unsigned
int
client_max_connections
;
extern
unsigned
int
client_max_connections
;
...
@@ -119,12 +128,6 @@ extern int client_timeout;
...
@@ -119,12 +128,6 @@ extern int client_timeout;
extern
size_t
client_max_command_list_size
;
extern
size_t
client_max_command_list_size
;
extern
size_t
client_max_output_buffer_size
;
extern
size_t
client_max_output_buffer_size
;
void
client_close
(
Client
*
client
);
void
client_set_expired
(
Client
*
client
);
/**
/**
* Schedule an "expired" check for all clients: permanently delete
* Schedule an "expired" check for all clients: permanently delete
* clients which have been set "expired" with client_set_expired().
* clients which have been set "expired" with client_set_expired().
...
...
src/ClientNew.cxx
View file @
1e2018ce
...
@@ -149,13 +149,12 @@ client_new(Partition &partition,
...
@@ -149,13 +149,12 @@ client_new(Partition &partition,
}
}
void
void
client_close
(
Client
*
client
)
Client
::
Close
(
)
{
{
client_list_remove
(
client
);
client_list_remove
(
this
);
client_set_expired
(
client
);
SetExpired
(
);
g_log
(
G_LOG_DOMAIN
,
LOG_LEVEL_SECURE
,
g_log
(
G_LOG_DOMAIN
,
LOG_LEVEL_SECURE
,
"[%u] closed"
,
num
);
"[%u] closed"
,
client
->
num
);
delete
this
;
delete
client
;
}
}
src/ClientProcess.cxx
View file @
1e2018ce
...
@@ -42,7 +42,7 @@ client_process_command_list(Client *client, bool list_ok,
...
@@ -42,7 +42,7 @@ client_process_command_list(Client *client, bool list_ok,
cmd
);
cmd
);
ret
=
command_process
(
client
,
num
++
,
cmd
);
ret
=
command_process
(
client
,
num
++
,
cmd
);
g_debug
(
"command_process_list: command returned %i"
,
ret
);
g_debug
(
"command_process_list: command returned %i"
,
ret
);
if
(
ret
!=
COMMAND_RETURN_OK
||
client
_is_expired
(
client
))
if
(
ret
!=
COMMAND_RETURN_OK
||
client
->
IsExpired
(
))
break
;
break
;
else
if
(
list_ok
)
else
if
(
list_ok
)
client_puts
(
client
,
"list_OK
\n
"
);
client_puts
(
client
,
"list_OK
\n
"
);
...
@@ -91,7 +91,7 @@ client_process_line(Client *client, char *line)
...
@@ -91,7 +91,7 @@ client_process_line(Client *client, char *line)
"list returned %i"
,
client
->
num
,
ret
);
"list returned %i"
,
client
->
num
,
ret
);
if
(
ret
==
COMMAND_RETURN_CLOSE
||
if
(
ret
==
COMMAND_RETURN_CLOSE
||
client
_is_expired
(
client
))
client
->
IsExpired
(
))
return
COMMAND_RETURN_CLOSE
;
return
COMMAND_RETURN_CLOSE
;
if
(
ret
==
COMMAND_RETURN_OK
)
if
(
ret
==
COMMAND_RETURN_OK
)
...
@@ -125,7 +125,7 @@ client_process_line(Client *client, char *line)
...
@@ -125,7 +125,7 @@ client_process_line(Client *client, char *line)
client
->
num
,
ret
);
client
->
num
,
ret
);
if
(
ret
==
COMMAND_RETURN_CLOSE
||
if
(
ret
==
COMMAND_RETURN_CLOSE
||
client
_is_expired
(
client
))
client
->
IsExpired
(
))
return
COMMAND_RETURN_CLOSE
;
return
COMMAND_RETURN_CLOSE
;
if
(
ret
==
COMMAND_RETURN_OK
)
if
(
ret
==
COMMAND_RETURN_OK
)
...
...
src/ClientRead.cxx
View file @
1e2018ce
...
@@ -58,7 +58,7 @@ client_input_received(Client *client, size_t bytesRead)
...
@@ -58,7 +58,7 @@ client_input_received(Client *client, size_t bytesRead)
if
(
ret
==
COMMAND_RETURN_KILL
||
if
(
ret
==
COMMAND_RETURN_KILL
||
ret
==
COMMAND_RETURN_CLOSE
)
ret
==
COMMAND_RETURN_CLOSE
)
return
ret
;
return
ret
;
if
(
client
_is_expired
(
client
))
if
(
client
->
IsExpired
(
))
return
COMMAND_RETURN_CLOSE
;
return
COMMAND_RETURN_CLOSE
;
}
}
...
...
src/ClientWrite.cxx
View file @
1e2018ce
...
@@ -49,13 +49,13 @@ client_write_deferred_buffer(Client *client,
...
@@ -49,13 +49,13 @@ client_write_deferred_buffer(Client *client,
case
G_IO_STATUS_EOF
:
case
G_IO_STATUS_EOF
:
/* client has disconnected */
/* client has disconnected */
client
_set_expired
(
client
);
client
->
SetExpired
(
);
return
0
;
return
0
;
case
G_IO_STATUS_ERROR
:
case
G_IO_STATUS_ERROR
:
/* I/O error */
/* I/O error */
client
_set_expired
(
client
);
client
->
SetExpired
(
);
g_warning
(
"failed to flush buffer for %i: %s"
,
g_warning
(
"failed to flush buffer for %i: %s"
,
client
->
num
,
error
->
message
);
client
->
num
,
error
->
message
);
g_error_free
(
error
);
g_error_free
(
error
);
...
@@ -126,7 +126,7 @@ client_defer_output(Client *client, const void *data, size_t length)
...
@@ -126,7 +126,7 @@ client_defer_output(Client *client, const void *data, size_t length)
(
unsigned
long
)
client
->
deferred_bytes
,
(
unsigned
long
)
client
->
deferred_bytes
,
(
unsigned
long
)
client_max_output_buffer_size
);
(
unsigned
long
)
client_max_output_buffer_size
);
/* cause client to close */
/* cause client to close */
client
_set_expired
(
client
);
client
->
SetExpired
(
);
return
;
return
;
}
}
...
@@ -160,13 +160,13 @@ client_write_direct(Client *client, const char *data, size_t length)
...
@@ -160,13 +160,13 @@ client_write_direct(Client *client, const char *data, size_t length)
case
G_IO_STATUS_EOF
:
case
G_IO_STATUS_EOF
:
/* client has disconnected */
/* client has disconnected */
client
_set_expired
(
client
);
client
->
SetExpired
(
);
return
;
return
;
case
G_IO_STATUS_ERROR
:
case
G_IO_STATUS_ERROR
:
/* I/O error */
/* I/O error */
client
_set_expired
(
client
);
client
->
SetExpired
(
);
g_warning
(
"failed to write to %i: %s"
,
g_warning
(
"failed to write to %i: %s"
,
client
->
num
,
error
->
message
);
client
->
num
,
error
->
message
);
g_error_free
(
error
);
g_error_free
(
error
);
...
@@ -184,14 +184,14 @@ client_write_direct(Client *client, const char *data, size_t length)
...
@@ -184,14 +184,14 @@ client_write_direct(Client *client, const char *data, size_t length)
void
void
client_write_output
(
Client
*
client
)
client_write_output
(
Client
*
client
)
{
{
if
(
client
_is_expired
(
client
)
||
!
client
->
send_buf_used
)
if
(
client
->
IsExpired
(
)
||
!
client
->
send_buf_used
)
return
;
return
;
if
(
!
g_queue_is_empty
(
client
->
deferred_send
))
{
if
(
!
g_queue_is_empty
(
client
->
deferred_send
))
{
client_defer_output
(
client
,
client
->
send_buf
,
client_defer_output
(
client
,
client
->
send_buf
,
client
->
send_buf_used
);
client
->
send_buf_used
);
if
(
client
_is_expired
(
client
))
if
(
client
->
IsExpired
(
))
return
;
return
;
/* try to flush the deferred buffers now; the current
/* try to flush the deferred buffers now; the current
...
@@ -216,10 +216,10 @@ static void
...
@@ -216,10 +216,10 @@ static void
client_write
(
Client
*
client
,
const
char
*
buffer
,
size_t
buflen
)
client_write
(
Client
*
client
,
const
char
*
buffer
,
size_t
buflen
)
{
{
/* if the client is going to be closed, do nothing */
/* if the client is going to be closed, do nothing */
if
(
client
_is_expired
(
client
))
if
(
client
->
IsExpired
(
))
return
;
return
;
while
(
buflen
>
0
&&
!
client
_is_expired
(
client
))
{
while
(
buflen
>
0
&&
!
client
->
IsExpired
(
))
{
size_t
copylen
;
size_t
copylen
;
assert
(
client
->
send_buf_used
<
sizeof
(
client
->
send_buf
));
assert
(
client
->
send_buf_used
<
sizeof
(
client
->
send_buf
));
...
...
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