Styx over HTTP
StyxをHTTPに乗せてしまう実装をみつけた→http://code.google.com/p/limbo-machine/
- クライアント: Javascript。エンコードしたStyxメッセージをXMLHttpRequest()で投げる。
- ゲートウェイ: Apacheモジュール。クライアントのメッセージをデコードしてInfernoへ中継。
- サーバ: Inferno。
という仕組み。サーバへの接続はこんな感じでやってる。(一部抜粋)
--styx-fs.js StyxFS.prototype.mount = function(user, aname) { this.styx.version(); var qid = this.styx.attach(1, user, aname); this.root = new Resource(aname, 1, qid); return this.root; } --styx-protocol.js Styx.prototype.attach = function(fid, user, aname) { var tAttach = new Message([], MessageType.Tattach, this.tag++); tAttach.add32(fid); tAttach.add32(NOFID); tAttach.addString(user); tAttach.addString(aname); tAttach.adjustSize(); var rAttach = this.conn.tx(tAttach); var e = getError(MessageType.Rattach, rAttach); if (e == null) return new Qid(7, rAttach); this.onerror(e); return null; } --connection.js Connection.prototype.tx = function(imsg) { this.req.open("POST", this.service, false); this.req.overrideMimeType("text/plain; charset=x-user-defined"); this.req.send(marshall(imsg.getBytes())); if (this.req.status > 299 || this.req.status < 200) return new Message([]); var omsg = new Message(unmarshall(this.req.responseText)); if (omsg.get32(0) != omsg.length()) this.onerror("message lengths do not match"); return omsg; }
早速テストしてみたいけど、まだ引越しの片付けが終わってないのでPCが用意できず。
既存のStyxサーバとWebアプリの"糊"としては有用かな。このやり方がメインになってしまうと鬱だけど。