DebugClients/Ruby/AsyncIO.rb

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 =begin edoc
7 File implementing an asynchronous interface for the debugger.
8 =end
9
10 if RUBY_VERSION < "1.9"
11 $KCODE = 'UTF8'
12 require 'jcode'
13 end
14
15 module AsyncIO
16 =begin edoc
17 Module implementing asynchronous reading and writing.
18 =end
19 def initializeAsyncIO
20 =begin edoc
21 Function to initialize the module.
22 =end
23 disconnect()
24 end
25
26 def disconnect
27 =begin edoc
28 Function to disconnect any current connection.
29 =end
30 @readfd = nil
31 @writefd = nil
32 end
33
34 def setDescriptors(rfd, wfd)
35 =begin edoc
36 Function called to set the descriptors for the connection.
37
38 @param fd file descriptor of the input file (int)
39 @param wfd file descriptor of the output file (int)
40 =end
41 @rbuf = ''
42 @readfd = rfd
43
44 @wbuf = ''
45 @writefd = wfd
46 end
47
48 def readReady(fd)
49 =begin edoc
50 Function called when there is data ready to be read.
51
52 @param fd file descriptor of the file that has data to be read (int)
53 =end
54 begin
55 got = @readfd.readline()
56 rescue
57 return
58 end
59
60 if got.length == 0
61 sessionClose()
62 return
63 end
64
65 @rbuf << got
66
67 # Call handleLine for the line if it is complete.
68 eol = @rbuf.index("\n")
69
70 while eol and eol >= 0
71 s = @rbuf[0..eol]
72 @rbuf = @rbuf[eol+1..-1]
73 handleLine(s)
74 eol = @rbuf.index("\n")
75 end
76 end
77
78 def writeReady(fd)
79 =begin edoc
80 Function called when we are ready to write data.
81
82 @param fd file descriptor of the file that has data to be written (int)
83 =end
84 @writefd.write(@wbuf)
85 @writefd.flush()
86 @wbuf = ''
87 end
88
89 def write(s)
90 =begin edoc
91 Function to write a string.
92
93 @param s the data to be written (string)
94 =end
95 @wbuf << s
96 end
97 end

eric ide

mercurial