コード例 #1
0
    def connect(self, socket_serv, address, cb_func, cb_param):
        """
        This method has the same semantics as the ``connect``
        method of ``TcpSymbianSocket``.

        In the BT case, ``address`` must be of the form
        ("hh:hh:hh:hh:hh:hh", port).
        """
        address, port = address
        check_mac(address)
        if self.connected:
            raise AsyncSocketAlreadyOpen
        if self.connecting:
            raise AsyncSocketRequestPending
        if self.inited:
            self.close()
        self.native = aosocketnativenew.AoSocket()
        self.inited = True
        try:
            self.native.set_socket_serv(socket_serv.native)
            self.native.open_bt()
            self.native.connect_bt(unicode(address), port, self.connect_cb,
                                   (cb_func, cb_param))
            self.connecting = True
        except:
            self.close()
            raise
コード例 #2
0
    def listen(self, socket_serv, address, queue_size, service_id,
               service_name):
        """
        This method has the same semantics as the ``listen``
        method of ``TcpSymbianSocket``.

        Note that no listening address needs to be specified
        in the BT case, as it is determined automatically.
        """
        if self.inited:
            raise AsyncSocketAlreadyOpen
        self.native = aosocketnativenew.AoSocket()
        self.inited = True

        try:
            port = address[1]
        except IndexError:
            port = None

        try:
            self.native.set_socket_serv(socket_serv.native)
            self.native.open_bt()
            if not port:
                port = self.get_available_port()
            self.native.listen_bt(port, queue_size, service_id, service_name)
            self.connected = True
        except:
            self.close()
            raise
コード例 #3
0
    def listen(self, socket_serv, address, queue_size):
        """
        A synchronous method that may throw an exception.

        Opens the still closed socket, has it bound to the specified
        ``address``, and has it start listening to connections at that
        address. The maximum number of connections are allowed in the
        accept queue is set to ``queue_size``.

        The ``socket_serv`` parameter must be a handle to an open
        socket session. The listening socket will then belong to that
        session.
        """
        if self.inited:
            raise AsyncSocketAlreadyOpen
        self.native = aosocketnativenew.AoSocket()
        self.inited = True
        try:
            self.native.set_socket_serv(socket_serv.native)
            self.native.open_tcp()
            self.native.listen_tcp(unicode(address[0]), address[1], queue_size)
            self.connected = True
        except:
            self.close()
            raise
コード例 #4
0
    def connect(self, socket_serv, address, cb_func, cb_param):
        """
        An asynchronous method that may throw an exception.

        Connects the still closed socket into a server at ``address``.

        The ``socket_serv`` parameter must be a handle to an open
        socket server session. The connected socket will then belong
        to that session.

        Once the request completes, an event will be delivered to the
        thread that made the request. The event will be delivered by
        calling ``cb_func`` with the following parameters:

        * a Symbian-specific error code

        * ``cb_param``

        An exception in the callback will be handled by the
        ``handle_callback_error`` method.
        """
        if self.connected:
            raise AsyncSocketAlreadyOpen
        if self.connecting:
            raise AsyncSocketRequestPending
        if self.inited:
            self.close()
        self.native = aosocketnativenew.AoSocket()
        self.inited = True
        try:
            self.native.set_socket_serv(socket_serv.native)
            self.native.open_tcp()
            self.native.connect_tcp(unicode(address[0]), address[1],
                                    self.connect_cb, (cb_func, cb_param))
            self.connecting = True
        except:
            self.close()
            raise
コード例 #5
0
def cl_thread_func(main_lock):
    try:
        tell("(client thread)")

        global cl_socket_serv
        cl_socket_serv = aosocketnativenew.AoSocketServ()
        cl_socket_serv.connect()
        tell("created socket server")

        cl_socket = aosocketnativenew.AoSocket()
        tell("created socket")
        cl_socket.open(cl_socket_serv)
        tell("initialized socket")

        cl_socket.close()
        # should free here, but do not
        #cl_socket_serv.close()

        tell("client now all done, releasing main thread")
        thread_finish_logging()
        main_lock.signal()
    except:
        log_exception()
コード例 #6
0
    def blank(self, socket_serv):
        """
        A synchronous method that may throw an exception.

        Turns the closed socket into a blank socket, which is the type
        of socket that the ``accept`` method requires as a parameter.

        The ``socket_serv`` parameter must be a handle to an open
        socket session. The blank socket will then belong to that
        session.

        This method returns the object instance being operated upon.
        """
        if self.inited:
            raise AsyncSocketAlreadyOpen
        self.native = aosocketnativenew.AoSocket()
        self.inited = True
        try:
            self.native.set_socket_serv(socket_serv.native)
            self.native.blank()
        except:
            self.close()
            raise
        return self
コード例 #7
0
def cl_thread_func(main_lock):

    def cl_read(error, data, dummy):
        try:
            if error == 0:
                tell("read " + data)
            else:
                tell("failed with code %d" % error)
            cl_loop.stop()
        except:
            log_exception()

    def cl_written(error, dummy):
        try:
            if error == 0:
                tell("sent request")
                cl_socket.read_some(1024, cl_read, None)
            else:
                tell("failed with code %d" % error)
                cl_loop.stop()
        except:
            log_exception()

    def cl_connected(error, dummy):
        try:
            if error == 0:
                tell("connected to server")
                cl_socket.write_data("GET / HTTP/1.0\n\n", cl_written, None)
            else:
                tell("failed with code %d" % error)
                cl_loop.stop()
        except:
            log_exception()


    try:
        tell("(client thread)")
    
        cl_socket_serv = aosocketnativenew.AoSocketServ()
        cl_socket_serv.connect()
        tell("created socket server")

        cl_socket = aosocketnativenew.AoSocket()
        tell("created socket")
        cl_socket.open(cl_socket_serv)
        tell("initialized socket")

        tell("attempting connect")
        cl_socket.connect_bt(unicode(address),
                             cl_connected, None)
        tell("connect request made")
    except:
        log_exception()

    cl_loop = aosocketnativenew.AoLoop()
    cl_loop.open()
    cl_loop.start()
    
    cl_loop.close()
    cl_socket.close()
    cl_socket_serv.close()
        
    tell("client now all done, releasing main thread")
    thread_finish_logging()
    main_lock.signal()
コード例 #8
0
def sv_thread_func(main_lock):
    def sv_written(error, dummy):
        try:
            if error == 0:
                tell("sent reply")
            else:
                tell("failed with code %d" % error)
            sv_loop.stop()
        except:
            log_exception()

    def sv_read(error, data, dummy):
        try:
            if error == 0:
                tell("got request " + data)
                sv_socket.write_data(data + " World!", sv_written, None)
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()

    def sv_accepted(error, sv_socket, dummy):
        try:
            if error == 0:
                tell("accepted client")
                sv_socket.read_some(1024, sv_read, None)
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()

    def ac_configured(error, dummy):
        try:
            if error == 0:
                tell("socket configured")
                tell("now making accept request")
                ac_socket.accept_client(sv_socket, sv_accepted, None)
                tell("did accept request")
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()

    try:
        tell("(server thread)")

        sv_socket_serv = aosocketnativenew.AoSocketServ()
        sv_socket_serv.connect()
        tell("created socket server")

        ac_socket = aosocketnativenew.AoSocket()
        tell("created socket")
        ac_socket.open(sv_socket_serv)
        tell("initialized socket")

        tell("creating blank socket")
        sv_socket = aosocketnativenew.AoSocket()
        sv_socket.open(sv_socket_serv)
        sv_socket.blank()
        tell("created blank socket")

        tell("calling listen")
        ac_socket.listen_bt()
        tell("socket bound -- now configuring")

        ac_socket.config_bt(ac_configured, None)
        tell("did config request")
    except:
        log_exception()

    sv_loop = aosocketnativenew.AoLoop()
    sv_loop.open()
    sv_loop.start()

    sv_loop.close()
    sv_socket.close()
    ac_socket.close()
    sv_socket_serv.close()

    tell("server now all done, releasing main thread")
    thread_finish_logging()
    main_lock.signal()
コード例 #9
0
def sv_thread_func(main_lock):

    def sv_written(error, dummy):
        try:
            if error == 0:
                tell("sent reply")
            else:
                tell("failed with code %d" % error)
            sv_loop.stop()
        except:
            log_exception()
    
    def sv_read(error, data, dummy):
        try:
            if error == 0:
                qty = len(data)
                tell("got request of size " + str(qty))

                global amount_read
                amount_read += qty
                if amount_read < data_amount:
                    log_heap_status("sv")
                    sv_socket.read_some(data_amount - amount_read,
                                        sv_read, None)
                    log_heap_status("sv")
                else:
                    sv_socket.write_data("thanks", sv_written, None)
                    
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()
    
    def sv_accepted(error, sv_socket, dummy):
        try:
            if error == 0:
                tell("accepted client")
                log_heap_status("sv")
                sv_socket.read_some(100000, sv_read, None)
                log_heap_status("sv")
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()
        
    try:
        tell("(server thread with heap %d)" % miso.heap_base_address())

        log_heap_status("sv")
        logwrite("heap avail %d" % test_heap_avail())
        log_heap_status("sv")

	#bigdata = gen_data(999999)

        sv_socket_serv = aosocketnativenew.AoSocketServ()
        sv_socket_serv.connect()
        tell("created socket server")

        ac_socket = aosocketnativenew.AoSocket()
        tell("created socket")
        ac_socket.set_socket_serv(sv_socket_serv)
        ac_socket.open_tcp()
        tell("initialized socket")

        tell("creating blank socket")
        sv_socket = aosocketnativenew.AoSocket()
        sv_socket.set_socket_serv(sv_socket_serv)
        sv_socket.blank()
        tell("created blank socket")
        ac_socket.listen_tcp(unicode(address[0]), address[1], 5)
        tell("now listening -- doing an accept")
        ac_socket.accept_client(sv_socket, sv_accepted, None)
        tell("did accept request")
    except:
        log_exception()

    sv_loop = aosocketnativenew.AoLoop()
    sv_loop.open()
    sv_loop.start()
    
    sv_loop.close()
    sv_socket.close()
    ac_socket.close()
    sv_socket_serv.close()
        
    tell("server now all done, releasing main thread")
    thread_finish_logging()
    main_lock.signal()
コード例 #10
0
def cl_thread_func(main_lock):

    def cl_read(error, data, dummy):
        try:
            if error == 0:
                tell("read " + data)
            else:
                tell("failed with code %d" % error)
            cl_loop.stop()
        except:
            log_exception()

    def cl_written(error, dummy):
        try:
            if error == 0:
                tell("sent request")
                cl_socket.read_some(1024, cl_read, None)
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()

    def cl_connected(error, dummy):
        try:
            if error == 0:
                tell("connected to server")
                log_heap_status("cl")
                cl_socket.write_data(gen_data(data_amount), cl_written, None)
                log_heap_status("cl")
            else:
                tell("failed with code %d" % error)
        except:
            log_exception()


    try:
        tell("(client thread with heap %d)" % miso.heap_base_address())

        log_heap_status("cl")
        logwrite("heap avail %d" % test_heap_avail())
        log_heap_status("cl")

        #bigdata = gen_data(999999)

        cl_socket_serv = aosocketnativenew.AoSocketServ()
        cl_socket_serv.connect()
        tell("created socket server")

        cl_socket = aosocketnativenew.AoSocket()
        tell("created socket")
        cl_socket.set_socket_serv(cl_socket_serv)
        cl_socket.open_tcp()
        tell("initialized socket")

        tell("attempting connect")
        cl_socket.connect_tcp(unicode(address[0]), address[1],
                              cl_connected, None)
        tell("connect request made")
    except:
        log_exception()

    cl_loop = aosocketnativenew.AoLoop()
    cl_loop.open()
    cl_loop.start()
    
    cl_loop.close()
    cl_socket.close()
    cl_socket_serv.close()
        
    tell("client now all done, releasing main thread")
    thread_finish_logging()
    main_lock.signal()