sas Tue Dec 3 09:14:34 2002 EDT Modified files: /php4/ext/ircg ircg.c php_ircg_private.h Log: further work on stabilizing concurrent IRCG accesses Index: php4/ext/ircg/ircg.c diff -u php4/ext/ircg/ircg.c:1.150 php4/ext/ircg/ircg.c:1.151 --- php4/ext/ircg/ircg.c:1.150 Tue Dec 3 05:13:36 2002 +++ php4/ext/ircg/ircg.c Tue Dec 3 09:14:33 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.150 2002/12/03 10:13:36 sas Exp $ */ +/* $Id: ircg.c,v 1.151 2002/12/03 14:14:33 sas Exp $ */ /* {{{ includes */ @@ -67,6 +67,15 @@ #include "ext/standard/php_smart_str.h" #include "php_ircg_private.h" +#ifdef USE_IRCONN_MANAGEMENT +static HashTable h_irconn; /* Integer IDs to php_irconn_t * */ +static int irconn_id; +#endif + +#ifdef USE_FD2IRCONN +static HashTable h_fd2irconn; /* fd's to Integer IDs */ +#endif + struct php_ircg_global *php_ircg; /* initialized in the IRCG control process, so that we can avoid locking */ @@ -181,7 +190,10 @@ struct sockaddr_in sin; /* address of stream conn */ #endif php_fmt_msgs_t *fmt_msgs; +#if IRCG_API_VERSION < 20021127 irc_write_buf wb; +#endif + irc_write_buf *wbp; ircg_hash_table ctcp_msgs; #ifdef IRCG_PENDING_URL @@ -352,7 +364,7 @@ shutdown(conn->fd, 2); #endif if (conn->file_fd == -1 && conn->fd >= 0) - irc_write_buf_del(&conn->wb); + irc_write_buf_del(conn->wbp); } if (conn->file_fd != -1) { smart_str m = {0}; @@ -381,6 +393,7 @@ } #endif + memset(conn, 0xbb, sizeof *conn); IRCG_SHARED_FREE(conn); } /* }}} */ @@ -453,7 +466,7 @@ goto done; default: #if IRCG_API_VERSION - 0 >= 20010601 - if ((n = irc_write_buf_append_ex(&conn->wb, msg, 0))) { + if ((n = irc_write_buf_append_ex(conn->wbp, msg, 0))) { const char *reason; #if IRCG_API_VERSION - 0 >= 20020308 @@ -481,10 +494,10 @@ } return; #elif IRCG_API_VERSION - 0 >= 20010302 - irc_write_buf_append_ex(&conn->wb, msg, 0); /* no copy */ + irc_write_buf_append_ex(conn->wbp, msg, 0); /* no copy */ return; #else - irc_write_buf_append(&conn->wb, msg); + irc_write_buf_append(conn->wbp, msg); goto done; #endif break; @@ -499,7 +512,7 @@ { msg_accum_send(conn, msg); if (conn->fd >= 0 && conn->file_fd == -1) - irc_write_buf_flush(&conn->wb); + irc_write_buf_flush(conn->wbp); } static void msg_replay_buffer(php_irconn_t *conn) @@ -882,8 +895,8 @@ smart_str tmp = {0}; smart_str_setl(&tmp, " ", 2); - irc_write_buf_append_ex(&conn->wb, &tmp, 1); - irc_write_buf_flush(&conn->wb); + irc_write_buf_append_ex(conn->wbp, &tmp, 1); + irc_write_buf_flush(conn->wbp); } else if (conn->file_fd < 0 && (php_ircg_now() - conn->login) > WINDOW_TIMEOUT) { char buf[1024]; @@ -1037,6 +1050,13 @@ } /* }}} */ +static void wbuf_destruct(irc_write_buf *p) +{ + php_ircg->irc_wbuf_destructs++; + memset(p, 0xaa, sizeof(*p)); + IRCG_SHARED_FREE(p); +} + /* {{{ proto bool ircg_set_current(int connection) Sets current connection for output */ PHP_FUNCTION(ircg_set_current) @@ -1059,11 +1079,9 @@ ircg_hash_index_del(&h_fd2irconn, conn->fd); #endif if (conn->file_fd == -1) - irc_write_buf_del(&conn->wb); + irc_write_buf_del(conn->wbp); conn->fd = -1; } - - php_ircg->irc_set_currents++; if (php_ircg_register_with_sapi(&conn->fd TSRMLS_CC) #ifdef USE_FD2IRCONN @@ -1081,7 +1099,15 @@ sizeof(int), NULL); #endif if (conn->file_fd == -1 && conn->fd >= 0) { - irc_write_buf_add(&conn->wb, conn->fd); +#if IRCG_API_VERSION < 20021127 + conn->wbp = &conn->wb; + irc_write_buf_add(conn->wbp, conn->fd); +#else + conn->wbp = IRCG_SHARED_ALLOC(sizeof(irc_write_buf)); + irc_write_buf_add_ex(conn->wbp, conn->fd, wbuf_destruct); +#endif + + php_ircg->irc_set_currents++; IRCGG(flush_data) = conn; } RETVAL_TRUE; @@ -2056,7 +2082,7 @@ #endif msg_replay_buffer(conn); - irc_write_buf_flush(&conn->wb); + irc_write_buf_flush(conn->wbp); } return SUCCESS; @@ -2183,10 +2209,12 @@ php_info_print_table_row(2, "Tokenizer invocations", buf); sprintf(buf, "%lu", php_ircg->irc_connects); php_info_print_table_row(2, "IRC connects", buf); - sprintf(buf, "%lu", php_ircg->irc_set_currents); - php_info_print_table_row(2, "Persistent HTTP connections", buf); sprintf(buf, "%lu", php_ircg->irc_quit_handlers); php_info_print_table_row(2, "Terminated IRC connections", buf); + sprintf(buf, "%lu", php_ircg->irc_set_currents); + php_info_print_table_row(2, "Persistent HTTP connections", buf); + sprintf(buf, "%lu", php_ircg->irc_wbuf_destructs); + php_info_print_table_row(2, "Write buffer destructs", buf); php_info_print_table_end(); } /* }}} */ Index: php4/ext/ircg/php_ircg_private.h diff -u php4/ext/ircg/php_ircg_private.h:1.1 php4/ext/ircg/php_ircg_private.h:1.2 --- php4/ext/ircg/php_ircg_private.h:1.1 Tue Dec 3 05:13:36 2002 +++ php4/ext/ircg/php_ircg_private.h Tue Dec 3 09:14:33 2002 @@ -8,12 +8,7 @@ #if IRCG_API_VERSION < 20021127 #define USE_IRCONN_MANAGEMENT -static HashTable h_irconn; /* Integer IDs to php_irconn_t * */ -static int irconn_id; - #define USE_FD2IRCONN -static HashTable h_fd2irconn; /* fd's to Integer IDs */ - /* provide dummy definitions */ #include "php_ircg_hash.h" @@ -32,7 +27,8 @@ /* these just serve statistical/entertainment purposes */ unsigned long irc_connects, irc_set_currents, irc_quit_handlers, - exec_fmt_msgs, exec_token_compiler; + exec_fmt_msgs, exec_token_compiler, + irc_wbuf_destructs; unsigned long cache_hits, cache_misses;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php