I found subuser's state is ADIED in the 2st situation. So, I made a
patch(attached) to del user and subuser immediately after user left the
page.
Is this OK?
2010/7/29 ma liang <[email protected]>
> hi,
>
> I used the JSONP transport method. Is there any way delete the client
> closed subuser immediately?
>
> It seems that subuser can only be delete in check_timeout() now.
> I think subuser can be delete in the ape_disconnect() function:
>
> >> if (co->fd == ((subuser *)(co->attach))->client->fd) {
> >> }
>
> This happens on the following situation:
> 1, client closed the subuser(normarlly left the page).
> 2, user data has sent to the client by ape_sent().
>
> How can I distinguish them?
>
--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/
diff --git a/src/servers.c b/src/servers.c
index b7f8c53..ec6326b 100755
--- a/src/servers.c
+++ b/src/servers.c
@@ -54,6 +54,12 @@ static void ape_disconnect(ape_socket *co, acetables *g_ape)
if (co->fd == ((subuser *)(co->attach))->client->fd) {
+ if (((subuser *)(co->attach))->state == ALIVE) {
+ /*
+ * user left this page, so, del this subuser
+ */
+ ((subuser*)(co->attach))->idle = 0;
+ }
((subuser *)(co->attach))->headers.sent = 0;
((subuser *)(co->attach))->state = ADIED;
http_headers_free(((subuser *)(co->attach))->headers.content);
diff --git a/src/users.c b/src/users.c
index 0225e08..c3be51b 100755
--- a/src/users.c
+++ b/src/users.c
@@ -260,8 +260,16 @@ void check_timeout(acetables *g_ape, int *last)
subuser **n = &(list->subuser);
while (*n != NULL) {
if ((ctime - (*n)->idle) >= TIMEOUT_SEC) {
- delsubuser(n, g_ape);
- continue;
+ if (list->nsub <= 1) {
+ /*
+ * after delete the last subuser, list can't be access
+ */
+ delsubuser(n, g_ape);
+ break;
+ } else {
+ delsubuser(n, g_ape);
+ continue;
+ }
}
if ((*n)->state == ALIVE && (*n)->raw_pools.nraw && !(*n)->need_update) {
@@ -581,7 +589,8 @@ subuser *getsubuser(USERS *user, const char *channel)
void delsubuser(subuser **current, acetables *g_ape)
{
subuser *del = *current;
-
+ USERS *user = (*current)->user;
+
FIRE_EVENT_NONSTOP(delsubuser, del, g_ape);
((*current)->user->nsub)--;
@@ -602,7 +611,13 @@ void delsubuser(subuser **current, acetables *g_ape)
} else {
free(del);
}
-
+
+ /*
+ * If this is the last subuser, del the user
+ */
+ if (user->nsub <= 0) {
+ deluser(user, g_ape);
+ }
}
void clear_subusers(USERS *user, acetables *g_ape)