Changeset eeab8bc


Ignore:
Timestamp:
2010-12-17T20:57:04Z (11 years ago)
Author:
Philippe Crama <pcfeb0009@…>
Branches:
master
Children:
5a54ec8
Parents:
a618ea6
Message:

Remove dependency on gobject and use select standard module

This is a restart of the windows-skyped branch based on the updated
bitlbee-skype using the builtin SSL libs of Python.

This version connects, but hangs for long times... to be continued

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skype/skyped.py

    ra618ea6 reeab8bc  
    2626import locale
    2727import time
    28 import gobject
    2928import socket
    3029import getopt
     
    3433from traceback import print_exception
    3534import ssl
     35import select
    3636
    3737__version__ = "0.1.1"
     
    4242        if type != KeyboardInterrupt:
    4343                print_exception(type, value, tb)
    44         gobject.MainLoop().quit()
    4544        options.conn.close()
    4645        # shut down client if it's running
     
    9493
    9594def bitlbee_idle_handler(skype):
     95        global options
    9696        if options.conn:
    9797                try:
     
    103103        return True
    104104
    105 def server(host, port):
     105def server(host, port, skype):
    106106        global options
    107107        sock = socket.socket()
     
    109109        sock.bind((host, port))
    110110        sock.listen(1)
    111         gobject.io_add_watch(sock, gobject.IO_IN, listener)
    112 
    113 def listener(sock, *args):
     111        dprint("Waiting for connection...")
     112        listener(sock, skype)
     113
     114def listener(sock, skype):
    114115        global options
    115116        rawsock, addr = sock.accept()
     
    140141                dprint("Username and password OK.")
    141142                options.conn.send("PASSWORD OK\n")
    142                 gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler)
     143                serverloop(options, skype)
    143144                return True
    144145        else:
     
    191192                        if options.conn:
    192193                                try:
     194                                        # I called the send function really_send
    193195                                        send(options.conn, e + "\n")
    194196                                except Exception, s:
     
    252254        -v      --version       display version information""" % (self.cfgpath, self.host, self.port)
    253255                sys.exit(ret)
     256
     257def serverloop(options, skype):
     258        timeout = 1; # in seconds
     259        skype_ping_period = 5
     260        bitlbee_ping_period = 30
     261        skype_ping_start_time = time.time()
     262        bitlbee_ping_start_time = time.time()
     263        while 1:
     264                ready_to_read, ready_to_write, in_error = \
     265                        select.select([options.conn], [], [], timeout)
     266                now = time.time()
     267                if len(ready_to_read) == 1:
     268                        input_handler(ready_to_read.pop(), options)
     269                        # don't ping bitlbee/skype if they already received data
     270                        bitlbee_ping_start_time = now
     271                        skype_ping_start_time = now
     272                if now - skype_ping_period > skype_ping_start_time:
     273                        skype_idle_handler(skype)
     274                        skype_ping_start_time = now
     275                if now - bitlbee_ping_period > bitlbee_ping_start_time:
     276                        bitlbee_idle_handler(skype)
     277                        bitlbee_ping_start_time = now
    254278
    255279if __name__=='__main__':
     
    317341        else:
    318342                dprint('skyped is started on port %s' % options.port)
    319         server(options.host, options.port)
    320343        try:
    321344                skype = SkypeApi()
    322345        except Skype4Py.SkypeAPIError, s:
    323346                sys.exit("%s. Are you sure you have started Skype?" % s)
    324         gobject.timeout_add(2000, skype_idle_handler, skype)
    325         gobject.timeout_add(60000, bitlbee_idle_handler, skype)
    326         gobject.MainLoop().run()
     347        server(options.host, options.port, skype)
Note: See TracChangeset for help on using the changeset viewer.