DebugClients/Ruby/AsyncIO.rb

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

eric ide

mercurial