testing channels and goroutines.
authorPaul J R <me@pjr.cc>
Sat, 14 Nov 2009 04:27:27 +0000 (15:27 +1100)
committerPaul J R <me@pjr.cc>
Sat, 14 Nov 2009 04:27:27 +0000 (15:27 +1100)
src/benchcontroller.go
src/makeit [changed mode: 0755->0644]
src/webconnector.go

index e69de29..579edcb 100644 (file)
@@ -0,0 +1,31 @@
+// the benchmark controller
+
+package benchcontroller
+
+import (
+       //"./dbconnector";
+       "os";
+       "time";
+)
+
+type BenchControllerConfig struct {
+       id int;
+}
+
+func CreateController()(contConfig *BenchControllerConfig)
+{
+       bcConfig := new(BenchControllerConfig);
+       
+       return bcConfig;
+}
+
+func MainLoop(conf *BenchControllerConfig, commInChan chan int, commOutChan chan int)
+{
+       for {
+               time.Sleep(1000000000);
+               i := <-commInChan;
+               os.Stdout.WriteString("got a coms\n");
+               commOutChan <- i;
+               os.Stdout.WriteString("Send some back\n");
+       }
+}
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index d83b860..2916e16
@@ -7,7 +7,9 @@ gopack grc dbibridge.a _dbibridge_.8 dbibridge.cgo3.8
 #cp dbibridge.a /export/src/external/golang//pkg/linux_386/dbibridge.a
 gcc -m32 -fPIC -O2 -o dbibridge.cgo4.o -c  dbibridge.cgo4.c
 gcc -m32 -shared -L`pwd` -lpthread -lm -ldbi -o dbibridge_dbibridge.so dbibridge.cgo4.o 
-#cp dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge_dbibridge.so
+cp dbibridge_dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge_dbibridge.so
+
+8g benchcontroller.go
 
 
 
index eb81cc0..c64e0bd 100644 (file)
@@ -6,27 +6,44 @@ package main
 import (
        "http";
        "io";
-       "./dbibridge";
+       //"./dbibridge";
+       "./benchcontroller";
+       "fmt";
 )
 
+var comin chan int;
+var comout chan int;
+
 // hello world, the web server
 func HelloServer(c *http.Conn, req *http.Request) {
+       comout <- 1;
        io.WriteString(c, "<html><form method=post><input type=\"input\"><input type=\"submit\" name=\"go\" value=\"go\"></html>\n");
+       
+       // fucking go, i just wanna consume the incoming data, but it forces me to do something with it... cunt of a language
+       k := <- comin;
+       fmt.Printf("%d\n", k);
 }
 
 func main() {
 
-       var Dbconn *dbibridge.DBIConnection;
+       //var Dbconn *dbibridge.DBIConnection;
+       
+       //Dbconn = dbibridge.DBICreate();
+       
+       //dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm");
+       //dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)");
+       //dbibridge.DBIDisconnect(Dbconn);
+       
+       comin = make(chan int);
+       comout = make(chan int);
        
-       Dbconn = dbibridge.DBICreate();
+       bc := benchcontroller.CreateController();
+       go benchcontroller.MainLoop(bc, comout, comin);
        
-       dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm");
-       dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)");
-       dbibridge.DBIDisconnect(Dbconn);
-       //http.Handle("/hello", http.HandlerFunc(HelloServer));
-       //err := http.ListenAndServe(":12345", nil);
-       //if err != nil {
-               ////panic("ListenAndServe: ", err.String())
-       //}
+       http.Handle("/hello", http.HandlerFunc(HelloServer));
+       err := http.ListenAndServe(":12345", nil);
+       if err != nil {
+               panic("ListenAndServe: ", err.String())
+       }
 
 }