sas Fri Dec 6 01:08:59 2002 EDT Modified files: /php4/ext/ircg ircg.c Log: added a hook-registration function similiar to irc_connect() for the write buffer. we register a callback for closed-conn notification and an async handler for write_buf_add completion, so that we can maintain proper reference counts. we also call the global IRCG init function only once. this proves to be successful all the time and even apachectl restart/graceful works beautifully now. Index: php4/ext/ircg/ircg.c diff -u php4/ext/ircg/ircg.c:1.156 php4/ext/ircg/ircg.c:1.157 --- php4/ext/ircg/ircg.c:1.156 Thu Dec 5 10:35:04 2002 +++ php4/ext/ircg/ircg.c Fri Dec 6 01:08:59 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.156 2002/12/05 15:35:04 sas Exp $ */ +/* $Id: ircg.c,v 1.157 2002/12/06 06:08:59 sas Exp $ */ /* {{{ includes */ @@ -1047,11 +1047,24 @@ } /* }}} */ -static void wbuf_dead(irc_write_buf *p, void *data) +static void wbuf_closed_conn(irc_write_buf *p, void *data) { irc_disconnect(data, "Client connection terminated"); } +static void wbuf_add_complete(irc_write_buf *p, void *data) +{ + php_irconn_t *conn = data; + + put_irconn(data); +} + +static void wbuf_hooks(irc_write_buf *p, void *data) +{ + irc_write_buf_reg(p, WB_CLOSED_CONN, wbuf_closed_conn); + irc_write_buf_reg(p, WB_ADD_COMPLETE, wbuf_add_complete); +} + /* {{{ proto bool ircg_set_current(int connection) Sets current connection for output */ PHP_FUNCTION(ircg_set_current) @@ -1099,7 +1112,8 @@ irc_write_buf_add(&conn->wb, conn->fd); if (1) { #else - if (irc_write_buf_add_ex(&conn->wb, conn->fd, wbuf_dead, conn) == 0) { + if (irc_write_buf_add_ex(&conn->wb, conn->fd, wbuf_hooks, +conn) == 0) { + ircg_resource_get(conn->irconn_id); #endif php_ircg->irc_set_currents++; IRCGG(flush_data) = conn; @@ -2135,7 +2149,7 @@ } } -static pid_t initialized_from; +static int initialized; /* {{{ PHP_MINIT_FUNCTION */ @@ -2157,14 +2171,16 @@ } #endif - initialized_from = getpid(); + if (initialized == 0) { + initialized = 1; #if IRCG_API_VERSION >= 20021127 - ircg_setup_global("/tmp/ircg.lock", 0, setup); + ircg_setup_global("/tmp/ircg.lock", 0, setup); #else - setup(0); - setup(1); + setup(0); + setup(1); #endif + } ircg_hash_init(&php_ircg->h_fmt_msgs, 0, NULL, fmt_msgs_dtor, 1); #ifdef USE_FD2IRCONN @@ -2188,15 +2204,6 @@ ircg_hash_destroy(&h_fd2irconn); #endif - if (getpid() == initialized_from) { - ircg_hash_destroy(&php_ircg->h_fmt_msgs); - - IRCG_LOCK_DESTROY(php_ircg->fmt_msgs_lock); - IRCG_LOCK_DESTROY(php_ircg->error_msgs_lock); - - ircg_shutdown_global(); - } - return SUCCESS; } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php