[cvslog] (2002-09-21 07:40:27 UTC) Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Sat Sep 21 02:41:01 CST 2002


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2002-09-21 07:40:27 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/eggdrop/memutil.c lib/eggdrop/memutil.h lib/eggdrop/script.h
     lib/eggdrop/sockbuf.c lib/eggdrop/sockbuf.h
     modules/javascript/javascript.c modules/perlscript/perlscript.c
     modules/server/scriptcmds.c modules/server/servsock.c
     modules/tclscript/tclscript.c src/Makefile.am src/main.c

Added files:
     src/scriptnet.c

Log message:

* Added script support for network stuff

---------------------- diff included ----------------------
Index: eggdrop1.7/lib/eggdrop/memutil.c
diff -u eggdrop1.7/lib/eggdrop/memutil.c:1.9 eggdrop1.7/lib/eggdrop/memutil.c:1.10
--- eggdrop1.7/lib/eggdrop/memutil.c:1.9	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/lib/eggdrop/memutil.c	Sat Sep 21 02:40:16 2002
@@ -23,7 +23,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: memutil.c,v 1.9 2002/09/20 02:06:25 stdarg Exp $";
+static const char rcsid[] = "$Id: memutil.c,v 1.10 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -263,7 +263,7 @@
   }
 }
 
-void str_redup(char **str, char *newstr)
+void str_redup(char **str, const char *newstr)
 {
 	int len;
 
Index: eggdrop1.7/lib/eggdrop/memutil.h
diff -u eggdrop1.7/lib/eggdrop/memutil.h:1.10 eggdrop1.7/lib/eggdrop/memutil.h:1.11
--- eggdrop1.7/lib/eggdrop/memutil.h:1.10	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/lib/eggdrop/memutil.h	Sat Sep 21 02:40:16 2002
@@ -22,7 +22,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 /*
- * $Id: memutil.h,v 1.10 2002/09/20 02:06:25 stdarg Exp $
+ * $Id: memutil.h,v 1.11 2002/09/21 07:40:16 stdarg Exp $
  */
 
 #ifndef _EGG_MEMUTIL_H
@@ -66,7 +66,7 @@
 
 extern void rmspace(char *);
 
-extern void str_redup(char **str, char *newstr);
+extern void str_redup(char **str, const char *newstr);
 
 extern char *egg_msprintf(char *buf, int len, int *final_len, const char *format, ...);
 extern char *egg_mvsprintf(char *buf, int len, int *final_len, const char *format, va_list args);
Index: eggdrop1.7/lib/eggdrop/script.h
diff -u eggdrop1.7/lib/eggdrop/script.h:1.7 eggdrop1.7/lib/eggdrop/script.h:1.8
--- eggdrop1.7/lib/eggdrop/script.h:1.7	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/lib/eggdrop/script.h	Sat Sep 21 02:40:16 2002
@@ -21,7 +21,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 /*
- * $Id: script.h,v 1.7 2002/09/20 02:06:25 stdarg Exp $
+ * $Id: script.h,v 1.8 2002/09/21 07:40:16 stdarg Exp $
  */
 
 #ifndef _EGG_SCRIPT_H
@@ -46,6 +46,7 @@
 typedef struct byte_array_b {
 	unsigned char *bytes;
 	int len;
+	int do_free;
 } byte_array_t;
 
 /* Flags for commands. */
Index: eggdrop1.7/lib/eggdrop/sockbuf.c
diff -u eggdrop1.7/lib/eggdrop/sockbuf.c:1.1 eggdrop1.7/lib/eggdrop/sockbuf.c:1.2
--- eggdrop1.7/lib/eggdrop/sockbuf.c:1.1	Thu Sep 19 21:10:33 2002
+++ eggdrop1.7/lib/eggdrop/sockbuf.c	Sat Sep 21 02:40:16 2002
@@ -100,7 +100,6 @@
 	/* If it's not blocked already, write as much as we can. */
 	if (!(sbuf->flags & SOCKBUF_BLOCK)) {
 		nbytes = write(sbuf->sock, data, len);
-		if (nbytes == len) return(nbytes);
 		if (nbytes < 0) {
 			if (errno != EAGAIN) {
 				sockbuf_got_eof(idx, errno);
@@ -108,6 +107,8 @@
 			}
 			nbytes = 0;
 		}
+		sockbuf_on_written(idx, SOCKBUF_LEVEL_INTERNAL, nbytes, 0);
+		if (nbytes == len) return(nbytes);
 		sockbuf_block(idx);
 		data += nbytes;
 		len -= nbytes;
@@ -260,7 +261,7 @@
 	}
 
 	sbuf->flags &= ~SOCKBUF_CLIENT;
-	sockbuf_unblock(idx);
+	if (!sbuf->len) sockbuf_unblock(idx);
 	socket_get_peer_name(sbuf->sock, &peer_ip, &peer_port);
 
 	sockbuf_on_connect(idx, SOCKBUF_LEVEL_INTERNAL, peer_ip, peer_port);
@@ -444,6 +445,8 @@
 			sbuf->filters[i]->on_delete(sbuf->filter_client_data[i], idx);
 		}
 	}
+
+	if (sbuf->handler->on_delete) sbuf->handler->on_delete(sbuf->client_data, idx);
 
 	/* Close the file descriptor. */
 	if (sbuf->sock >= 0) close(sbuf->sock);
Index: eggdrop1.7/lib/eggdrop/sockbuf.h
diff -u eggdrop1.7/lib/eggdrop/sockbuf.h:1.1 eggdrop1.7/lib/eggdrop/sockbuf.h:1.2
--- eggdrop1.7/lib/eggdrop/sockbuf.h:1.1	Thu Sep 19 21:10:33 2002
+++ eggdrop1.7/lib/eggdrop/sockbuf.h	Sat Sep 21 02:40:16 2002
@@ -55,6 +55,9 @@
 	/* Data-level events. */
 	int (*on_read)(void *client_data, int idx, char *data, int len);
 	int (*on_written)(void *client_data, int idx, int len, int remaining);
+
+	/* Command-level events. */
+	int (*on_delete)(void *client_data, int idx);
 } sockbuf_handler_t;
 
 int sockbuf_write(int idx, const char *data, int len);
Index: eggdrop1.7/modules/javascript/javascript.c
diff -u eggdrop1.7/modules/javascript/javascript.c:1.11 eggdrop1.7/modules/javascript/javascript.c:1.12
--- eggdrop1.7/modules/javascript/javascript.c:1.11	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/modules/javascript/javascript.c	Sat Sep 21 02:40:16 2002
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: javascript.c,v 1.11 2002/09/20 02:06:25 stdarg Exp $";
+static const char rcsid[] = "$Id: javascript.c,v 1.12 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -423,8 +423,7 @@
 		case SCRIPT_UNSIGNED:
 			*result = INT_TO_JSVAL(((int) v->value));
 			break;
-		case SCRIPT_STRING:
-		case SCRIPT_BYTES: {
+		case SCRIPT_STRING: {
 			char *str = v->value;
 
 			if (!str) str = "";
@@ -432,6 +431,14 @@
 			*result = STRING_TO_JSVAL(JS_NewStringCopyN(cx, str, v->len));
 
 			if (v->value && v->type & SCRIPT_FREE) free((char *)v->value);
+			break;
+		}
+		case SCRIPT_BYTES: {
+			byte_array_t *bytes = v->value;
+
+			*result = STRING_TO_JSVAL(JS_NewStringCopyN(cx, bytes->bytes, bytes->len));
+			if (bytes->do_free) free(bytes->bytes);
+			if (v->type & SCRIPT_FREE) free(bytes);
 			break;
 		}
 		case SCRIPT_POINTER: {
Index: eggdrop1.7/modules/perlscript/perlscript.c
diff -u eggdrop1.7/modules/perlscript/perlscript.c:1.21 eggdrop1.7/modules/perlscript/perlscript.c:1.22
--- eggdrop1.7/modules/perlscript/perlscript.c:1.21	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/modules/perlscript/perlscript.c	Sat Sep 21 02:40:16 2002
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: perlscript.c,v 1.21 2002/09/20 02:06:25 stdarg Exp $";
+static const char rcsid[] = "$Id: perlscript.c,v 1.22 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -335,14 +335,21 @@
 		case SCRIPT_UNSIGNED:
 			result = newSViv((int) v->value);
 			break;
-		case SCRIPT_STRING:
-		case SCRIPT_BYTES: {
+		case SCRIPT_STRING: {
 			char *str = v->value;
 
 			if (!str) str = "";
 			if (v->len == -1) v->len = strlen(str);
 			result = newSVpv(str, v->len);
 			if (v->value && v->type & SCRIPT_FREE) free(v->value);
+			break;
+		}
+		case SCRIPT_BYTES: {
+			byte_array_t *bytes = v->value;
+
+			result = newSVpv(bytes->bytes, bytes->len);
+			if (bytes->do_free) free(bytes->bytes);
+			if (v->type & SCRIPT_FREE) free(bytes);
 			break;
 		}
 		case SCRIPT_POINTER: {
Index: eggdrop1.7/modules/server/scriptcmds.c
diff -u eggdrop1.7/modules/server/scriptcmds.c:1.10 eggdrop1.7/modules/server/scriptcmds.c:1.11
--- eggdrop1.7/modules/server/scriptcmds.c:1.10	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/modules/server/scriptcmds.c	Sat Sep 21 02:40:16 2002
@@ -22,7 +22,7 @@
 
 /* FIXME: #include mess
 #ifndef lint
-static const char rcsid[] = "$Id: scriptcmds.c,v 1.10 2002/09/20 02:06:25 stdarg Exp $";
+static const char rcsid[] = "$Id: scriptcmds.c,v 1.11 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 */
 
@@ -46,6 +46,7 @@
 extern current_server_t current_server;
 
 script_linked_var_t server_script_vars[] = {
+	{"", "servidx", &current_server.idx, SCRIPT_INTEGER | SCRIPT_READONLY, NULL},
 	{"", "server", &server_list_index, SCRIPT_INTEGER | SCRIPT_READONLY, NULL},
 	{"", "botnick", &current_server.nick, SCRIPT_STRING | SCRIPT_READONLY, NULL},
 	{0}
Index: eggdrop1.7/modules/server/servsock.c
diff -u eggdrop1.7/modules/server/servsock.c:1.1 eggdrop1.7/modules/server/servsock.c:1.2
--- eggdrop1.7/modules/server/servsock.c:1.1	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/modules/server/servsock.c	Sat Sep 21 02:40:16 2002
@@ -21,10 +21,13 @@
 
 static int server_on_read(void *client_data, int idx, char *text, int len);
 
+static int server_on_delete(void *client_data, int idx);
+
 static sockbuf_handler_t server_handler = {
 	"server",
 	server_on_connect, server_on_eof, NULL,
-	server_on_read, NULL
+	server_on_read, NULL,
+	server_on_delete
 };
 
 /**********************************************************************
@@ -157,5 +160,10 @@
 	text[-1] = 0;
 	check_bind(BT_raw, msg.cmd, NULL, prefix, msg.cmd, text);
 	free(prefix);
+	return(0);
+}
+
+static int server_on_delete(void *client_data, int idx)
+{
 	return(0);
 }
Index: eggdrop1.7/modules/tclscript/tclscript.c
diff -u eggdrop1.7/modules/tclscript/tclscript.c:1.20 eggdrop1.7/modules/tclscript/tclscript.c:1.21
--- eggdrop1.7/modules/tclscript/tclscript.c:1.20	Thu Sep 19 21:06:25 2002
+++ eggdrop1.7/modules/tclscript/tclscript.c	Sat Sep 21 02:40:16 2002
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: tclscript.c,v 1.20 2002/09/20 02:06:25 stdarg Exp $";
+static const char rcsid[] = "$Id: tclscript.c,v 1.21 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 
 #include "lib/eggdrop/module.h"
@@ -370,8 +370,7 @@
 		case SCRIPT_UNSIGNED:
 			result = Tcl_NewIntObj((int) v->value);
 			break;
-		case SCRIPT_STRING:
-		case SCRIPT_BYTES: {
+		case SCRIPT_STRING: {
 			char *str = v->value;
 
 			if (!str) str = "";
@@ -382,6 +381,17 @@
 			result = Tcl_NewStringObj(str, v->len);
 			#endif
 			if (v->value && v->type & SCRIPT_FREE) free(v->value);
+			break;
+		}
+		case SCRIPT_BYTES: {
+			byte_array_t *bytes = v->value;
+			#ifdef USE_BYTE_ARRAYS
+			result = Tcl_NewByteArrayObj(bytes->bytes, bytes->len);
+			#else
+			result = Tcl_NewStringObj(bytes->bytes, bytes->len);
+			#endif
+			if (bytes->do_free) free(bytes->bytes);
+			if (v->type & SCRIPT_FREE) free(bytes);
 			break;
 		}
 		case SCRIPT_POINTER: {
Index: eggdrop1.7/src/Makefile.am
diff -u eggdrop1.7/src/Makefile.am:1.28 eggdrop1.7/src/Makefile.am:1.29
--- eggdrop1.7/src/Makefile.am:1.28	Fri Sep 20 16:41:49 2002
+++ eggdrop1.7/src/Makefile.am	Sat Sep 21 02:40:16 2002
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.28 2002/09/20 21:41:49 stdarg Exp $
+# $Id: Makefile.am,v 1.29 2002/09/21 07:40:16 stdarg Exp $
 
 # FIXME: optionally allow a system wide install by ignoring the line below.
 bindir			= $(exec_prefix)
@@ -58,6 +58,7 @@
 			net.c \
 			net.h \
 			patch.h \
+			scriptnet.c \
 			tcl.c \
 			tcl.h \
 			tcldcc.c \
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.122 eggdrop1.7/src/main.c:1.123
--- eggdrop1.7/src/main.c:1.122	Fri Sep 20 16:41:49 2002
+++ eggdrop1.7/src/main.c	Sat Sep 21 02:40:16 2002
@@ -30,7 +30,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: main.c,v 1.122 2002/09/20 21:41:49 stdarg Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.123 2002/09/21 07:40:16 stdarg Exp $";
 #endif
 
 #include "main.h"
@@ -452,6 +452,7 @@
 
 int init_userent(), init_net(),
  init_tcl(int, char **);
+void script_net_init();
 void dns_init();
 void binds_init();
 void dcc_init();
@@ -574,6 +575,7 @@
 
   egg = eggdrop_new();
   script_init();
+  script_net_init();
   binds_init();
   modules_init();
   logfile_init();
Index: eggdrop1.7/src/scriptnet.c
diff -u /dev/null eggdrop1.7/src/scriptnet.c:1.1
--- /dev/null	Sat Sep 21 02:40:27 2002
+++ eggdrop1.7/src/scriptnet.c	Sat Sep 21 02:40:16 2002
@@ -0,0 +1,278 @@
+/*
+ * scriptnet.c -- script support for network functions
+ *
+ */
+
+#include <stdio.h> /* NULL */
+#include <eggdrop/eggdrop.h>
+
+/* From main.c */
+extern egg_timeval_t egg_timeval_now;
+
+typedef struct script_net_info {
+	struct script_net_info *prev, *next;
+	int idx;
+	char *peer_ip, *peer_host, *peer_ident;
+	int peer_port;
+	script_callback_t *on_connect, *on_eof, *on_newclient;
+	script_callback_t *on_read, *on_written;
+	script_callback_t *on_delete;
+
+	/* Some stats about this connection. */
+	egg_timeval_t connected_at;
+	egg_timeval_t last_input_at;
+	egg_timeval_t last_output_at;
+
+	unsigned int bytes_in, bytes_out;
+	unsigned int bytes_left;
+} script_net_info_t;
+
+/* We keep a list of script-controlled sockbufs. */
+static script_net_info_t *script_net_info_head = NULL;
+
+static void script_net_info_add(script_net_info_t *info);
+static void script_net_info_remove(script_net_info_t *info);
+
+/* Script interface prototypes. */
+int script_net_takeover(int idx);
+static int script_net_open(const char *host, int port, int timeout);
+static int script_net_close(int idx);
+static int script_net_write(int idx, const char *text, int len);
+static int script_net_linemode(int idx, int onoff);
+static int script_net_handler(int idx, const char *event, script_callback_t *handler);
+static int script_net_info(script_var_t *retval, int idx, char *what);
+
+static script_command_t script_cmds[] = {
+	{"", "net_takeover", script_net_takeover, NULL, 1, "i", "idx", SCRIPT_INTEGER, 0},
+	{"", "net_open", script_net_open, NULL, 2, "sii", "host port ?timeout?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
+	{"", "net_close", script_net_close, NULL, 1, "i", "idx", SCRIPT_INTEGER, 0},
+	{"", "net_write", script_net_write, NULL, 2, "isi", "idx text ?len?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
+	{"", "net_handler", script_net_handler, NULL, 2, "isc", "idx event callback", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
+	{"", "net_linemode", script_net_linemode, NULL, 2, "ii", "idx on-off", SCRIPT_INTEGER, 0},
+	{"", "net_info", script_net_info, NULL, 2, "is", "idx what", 0, SCRIPT_PASS_RETVAL},
+	{0}
+};
+
+
+/* Sockbuf handler prototypes. */
+static int on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
+static int on_eof(void *client_data, int idx, int err, const char *errmsg);
+static int on_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port);
+static int on_read(void *client_data, int idx, char *data, int len);
+static int on_written(void *client_data, int idx, int len, int remaining);
+static int on_delete(void *client_data, int idx);
+
+static sockbuf_handler_t sock_handler = {
+	"script",
+	on_connect, on_eof, on_newclient,
+	on_read, on_written,
+	on_delete
+};
+
+/* Create script commands. */
+void script_net_init()
+{
+	script_create_commands(script_cmds);
+}
+
+/* Put an idx under script control. */
+int script_net_takeover(int idx)
+{
+	script_net_info_t *info;
+
+	info = calloc(1, sizeof(*info));
+	info->idx = idx;
+	script_net_info_add(info);
+	sockbuf_set_handler(info->idx, &sock_handler, info);
+	return(0);
+}
+
+/* Look up info based on the idx. */
+static script_net_info_t *script_net_info_lookup(int idx)
+{
+	script_net_info_t *info;
+
+	for (info = script_net_info_head; info; info = info->next) {
+		if (info->idx == idx) break;
+	}
+	return(info);
+}
+
+static void script_net_info_add(script_net_info_t *info)
+{
+	info->next = script_net_info_head;
+	info->prev = NULL;
+	if (script_net_info_head) script_net_info_head->prev = info;
+	script_net_info_head = info;
+}
+
+static void script_net_info_remove(script_net_info_t *info)
+{
+	if (info->prev) info->prev->next = info->next;
+	else script_net_info_head = info->next;
+
+	if (info->next) info->next->prev = info->prev;
+}
+
+/* Script interface functions. */
+static int script_net_open(const char *host, int port, int timeout)
+{
+	int idx;
+
+	idx = egg_connect(host, port, timeout);
+	script_net_takeover(idx);
+	return(idx);
+}
+
+static int script_net_close(int idx)
+{
+	return sockbuf_delete(idx);
+}
+
+static int script_net_write(int idx, const char *text, int len)
+{
+	if (len <= 0) len = strlen(text);
+
+	return sockbuf_write(idx, text, len);
+}
+
+static int script_net_linemode(int idx, int onoff)
+{
+	if (onoff) linemode_on(idx);
+	else linemode_off(idx);
+	return(0);
+}
+
+static int script_net_handler(int idx, const char *event, script_callback_t *callback)
+{
+	script_net_info_t *info = script_net_info_lookup(idx);
+	script_callback_t **replace = NULL;
+	const char *newsyntax;
+
+	/* Not a script-controlled idx. */
+	if (!info) return(-1);
+
+	if (!strcasecmp(event, "connect")) {
+		replace = &info->on_connect;
+		newsyntax = "isi";
+	}
+	else if (!strcasecmp(event, "eof")) {
+		replace = &info->on_eof;
+		newsyntax = "iis";
+	}
+	else if (!strcasecmp(event, "newclient")) {
+		replace = &info->on_newclient;
+		newsyntax = "iisi";
+	}
+	else if (!strcasecmp(event, "read")) {
+		replace = &info->on_read;
+		newsyntax = "ibi";
+	}
+	else if (!strcasecmp(event, "written")) {
+		replace = &info->on_written;
+		newsyntax = "iii";
+	}
+	else if (!strcasecmp(event, "delete")) {
+		replace = &info->on_delete;
+		newsyntax = "i";
+	}
+	else {
+		/* Invalid event type. */
+		return(-2);
+	}
+
+	if (*replace) (*replace)->del(*replace);
+	if (callback) callback->syntax = strdup(newsyntax);
+	*replace = callback;
+	return(0);
+}
+
+static int script_net_info(script_var_t *retval, int idx, char *what)
+{
+	script_net_info_t *info = script_net_info_lookup(idx);
+
+	retval->type = SCRIPT_INTEGER;
+	if (!info) return(0);
+
+	if (!strcasecmp(what, "bytesleft")) retval->value = (void *)info->bytes_left;
+	return(0);
+}
+
+/* Sockbuf handler functions. */
+static int on_connect(void *client_data, int idx, const char *peer_ip, int peer_port)
+{
+	script_net_info_t *info = client_data;
+
+	str_redup(&info->peer_ip, peer_ip);
+	info->peer_port = peer_port;
+	memcpy(&info->connected_at, &egg_timeval_now, sizeof(egg_timeval_now));
+
+	if (info->on_connect) info->on_connect->callback(info->on_connect, idx, peer_ip, peer_port);
+	return(0);
+}
+
+static int on_eof(void *client_data, int idx, int err, const char *errmsg)
+{
+	script_net_info_t *info = client_data;
+
+	if (info->on_eof) info->on_eof->callback(info->on_eof, idx, err, errmsg);
+	if (sockbuf_isvalid(idx)) sockbuf_delete(idx);
+	return(0);
+}
+
+static int on_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port)
+{
+	script_net_info_t *info = client_data;
+
+	if (info->on_newclient) info->on_newclient->callback(info->on_newclient, idx, newidx, peer_ip, peer_port);
+	return(0);
+}
+
+static int on_read(void *client_data, int idx, char *data, int len)
+{
+	script_net_info_t *info = client_data;
+	byte_array_t bytes;
+
+	info->bytes_in += len;
+	memcpy(&info->last_input_at, &egg_timeval_now, sizeof(egg_timeval_now));
+
+	if (info->on_read) {
+		bytes.bytes = data;
+		bytes.len = len;
+		bytes.do_free = 0;
+		info->on_read->callback(info->on_read, idx, &bytes, len);
+	}
+	return(0);
+}
+
+static int on_written(void *client_data, int idx, int len, int remaining)
+{
+	script_net_info_t *info = client_data;
+
+	memcpy(&info->last_output_at, &egg_timeval_now, sizeof(egg_timeval_now));
+
+	info->bytes_out += len;
+	info->bytes_left = remaining;
+
+	if (info->on_written) info->on_written->callback(info->on_written, idx, len, remaining);
+	return(0);
+}
+
+static int on_delete(void *client_data, int idx)
+{
+	script_net_info_t *info = client_data;
+
+	if (info->on_connect) info->on_connect->del(info->on_connect);
+	if (info->on_eof) info->on_eof->del(info->on_eof);
+	if (info->on_newclient) info->on_newclient->del(info->on_newclient);
+	if (info->on_read) info->on_read->del(info->on_read);
+	if (info->on_written) info->on_written->del(info->on_written);
+
+	if (info->on_delete) {
+		info->on_delete->callback(info->on_delete, idx);
+		info->on_delete->del(info->on_delete);
+	}
+	script_net_info_remove(info);
+	free(info);
+	return(0);
+}
----------------------- End of diff -----------------------



More information about the Changes mailing list