summaryrefslogtreecommitdiff
path: root/comm
diff options
context:
space:
mode:
authorchatty2000-11-28 16:59:45 +0000
committerchatty2000-11-28 16:59:45 +0000
commit1766d5847c86de962190224b94ee71e208fc5862 (patch)
tree3395923559f5be363491f2cad80906ef2e33a631 /comm
parent7c44c466aeba17b04ad493c21ef388b844a84355 (diff)
downloadivy-league-1766d5847c86de962190224b94ee71e208fc5862.zip
ivy-league-1766d5847c86de962190224b94ee71e208fc5862.tar.gz
ivy-league-1766d5847c86de962190224b94ee71e208fc5862.tar.bz2
ivy-league-1766d5847c86de962190224b94ee71e208fc5862.tar.xz
Archiving of a file that was born dead
Diffstat (limited to 'comm')
-rwxr-xr-xcomm/essai13
-rw-r--r--comm/test.cc122
2 files changed, 135 insertions, 0 deletions
diff --git a/comm/essai b/comm/essai
new file mode 100755
index 0000000..afafb7f
--- /dev/null
+++ b/comm/essai
@@ -0,0 +1,13 @@
+client toto;
+
+request CreateStageReq {
+ long StageID -> lword;
+ const char* L -> CcuString;
+ int T -> lword;
+ int R -> lword;
+ int B -> lword;
+ CreateStageReq (StageID, L, T, R, B);
+ getters (L, T);
+ setters (L, T);
+};
+
diff --git a/comm/test.cc b/comm/test.cc
new file mode 100644
index 0000000..a6dfabf
--- /dev/null
+++ b/comm/test.cc
@@ -0,0 +1,122 @@
+#include "uch.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define TESTMSG
+
+#ifdef TESTMSG
+class MyRemoteAgent : public UchRemoteAgent {
+public:
+ MyRemoteAgent (UchAgent* a, UchChannel* ch) : UchRemoteAgent (a, ch) {}
+ ~MyRemoteAgent () {}
+bool NewMessage (UchMsgBuffer&, bool);
+};
+
+class MyAgent : public UchAgent {
+public:
+ MyAgent (UchAddress* a) : UchAgent (a) {}
+ ~MyAgent () {}
+UchRemoteAgent* HandleNew (UchChannel* ch) { return new MyRemoteAgent (this, ch); }
+};
+
+class MyMsg : public UchMessage {
+ CcuString S1;
+ CcuString S2;
+
+public:
+ MyMsg (const char* s1, const char* s2) : UchMessage (), S1 (s1), S2 (s2) {}
+ MyMsg () : UchMessage (), S1 ("S1"), S2 ("S2") {}
+ ~MyMsg () {}
+ void ReadFrom (UchMsgBuffer&, lword);
+ void WriteTo (UchMsgBuffer&);
+ void Dump () { printf ("[%s] [%s]\n", (const char*) S1, (const char*) S2); }
+};
+
+bool
+MyRemoteAgent :: NewMessage (UchMsgBuffer& b, bool)
+{
+ MyMsg m;
+ b.Get (m);
+ m.Dump ();
+ return true;
+}
+
+void
+MyMsg :: WriteTo (UchMsgBuffer& b)
+{
+ b << S1 << S2;
+}
+
+void
+MyMsg :: ReadFrom (UchMsgBuffer& b, lword len)
+{
+ b >> S1 >> S2;
+}
+
+#endif
+
+UchAgent* A;
+UchPortServer* PS;
+const char* BUF;
+
+int
+fMatch (const char* match, lword host, sword port, const char*)
+{
+ printf ("0x%lx:%d -> %s\n", host, port, match);
+ UchInetAddress* addr = new UchInetAddress (host == UchInetAddress::LoopBack ()
+ ? LOOPBACK : host, port);
+ UchRemoteAgent* ra = A->Contact (addr);
+ if (ra) {
+ printf ("joined\n");
+#ifdef TESTMSG
+ MyMsg m ("hello", "world");
+ ra->Send (m);
+#endif
+ } else {
+ printf ("connection failed\n");
+ delete addr;
+ }
+ return 1;
+}
+
+void
+fQuit (int, int)
+{
+ printf ("quit\n");
+ PS->Remove (BUF, *(UchInetAddress*) A->BoundTo ());
+ exit (0);
+}
+
+void
+fTick (Millisecond t)
+{
+ printf ("%d\n", t);
+}
+
+main (int argc, char** argv)
+{
+ const char* id = argc > 1 ? argv [1] : "";
+ UchInetAddress addr (ANYADDR);
+#ifdef TESTMSG
+ MyAgent a (&addr);
+#else
+ UchAgent a (&addr);
+#endif
+ if (a.Setup ()) {
+ A = &a;
+ UchPortServer ps ("portserv");
+ PS = &ps;
+ ps.Match ("portserv:chatty", fMatch);
+ char buf [64];
+ strcpy (buf, "%s:%u:test");
+ strcat (buf, id);
+ BUF = buf;
+ printf ("registering as %s\n", buf);
+ ps.Register (buf, *(UchInetAddress*) a.BoundTo ());
+ UchSignalHandler h (*a.GetMultiplexer (), SigHup, fQuit);
+// UchTimeOut to (*a.GetMultiplexer (), 1000, fTick);
+ a.Run ();
+ ps.Remove (buf, *(UchInetAddress*) a.BoundTo ());
+ }
+}