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
bdeb8e14
Commit
bdeb8e14
authored
Aug 28, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: moved "expired" accesses into inline function
Hiding this flag allows us later to remove it easily.
parent
e0fd63ec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
13 deletions
+29
-13
client.c
src/client.c
+29
-13
No files found.
src/client.c
View file @
bdeb8e14
...
@@ -131,6 +131,16 @@ static void set_send_buf_size(struct client *client)
...
@@ -131,6 +131,16 @@ static void set_send_buf_size(struct client *client)
}
}
}
}
static
inline
int
client_is_expired
(
const
struct
client
*
client
)
{
return
client
->
expired
;
}
static
inline
void
client_set_expired
(
struct
client
*
client
)
{
client
->
expired
=
1
;
}
static
void
client_init
(
struct
client
*
client
,
int
fd
)
static
void
client_init
(
struct
client
*
client
,
int
fd
)
{
{
static
unsigned
int
next_client_num
;
static
unsigned
int
next_client_num
;
...
@@ -315,19 +325,25 @@ static int client_process_line(struct client *client)
...
@@ -315,19 +325,25 @@ static int client_process_line(struct client *client)
if
(
client
->
cmd_list_OK
>=
0
)
{
if
(
client
->
cmd_list_OK
>=
0
)
{
if
(
strcmp
(
line
,
CLIENT_LIST_MODE_END
)
==
0
)
{
if
(
strcmp
(
line
,
CLIENT_LIST_MODE_END
)
==
0
)
{
int
expired
;
DEBUG
(
"client %i: process command "
DEBUG
(
"client %i: process command "
"list
\n
"
,
client
->
num
);
"list
\n
"
,
client
->
num
);
ret
=
processListOfCommands
(
client
->
fd
,
ret
=
processListOfCommands
(
client
->
fd
,
&
(
client
->
permission
),
&
(
client
->
permission
),
&
(
client
->
expired
),
&
(
expired
),
client
->
cmd_list_OK
,
client
->
cmd_list_OK
,
client
->
cmd_list
);
client
->
cmd_list
);
DEBUG
(
"client %i: process command "
DEBUG
(
"client %i: process command "
"list returned %i
\n
"
,
client
->
num
,
ret
);
"list returned %i
\n
"
,
client
->
num
,
ret
);
if
(
expired
)
client_set_expired
(
client
);
if
(
ret
==
0
)
if
(
ret
==
0
)
commandSuccess
(
client
->
fd
);
commandSuccess
(
client
->
fd
);
else
if
(
ret
==
COMMAND_RETURN_CLOSE
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
client
->
expired
)
||
client
_is_expired
(
client
)
)
client_close
(
client
);
client_close
(
client
);
client_write_output
(
client
);
client_write_output
(
client
);
...
@@ -369,7 +385,7 @@ static int client_process_line(struct client *client)
...
@@ -369,7 +385,7 @@ static int client_process_line(struct client *client)
if
(
ret
==
0
)
if
(
ret
==
0
)
commandSuccess
(
client
->
fd
);
commandSuccess
(
client
->
fd
);
else
if
(
ret
==
COMMAND_RETURN_CLOSE
else
if
(
ret
==
COMMAND_RETURN_CLOSE
||
client
->
expired
)
{
||
client
_is_expired
(
client
)
)
{
client_close
(
client
);
client_close
(
client
);
}
}
client_write_output
(
client
);
client_write_output
(
client
);
...
@@ -395,7 +411,7 @@ static int client_input_received(struct client *client, int bytesRead)
...
@@ -395,7 +411,7 @@ static int client_input_received(struct client *client, int bytesRead)
*
(
buf_tail
-
1
)
=
'\0'
;
*
(
buf_tail
-
1
)
=
'\0'
;
}
}
ret
=
client_process_line
(
client
);
ret
=
client_process_line
(
client
);
if
(
client
->
expired
)
if
(
client
_is_expired
(
client
)
)
return
ret
;
return
ret
;
client
->
bufferPos
=
client
->
bufferLength
;
client
->
bufferPos
=
client
->
bufferLength
;
}
}
...
@@ -453,7 +469,7 @@ static void client_manager_register_read_fd(fd_set * fds, int *fdmax)
...
@@ -453,7 +469,7 @@ static void client_manager_register_read_fd(fd_set * fds, int *fdmax)
addListenSocketsToFdSet
(
fds
,
fdmax
);
addListenSocketsToFdSet
(
fds
,
fdmax
);
list_for_each_entry
(
client
,
&
clients
,
siblings
)
{
list_for_each_entry
(
client
,
&
clients
,
siblings
)
{
if
(
!
client
->
expired
&&
!
client
->
deferred_send
)
{
if
(
!
client
_is_expired
(
client
)
&&
!
client
->
deferred_send
)
{
FD_SET
(
client
->
fd
,
fds
);
FD_SET
(
client
->
fd
,
fds
);
if
(
*
fdmax
<
client
->
fd
)
if
(
*
fdmax
<
client
->
fd
)
*
fdmax
=
client
->
fd
;
*
fdmax
=
client
->
fd
;
...
@@ -468,7 +484,7 @@ static void client_manager_register_write_fd(fd_set * fds, int *fdmax)
...
@@ -468,7 +484,7 @@ static void client_manager_register_write_fd(fd_set * fds, int *fdmax)
FD_ZERO
(
fds
);
FD_ZERO
(
fds
);
list_for_each_entry
(
client
,
&
clients
,
siblings
)
{
list_for_each_entry
(
client
,
&
clients
,
siblings
)
{
if
(
client
->
fd
>=
0
&&
!
client
->
expired
if
(
client
->
fd
>=
0
&&
!
client
_is_expired
(
client
)
&&
client
->
deferred_send
)
{
&&
client
->
deferred_send
)
{
FD_SET
(
client
->
fd
,
fds
);
FD_SET
(
client
->
fd
,
fds
);
if
(
*
fdmax
<
client
->
fd
)
if
(
*
fdmax
<
client
->
fd
)
...
@@ -601,7 +617,7 @@ void client_manager_expire(void)
...
@@ -601,7 +617,7 @@ void client_manager_expire(void)
struct
client
*
client
,
*
n
;
struct
client
*
client
,
*
n
;
list_for_each_entry_safe
(
client
,
n
,
&
clients
,
siblings
)
{
list_for_each_entry_safe
(
client
,
n
,
&
clients
,
siblings
)
{
if
(
client
->
expired
)
{
if
(
client
_is_expired
(
client
)
)
{
DEBUG
(
"client %i: expired
\n
"
,
client
->
num
);
DEBUG
(
"client %i: expired
\n
"
,
client
->
num
);
client_close
(
client
);
client_close
(
client
);
}
else
if
(
time
(
NULL
)
-
client
->
lastTime
>
}
else
if
(
time
(
NULL
)
-
client
->
lastTime
>
...
@@ -648,7 +664,7 @@ static void client_write_deferred(struct client *client)
...
@@ -648,7 +664,7 @@ static void client_write_deferred(struct client *client)
/* cause client to close */
/* cause client to close */
DEBUG
(
"client %i: problems flushing buffer
\n
"
,
DEBUG
(
"client %i: problems flushing buffer
\n
"
,
client
->
num
);
client
->
num
);
client
->
expired
=
1
;
client
_set_expired
(
client
)
;
}
}
}
}
...
@@ -675,10 +691,10 @@ int client_print(int fd, const char *buffer, size_t buflen)
...
@@ -675,10 +691,10 @@ int client_print(int fd, const char *buffer, size_t buflen)
return
-
1
;
return
-
1
;
/* if fd isn't found or client is going to be closed, do nothing */
/* if fd isn't found or client is going to be closed, do nothing */
if
(
client
->
expired
)
if
(
client
_is_expired
(
client
)
)
return
0
;
return
0
;
while
(
buflen
>
0
&&
!
client
->
expired
)
{
while
(
buflen
>
0
&&
!
client
_is_expired
(
client
)
)
{
size_t
left
;
size_t
left
;
assert
(
client
->
send_buf_size
>=
client
->
send_buf_used
);
assert
(
client
->
send_buf_size
>=
client
->
send_buf_used
);
...
@@ -712,7 +728,7 @@ static void client_defer_output(struct client *client,
...
@@ -712,7 +728,7 @@ static void client_defer_output(struct client *client,
(
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
->
expired
=
1
;
client
_set_expired
(
client
)
;
return
;
return
;
}
}
...
@@ -734,7 +750,7 @@ static void client_write(struct client *client,
...
@@ -734,7 +750,7 @@ static void client_write(struct client *client,
client_defer_output
(
client
,
data
,
length
);
client_defer_output
(
client
,
data
,
length
);
}
else
{
}
else
{
DEBUG
(
"client %i: problems writing
\n
"
,
client
->
num
);
DEBUG
(
"client %i: problems writing
\n
"
,
client
->
num
);
client
->
expired
=
1
;
client
_set_expired
(
client
)
;
return
;
return
;
}
}
}
else
if
((
size_t
)
ret
<
client
->
send_buf_used
)
{
}
else
if
((
size_t
)
ret
<
client
->
send_buf_used
)
{
...
@@ -747,7 +763,7 @@ static void client_write(struct client *client,
...
@@ -747,7 +763,7 @@ static void client_write(struct client *client,
static
void
client_write_output
(
struct
client
*
client
)
static
void
client_write_output
(
struct
client
*
client
)
{
{
if
(
client
->
expired
||
!
client
->
send_buf_used
)
if
(
client
_is_expired
(
client
)
||
!
client
->
send_buf_used
)
return
;
return
;
if
(
client
->
deferred_send
!=
NULL
)
if
(
client
->
deferred_send
!=
NULL
)
...
...
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