File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -151,3 +151,47 @@ def sleep2(secs):
151
151
yield None
152
152
# print("Finished sleeping", secs)
153
153
# time.sleep(secs)
154
+
155
+
156
+ import microsocket as _socket
157
+
158
+ class StreamReader :
159
+
160
+ def __init__ (self , s ):
161
+ self .s = s
162
+
163
+ def readline (self ):
164
+ print ("readline" )
165
+ s = yield IORead (self .s )
166
+ print ("after IORead" )
167
+ res = self .s .readline ()
168
+ print ("readline res:" , res )
169
+ return res
170
+
171
+
172
+ class StreamWriter :
173
+
174
+ def __init__ (self , s ):
175
+ self .s = s
176
+
177
+ def write (self , buf ):
178
+ print ("Write!" )
179
+ res = self .s .write (str (buf ))
180
+ print ("write res:" , res )
181
+ s = yield IOWrite (self .s )
182
+ print ("returning write res:" , res )
183
+
184
+
185
+ def open_connection (host , port ):
186
+ s = _socket .socket ()
187
+ s .setblocking (False )
188
+ ai = _socket .getaddrinfo (host , port )
189
+ addr = ai [0 ][4 ]
190
+ try :
191
+ s .connect (addr )
192
+ except OSError as e :
193
+ print (e .args [0 ])
194
+ print ("After connect" )
195
+ s = yield IOWrite (s )
196
+ print ("After iowait:" , s )
197
+ return StreamReader (s ), StreamWriter (s )
You can’t perform that action at this time.
0 commit comments