~ubuntu-branches/ubuntu/oneiric/haxe/oneiric

« back to all changes in this revision

Viewing changes to haxe/std/haxe/remoting/SyncSocketConnection.hx

  • Committer: Bazaar Package Importer
  • Author(s): Jens Peter Secher
  • Date: 2009-03-18 23:09:50 UTC
  • mfrom: (3.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090318230950-pgfuxg2ucolps74t
Tags: 1:2.2-2
* Use ocamlfind to locate and use the libraries xml-light and extlib
  which already exist in Debian as separate packages.
  (Closes: #519630)
* Fixed compile error with camlp4 3.11, thanks to Stéphane Glondu.
  (Closes: #519627)
* Use quilt instead of dpatch for patches, and describe how to use
  quilt in Debian.source (thanks to Russ Allbery).
* Added a Vcs-Hg control filed to indicate the location of the public
  repository.
* Bumped Standards-Version to 3.8.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2007, The haXe Project Contributors
 
3
 * All rights reserved.
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 *   - Redistributions of source code must retain the above copyright
 
8
 *     notice, this list of conditions and the following disclaimer.
 
9
 *   - Redistributions in binary form must reproduce the above copyright
 
10
 *     notice, this list of conditions and the following disclaimer in the
 
11
 *     documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
16
 * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
 
17
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
18
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
19
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
20
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
21
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
22
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 
23
 * DAMAGE.
 
24
 */
 
25
package haxe.remoting;
 
26
import haxe.remoting.SocketProtocol.Socket;
 
27
 
 
28
class SyncSocketConnection implements Connection, implements Dynamic<Connection> {
 
29
 
 
30
        var __path : Array<String>;
 
31
        var __proto : SocketProtocol;
 
32
 
 
33
        function new(proto,path) {
 
34
                __proto = proto;
 
35
                __path = path;
 
36
        }
 
37
 
 
38
        public function resolve( name ) : Connection {
 
39
                var s = new SyncSocketConnection(__proto,__path.copy());
 
40
                s.__path.push(name);
 
41
                return s;
 
42
        }
 
43
 
 
44
        public function call( params : Array<Dynamic> ) : Dynamic {
 
45
                var proto = __proto;
 
46
                proto.sendRequest(__path,params);
 
47
                while( true ) {
 
48
                        var data = proto.readMessage();
 
49
                        if( proto.isRequest(data) ) {
 
50
                                if( proto.context == null )
 
51
                                        throw "Request received";
 
52
                                proto.processRequest(data,onRequestError);
 
53
                                continue;
 
54
                        }
 
55
                        return proto.processAnswer(data);
 
56
                }
 
57
                return null; // never reached
 
58
        }
 
59
 
 
60
        public function processRequest() {
 
61
                if( __proto.context == null )
 
62
                        throw "Can't process request";
 
63
                var data = __proto.readMessage();
 
64
                __proto.processRequest(data,onRequestError);
 
65
        }
 
66
 
 
67
        public function onRequestError( path : Array<String>, args : Array<Dynamic>, exc : Dynamic ) {
 
68
        }
 
69
 
 
70
        public function setProtocol( p : SocketProtocol ) {
 
71
                __proto = p;
 
72
        }
 
73
 
 
74
        public function getProtocol() : SocketProtocol {
 
75
                return __proto;
 
76
        }
 
77
 
 
78
        public function close() {
 
79
                try __proto.socket.close() catch( e : Dynamic ) { };
 
80
        }
 
81
 
 
82
        public static function create( s : Socket, ?ctx : Context ) {
 
83
                return new SyncSocketConnection(new SocketProtocol(s,ctx),[]);
 
84
        }
 
85
 
 
86
}