My favorites
▼
|
Sign in
hxcpp
Runtime files for c++ backend for haxe
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
233
attachment: DebugSocket.hx
(2.7 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package hxcpp;
import sys.net.Socket;
import haxe.CallStack;
import hxcpp.DebugBase;
import cpp.vm.Thread;
class OutputMessage
{
public function new(inType:Int, inValue:Dynamic)
{
type = inType;
value = inValue;
}
public static inline var RESULT = 0;
public static inline var STATUS = 1;
public static inline var OUTPUT = 2;
public var type:Int;
public var value:Dynamic;
}
class DebugSocket extends DebugStdio
{
var socket:Socket;
var host:String;
var port:Int;
var outputThread:Thread;
var socketOut:haxe.io.Output;
public function new(inHost:String, inPort:Int, inCreateStopped:Bool=false)
{
host = inHost;
port = inPort;
super(inCreateStopped);
}
override function init() : Bool
{
try
{
socket = new Socket();
trace("Connect " + host + ":" + port + "...");
try
{
socket.connect( new sys.net.Host(host), port );
} catch (e:Dynamic)
{
trace("Could not CONNECT!");
socket = null;
}
if (socket!=null)
{
trace("connected.");
input = socket.input;
socketOut = socket.output;
}
else
{
trace("debugging failed.");
return false;
}
}
catch(e:Dynamic)
{
if (socket!=null)
socket.close();
socket = null;
trace("Socket error:" + e);
return false;
}
outputThread = Thread.create(outputLoop);
return true;
}
override function getNextCommand() : String
{
if (input==null)
return "bye";
try
{
return input.readLine();
}
catch(e:Dynamic)
{
trace("getNextCommand - socket closed");
input.close();
input = null;
}
return "bye";
}
override function onResult(inString:String)
{
if (stillDebugging)
outputThread.sendMessage(new OutputMessage(OutputMessage.RESULT,inString) );
}
override function sendOutput(inString:String)
{
if (stillDebugging)
outputThread.sendMessage(new OutputMessage(OutputMessage.OUTPUT,inString) );
}
override function sendStatus(inString:String)
{
if (stillDebugging)
outputThread.sendMessage(new OutputMessage(OutputMessage.STATUS,inString) );
}
function outputLoop()
{
while(stillDebugging)
{
var message:OutputMessage = Thread.readMessage(true);
socketOut.writeByte(message.type);
var value:String = message.value;
var len = value.length;
socketOut.writeInt32(len);
socketOut.writeString(value);
}
socketOut.close();
}
}
Powered by
Google Project Hosting