def test(self): c = cio.channel() cio.routine(self.reader, c) cio.routine(self.writer, c) cio.nonblock(1) for i in range(10): cio.write(1, "%d\n" % i)
def server(self, listener, count): for i in range(count): socketfd = cio.accept(listener.fileno()) print("accept() -> %d" % socketfd) cio.routine(self.server_handle, socketfd) listener.close() for i in range(10000): cio.write(1, "")
import cio #import sys def getchar (): # return ord(sys.stdin.read(1)); return cio.getchar(); s="" cio.write ("Hello World!") while (1): rc = getchar() print ( rc ); print ( str(chr( rc )) ) if ( rc == 0x08 ): # backspace if (len(s) >= 1): s = s[:-1] pass else: s = "" elif ( rc == '\n' or rc=='\r' or rc=='\\' ): # newline -> try compiling and evaluating try: print (eval ( compile ( s, "repl", "exec"))); s = ""; except: print ("MÖP"); s = s + chr( rc ); elif ( rc == 'b' ) : # b as debug-character print ( s ); else: s = s + chr( rc ) print (s)
def writer(self, fd, i): buf = str(i) n = cio.write(fd, buf) print("write(%s) = %d" % (repr(buf), n)) cio.close(fd)