From bef84ec5fda392a2025be99354dd93f32c686a41 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sat, 14 Nov 2009 15:27:27 +1100 Subject: [PATCH] testing channels and goroutines. --- src/benchcontroller.go | 31 +++++++++++++++++++++++++++++++ src/makeit | 4 +++- src/webconnector.go | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 62 insertions(+), 12 deletions(-) mode change 100755 => 100644 src/makeit diff --git a/src/benchcontroller.go b/src/benchcontroller.go index e69de29..579edcb 100644 --- a/src/benchcontroller.go +++ b/src/benchcontroller.go @@ -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 diff --git a/src/makeit b/src/makeit old mode 100755 new mode 100644 index d83b860..2916e16 --- a/src/makeit +++ b/src/makeit @@ -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 diff --git a/src/webconnector.go b/src/webconnector.go index eb81cc0..c64e0bd 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -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, "
\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()) + } } -- 1.7.0.4