예제 #1
0
def ChatListener(addr):
  ss = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
  ss.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  ss.bind(addr)
  ss.listen(128)
  print >>sys.stderr, 'info: listening for telnet chat on %r' % (
      ss.getsockname(),)
  print >>sys.stderr, 'info: to connect, run:  telnet %s %s' % (
      ss.getsockname()[:2])
  while True:
    cs, csaddr = ss.accept()
    print >>sys.stderr, 'info: connection from %r' % (csaddr,)
    coio.stackless.tasklet(ChatWorker)(cs.makefile(), csaddr)
    cs = csaddr = None  # Free memory early.
예제 #2
0
def ChatListener(addr):
    ss = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
    ss.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    ss.bind(addr)
    ss.listen(128)
    print >> sys.stderr, 'info: listening for telnet chat on %r' % (
        ss.getsockname(), )
    print >> sys.stderr, 'info: to connect, run:  telnet %s %s' % (
        ss.getsockname()[:2])
    while True:
        cs, csaddr = ss.accept()
        print >> sys.stderr, 'info: connection from %r' % (csaddr, )
        coio.stackless.tasklet(ChatWorker)(cs.makefile(), csaddr)
        cs = csaddr = None  # Free memory early.
예제 #3
0
    while True:
      msg = sock.recv(256)
      if not msg:
        break
      timestamps[0] = max(timestamps[0], time.time())  # Register read.
      # TODO(pts): Flush earlier.
      write_channel.send('You typed %r.\r\n' % msg)
  finally:
    logging.info('connection closed from %r' % (addr,))
    if writer_tasklet.alive:
      write_channel.send(None)  # Will kill writer_tasklet eventually.
    timestamps[0] = None  # Will kill sleeper_tasklet eventually.
    while writer_tasklet.alive or sleeper_tasklet.alive:
      stackless.schedule(None)
    sock.close()

if __name__ == '__main__':
  logging.root.setLevel(logging.INFO)
  logging.info('echo server with heartbeat initializing')
  server_socket = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
  server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  server_socket.bind(('127.0.0.1', 5454))
  server_socket.listen(100)
  logging.info('connect with:  telnet %s %s' % server_socket.getsockname()[:2])
  while True:
    client_socket, addr = server_socket.accept()
    logging.info('connection from %r, runcount=%d' %
                 (addr, stackless.getruncount()))
    stackless.tasklet(Worker)(client_socket, addr)
    client_socket = addr = None  # Free memory early.
예제 #4
0
            if not msg:
                break
            timestamps[0] = max(timestamps[0], time.time())  # Register read.
            # TODO(pts): Flush earlier.
            write_channel.send('You typed %r.\r\n' % msg)
    finally:
        logging.info('connection closed from %r' % (addr, ))
        if writer_tasklet.alive:
            write_channel.send(None)  # Will kill writer_tasklet eventually.
        timestamps[0] = None  # Will kill sleeper_tasklet eventually.
        while writer_tasklet.alive or sleeper_tasklet.alive:
            stackless.schedule(None)
        sock.close()


if __name__ == '__main__':
    logging.root.setLevel(logging.INFO)
    logging.info('echo server with heartbeat initializing')
    server_socket = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind(('127.0.0.1', 5454))
    server_socket.listen(100)
    logging.info('connect with:  telnet %s %s' %
                 server_socket.getsockname()[:2])
    while True:
        client_socket, addr = server_socket.accept()
        logging.info('connection from %r, runcount=%d' %
                     (addr, stackless.getruncount()))
        stackless.tasklet(Worker)(client_socket, addr)
        client_socket = addr = None  # Free memory early.
예제 #5
0
파일: demo.py 프로젝트: breezechen/syncless
      psyco.full()
      logging.info('using psyco')
    except ImportError:
      logging.info('psyco not available')
      pass
  else:
    logging.info('not using psyco')

  #try:
  #  rdata = coio.gethostbyname_ex('en.wikipedia.org')
  #except socket.gaierror, e:
  #  rdata = e
  #logging.info(repr(rdata))
  #logging.info('Query2 done.')

  listener_nbs = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
  listener_nbs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  listener_nbs.bind(('127.0.0.1', 6666))
  # Reducing this has a strong negative effect on ApacheBench worst-case
  # connection times, as measured with:
  # ab -n 100000 -c 50 http://127.0.0.1:6666/ >ab.stackless3.txt
  # It increases the maximum Connect time from 8 to 9200 milliseconds.
  listener_nbs.listen(100)
  if use_http:
    logging.info('visit http://%s:%s/' % listener_nbs.getsockname())
  if use_https:
    upgrade_ssl_callback = wsgi.SslUpgrader(
        {'certfile': os.path.join(os.path.dirname(__file__), 'ssl_cert.pem'),
         'keyfile':  os.path.join(os.path.dirname(__file__), 'ssl_key.pem')},
        use_http)
    logging.info('visit https://%s:%s/' % listener_nbs.getsockname())
예제 #6
0
파일: demo.py 프로젝트: olopez32/syncless
            psyco.full()
            logging.info('using psyco')
        except ImportError:
            logging.info('psyco not available')
            pass
    else:
        logging.info('not using psyco')

    #try:
    #  rdata = coio.gethostbyname_ex('en.wikipedia.org')
    #except socket.gaierror, e:
    #  rdata = e
    #logging.info(repr(rdata))
    #logging.info('Query2 done.')

    listener_nbs = coio.new_realsocket(socket.AF_INET, socket.SOCK_STREAM)
    listener_nbs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    listener_nbs.bind(('127.0.0.1', 6666))
    # Reducing this has a strong negative effect on ApacheBench worst-case
    # connection times, as measured with:
    # ab -n 100000 -c 50 http://127.0.0.1:6666/ >ab.stackless3.txt
    # It increases the maximum Connect time from 8 to 9200 milliseconds.
    listener_nbs.listen(100)
    if use_http:
        logging.info('visit http://%s:%s/' % listener_nbs.getsockname())
    if use_https:
        upgrade_ssl_callback = wsgi.SslUpgrader(
            {
                'certfile': os.path.join(os.path.dirname(__file__),
                                         'ssl_cert.pem'),
                'keyfile': os.path.join(os.path.dirname(__file__),