summaryrefslogtreecommitdiffstats
path: root/hyper
diff options
context:
space:
mode:
Diffstat (limited to 'hyper')
-rw-r--r--hyper/process/main.go19
-rw-r--r--hyper/process/src/hyper/process/process.go13
-rw-r--r--hyper/sink/index.js13
3 files changed, 41 insertions, 4 deletions
diff --git a/hyper/process/main.go b/hyper/process/main.go
index ebeeb6d6..5420f681 100644
--- a/hyper/process/main.go
+++ b/hyper/process/main.go
@@ -6,6 +6,7 @@ import "http"
import "gorilla.googlecode.com/hg/gorilla/mux"
import "os"
import "fmt"
+import "bytes"
import "hyper/process"
@@ -47,13 +48,29 @@ func RetrieveProcess(res http.ResponseWriter, req *http.Request) {
}
}
+func FeedProcess(res http.ResponseWriter, req *http.Request) {
+ if p := proc[mux.Vars(req)["id"]]; p != nil {
+ body := make([]byte, 4096)
+ if _, err := req.Body.Read(body); err == nil {
+ body = bytes.TrimRight(body, string([]byte{0}))
+ p.Write(body)
+ //if err := p.Write(body); err == nil {
+ RespondJSON(res, true)
+ //}
+ }
+ } else {
+ res.WriteHeader(http.StatusNotFound)
+ }
+}
+
func main() {
// Gorilla
mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST")
mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET")
+ mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST")
- err := http.ListenAndServe(":8888", mux.DefaultRouter)
+ err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
diff --git a/hyper/process/src/hyper/process/process.go b/hyper/process/src/hyper/process/process.go
index a52197f0..18cf55fb 100644
--- a/hyper/process/src/hyper/process/process.go
+++ b/hyper/process/src/hyper/process/process.go
@@ -18,6 +18,7 @@ type Process struct {
process_stdout *os.File
process_stderr *os.File
id string
+ client http.Client
}
func (p *Process) Id() string {
@@ -99,18 +100,24 @@ func (hp *Process) Start() os.Error {
file.Close()
}
- go reader(hp.process_stdout)
- go reader(hp.process_stderr)
+ go hp.reader(hp.process_stdout, hp.Stdout)
+ go hp.reader(hp.process_stderr, hp.Stderr)
return nil
}
-func reader(file *os.File) {
+func (p *Process) reader(file *os.File, url string) {
var b []byte = make([]byte, 1024)
var err os.Error = nil
for err == nil {
var n int
n, err = file.Read(b)
fmt.Printf("data: %d, %s\n", n, b)
+
+ res, err := p.client.Post(url, "application/octet-stream", bytes.NewBuffer(b))
+ res = res
+ if err != nil {
+ fmt.Printf("EE: %s: %s\n", url, err)
+ }
}
}
diff --git a/hyper/sink/index.js b/hyper/sink/index.js
new file mode 100644
index 00000000..b556b88d
--- /dev/null
+++ b/hyper/sink/index.js
@@ -0,0 +1,13 @@
+require('http').createServer(function (req, res) {
+
+ req.on('data', function (data) {
+ require('util').puts(data);
+ });
+
+ req.on('end', function () {
+ res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 0});
+ res.end();
+ });
+}).listen(1337, '127.0.0.1', function () {
+ console.log('Running HyperSink at http://127.0.0.1:1337/');
+});