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
d01d1cca
Commit
d01d1cca
authored
Apr 25, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: use GTimer to track timeouts
parent
616dc9d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
client.c
src/client.c
+14
-7
No files found.
src/client.c
View file @
d01d1cca
...
...
@@ -83,7 +83,11 @@ struct client {
/** the uid of the client process, or -1 if unknown */
int
uid
;
time_t
lastTime
;
/**
* How long since the last activity from this client?
*/
GTimer
*
last_activity
;
GSList
*
cmd_list
;
/* for when in list mode */
int
cmd_list_OK
;
/* print OK after each command execution */
size_t
cmd_list_size
;
/* mem cmd_list consumes */
...
...
@@ -196,7 +200,6 @@ static void client_init(struct client *client, int fd)
client
->
input
=
fifo_buffer_new
(
4096
);
client
->
lastTime
=
time
(
NULL
);
client
->
cmd_list
=
NULL
;
client
->
deferred_send
=
g_queue_new
();
client
->
deferred_bytes
=
0
;
...
...
@@ -238,6 +241,8 @@ static void client_close(struct client *client)
client_set_expired
(
client
);
g_timer_destroy
(
client
->
last_activity
);
if
(
client
->
cmd_list
)
{
free_cmd_list
(
client
->
cmd_list
);
client
->
cmd_list
=
NULL
;
...
...
@@ -271,6 +276,8 @@ void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid)
client_init
(
client
,
fd
);
client
->
uid
=
uid
;
client
->
last_activity
=
g_timer_new
();
remote
=
sockaddr_to_string
(
sa
,
sa_length
,
NULL
);
g_log
(
G_LOG_DOMAIN
,
LOG_LEVEL_SECURE
,
"[%u] opened from %s"
,
client
->
num
,
remote
);
...
...
@@ -474,7 +481,7 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source,
return
false
;
}
client
->
lastTime
=
time
(
NULL
);
g_timer_start
(
client
->
last_activity
);
ret
=
client_read
(
client
);
switch
(
ret
)
{
...
...
@@ -525,7 +532,7 @@ client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
return
false
;
}
client
->
lastTime
=
time
(
NULL
);
g_timer_start
(
client
->
last_activity
);
if
(
g_queue_is_empty
(
client
->
deferred_send
))
{
/* done sending deferred buffers exist: schedule
...
...
@@ -589,7 +596,7 @@ client_check_expired_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
client_close
(
client
);
}
else
if
(
!
client
->
idle_waiting
&&
/* idle clients
never expire */
time
(
NULL
)
-
client
->
lastTime
>
(
int
)
g_timer_elapsed
(
client
->
last_activity
,
NULL
)
>
client_timeout
)
{
g_debug
(
"[%u] timeout"
,
client
->
num
);
client_close
(
client
);
...
...
@@ -671,7 +678,7 @@ static void client_write_deferred(struct client *client)
g_queue_pop_head
(
client
->
deferred_send
);
}
client
->
lastTime
=
time
(
NULL
);
g_timer_start
(
client
->
last_activity
);
}
if
(
g_queue_is_empty
(
client
->
deferred_send
))
{
...
...
@@ -860,7 +867,7 @@ client_idle_notify(struct client *client)
}
client_puts
(
client
,
"OK
\n
"
);
client
->
lastTime
=
time
(
NULL
);
g_timer_start
(
client
->
last_activity
);
}
static
void
...
...
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