Advanced search
Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Python for S60
Summary Tracker News SCM Files

Bugs: Browse | Download .csv

[#4440] select() can't wait for Bluetooth sockets

Please login

State:
Open
Date:
2009-08-26 21:39
Priority:
3
Submitted By:
Elvis Pfutzenreuter (epx)
Assigned To:
Nobody (None)
Summary:
select() can't wait for Bluetooth sockets

Detailed description
select.select() only works for sockets created using the standard Python socket module. Neither TCP/IP nor Bluetooth
sockets created via btsocket can be waited. This leaves BT sockets completely out of reach for select().

In Python 1.4.6, since Bluetooth sockets were created via socket module, select() could handle all of them.

Followup

Message
Date: 2009-10-15 16:53
Sender: Elvis Pfutzenreuter

I have tested with AF_INET sockets, which didn't work either
with select() when created via bt-socket, and
the new_btsocket.select() worked well. I didn't test with AF_BT
sockets but the new_btsocket code does not seem do do anything
different with them, so I estimate your code can go into official
btsocket.
Date: 2009-10-15 16:20
Sender: Mahesh Sayibabu

Hi,
I have attached a new version of btsocket module. It has a new
method called select. Please test with this module.

Usage:
import new_btsocket
sock = new_btsocket.socket(new_btsocket.AF_BT,
new_btsocket.SOCK_STREAM)
--
--
new_btsocket.select(sock, ...)

Date: 2009-10-08 14:04
Sender: Elvis Pfutzenreuter

If a socket object has the recv_will_return_data_immediately
and _set_recv_listener methods, I can understand that the suggestded
function works.

The only problem is that I created two btsockets, one BT and
another TCP/IP, and they don't show those methods in dir(). I
even took a look at _sock, _internalsocket and such inner objects
and couldn't find the functions anywhere.
Date: 2009-10-08 12:04
Sender: Mahesh Sayibabu

I have attached the file with the same function. Please test
with this and let me know if it works fine with your script.
Date: 2009-10-08 09:33
Sender: Mahesh Sayibabu

Can you add this function in your script and test if it helps.

In the script snippet.py call this function, btselect() instead
of select.select().
===========================================================
import e32socket
import e32


def btselect(in_objs, out_objs, exc_objs, timeout=None):
    if len(out_objs)>0 or len(exc_objs)>0:
        raise NotImplementedError('selecting for output ' \
                              'and exception not supported')
    for k in in_objs:
        if not isinstance(k, e32socket._socketobject):
            raise NotImplementedError('select supports only socket
objects')
    lock = e32.Ao_lock()
    if timeout is not None and timeout > 0:
        e32.ao_sleep(timeout, lock.signal)
    (ready_in, ready_out, ready_exc) = ([], [], [])
    for sock in in_objs:
        if sock._recv_will_return_data_immediately():
            ready_in.append(sock)
    # If we have readable sockets or we just want to poll, return
now.
    if len(ready_in) > 0 or timeout == 0:
        return (ready_in, ready_out, ready_exc)

    # Ok, so we want to wait for it...

    def callback(sock):
        ready_in.append(sock)
        lock.signal()
    for sock in in_objs:
        sock._set_recv_listener(lambda sock=sock:
callback(sock))
    lock.wait()
    return (ready_in, ready_out, ready_exc)
===========================================================
Date: 2009-09-18 14:59
Sender: Elvis Pfutzenreuter

I have attached a snippet with two functions that are part of
my application. It syncs data gathered in field to/from PC over
Bluetooth or TCP/IP. This works well up to PyS60 1.4.6 (note
that I didn't convert to btsocket yet).

The "wait_many" function is platfom-independent and
protocol-independent. The S60 BT socket is created by a
platform-dependent function "client_socket()".

The only workaround I can imagine for this thing, if select()
is not going to work with btsocket sockets anymore, is to dedicate
a thread to handle the BT connection.
Date: 2009-09-18 10:08
Sender: Mahesh Sayibabu

Hi, Can you please share the code that you intend to write using
btsocket and select modules.

Attached Files:

Name Download
No Files Currently Attached

Changes:

Field Old Value Date By
File Added634: new_btsocket.py2009-10-15 16:20sayibabu
File Added627: btselect.py2009-10-08 12:03sayibabu
File Added615: snippet.py2009-09-18 14:59epx

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment