summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbjj <bjj>2005-09-29 18:46:17 (GMT)
committerbjj <bjj>2005-09-29 18:46:17 (GMT)
commit468c33fcc527c6b34d9201e906a2197439c07cab (patch)
treece1164649b0be27cbf95d220e9f22df81931c0ef
parente1ffdb2d47bd83bdf6bc6ef9e92ca646a4ba7e70 (diff)
downloadmoo-468c33fcc527c6b34d9201e906a2197439c07cab.zip
moo-468c33fcc527c6b34d9201e906a2197439c07cab.tar.gz
moo-468c33fcc527c6b34d9201e906a2197439c07cab.tar.bz2
moo-468c33fcc527c6b34d9201e906a2197439c07cab.tar.xz
Add third argument to open_network_connection() that associates a specific listener object with the new connection. This simplifies a lot of outbound connection management.WAIF.ROOT.3
-rw-r--r--net_multi.c7
-rw-r--r--network.h5
-rw-r--r--server.c52
3 files changed, 55 insertions, 9 deletions
diff --git a/net_multi.c b/net_multi.c
index 6608c2d..9e54c71 100644
--- a/net_multi.c
+++ b/net_multi.c
@@ -660,7 +660,7 @@ network_set_client_echo(network_handle nh, int is_on)
#ifdef OUTBOUND_NETWORK
enum error
-network_open_connection(Var arglist)
+network_open_connection(Var arglist, server_listener sl)
{
int rfd, wfd;
const char *local_name, *remote_name;
@@ -668,7 +668,7 @@ network_open_connection(Var arglist)
e = proto_open_connection(arglist, &rfd, &wfd, &local_name, &remote_name);
if (e == E_NONE)
- make_new_connection(null_server_listener, rfd, wfd,
+ make_new_connection(sl, rfd, wfd,
local_name, remote_name, 1);
return e;
@@ -700,6 +700,9 @@ char rcsid_net_multi[] = "$Id$";
/*
* $Log$
+ * Revision 1.5 2005/09/29 18:46:17 bjj
+ * Add third argument to open_network_connection() that associates a specific listener object with the new connection. This simplifies a lot of outbound connection management.
+ *
* Revision 1.4 2004/05/22 01:25:43 wrog
* merging in WROGUE changes (W_SRCIP, W_STARTUP, W_OOB)
*
diff --git a/network.h b/network.h
index 3a2660c..e2f03e3 100644
--- a/network.h
+++ b/network.h
@@ -191,7 +191,7 @@ extern int network_set_connection_option(network_handle nh,
#ifdef OUTBOUND_NETWORK
#include "structures.h"
-extern enum error network_open_connection(Var arglist);
+extern enum error network_open_connection(Var arglist, server_listener sl);
/* The given MOO arguments should be used as a
* specification of a remote network connection
* to be made. If the arguments are OK and the
@@ -246,6 +246,9 @@ extern void network_shutdown(void);
/*
* $Log$
+ * Revision 1.4 2005/09/29 18:46:18 bjj
+ * Add third argument to open_network_connection() that associates a specific listener object with the new connection. This simplifies a lot of outbound connection management.
+ *
* Revision 1.3 1998/12/14 13:18:36 nop
* Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims
*
diff --git a/server.c b/server.c
index 15cea1a..f7aa9c9 100644
--- a/server.c
+++ b/server.c
@@ -88,8 +88,7 @@ typedef struct slistener {
static slistener *all_slisteners = 0;
-server_listener null_server_listener =
-{0};
+server_listener null_server_listener = {0};
static void
free_shandle(shandle * h)
@@ -956,14 +955,14 @@ server_new_connection(server_listener sl, network_handle nh, int outbound)
h->connection_time = 0;
h->last_activity_time = time(0);
h->player = next_unconnected_player--;
- h->listener = outbound ? SYSTEM_OBJECT : l->oid;
+ h->listener = l ? l->oid : SYSTEM_OBJECT;
h->tasks = new_task_queue(h->player, h->listener);
h->disconnect_me = 0;
h->outbound = outbound;
h->binary = 0;
- h->print_messages = (!outbound && l->print_messages);
+ h->print_messages = l ? l->print_messages : !outbound;
- if (!outbound) {
+ if (l || !outbound) {
new_input_task(h->tasks, "", 0);
/*
* Suspend input at the network level until the above input task
@@ -1371,6 +1370,20 @@ bf_db_disk_size(Var arglist, Byte next, void *vdata, Objid progr)
return make_var_pack(v);
}
+#ifdef OUTBOUND_NETWORK
+static slistener *
+find_slistener_by_oid(Objid obj)
+{
+ slistener *l;
+
+ for (l = all_slisteners; l; l = l->next)
+ if (l->oid == obj)
+ return l;
+
+ return 0;
+}
+#endif /* OUTBOUND_NETWORK */
+
static package
bf_open_network_connection(Var arglist, Byte next, void *vdata, Objid progr)
{
@@ -1378,13 +1391,37 @@ bf_open_network_connection(Var arglist, Byte next, void *vdata, Objid progr)
Var r;
enum error e;
+ server_listener sl;
+ slistener l;
if (!is_wizard(progr)) {
free_var(arglist);
return make_error_pack(E_PERM);
}
- e = network_open_connection(arglist);
+ if (arglist.v.list[0].v.num == 3) {
+ Objid oid;
+
+ if (arglist.v.list[3].type != TYPE_OBJ) {
+ return make_error_pack(E_TYPE);
+ }
+ oid = arglist.v.list[3].v.obj;
+ arglist = listdelete(arglist, 3);
+
+ sl.ptr = find_slistener_by_oid(oid);
+ if (!sl.ptr) {
+ /* Create a temporary */
+ l.print_messages = 0;
+ l.name = "open_network_connection";
+ l.desc = zero;
+ l.oid = oid;
+ sl.ptr = &l;
+ }
+ } else {
+ sl.ptr = NULL;
+ }
+
+ e = network_open_connection(arglist, sl);
free_var(arglist);
if (e == E_NONE) {
/* The connection was successfully opened, implying that
@@ -1753,6 +1790,9 @@ char rcsid_server[] = "$Id$";
/*
* $Log$
+ * Revision 1.9 2005/09/29 18:46:18 bjj
+ * Add third argument to open_network_connection() that associates a specific listener object with the new connection. This simplifies a lot of outbound connection management.
+ *
* Revision 1.8 2004/05/25 07:28:55 wrog
* indentation fixes
*