You Are Here:

Community: Developer Discussion Boards

#1 Old Question Bug in socket.py? - 2007-05-09, 08:24

Join Date: Jul 2005
Posts: 66
Location: Espoo, Finland
tsharju
Offline
Regular Contributor
Hi,

I've been wondering the behavior of socket.py for some time now. I've created a application that uses TCP socket and every now and then the socket dies and prints something like "socket.error, Broken pipe". I know that this is probably work of an evil mobile operator, but my problem is that current socket.py implementation only prints that error and does not raise an exception. So I cannot handle this situation in my application at all to e.g., re-open the socket once this happens.

This is the code in socket.py that does this... I've noticed the problem only with the receive callback starting from line 371.

Code:
    def _recv_callback(self,data):
        if isinstance(data,tuple):
            print "error %s %s"%data
            self._seterror(data)
            return
        self._recvbuf += data
        self._recv_callback_pending=False
        if self._recv_listener:
            t=self._recv_listener
            self._recv_listener=None
            t()
Instead of just printing the error and returning it should do something like this.

Code:
    def _recv_callback(self,data):
        if isinstance(data,tuple):
            print "error %s %s"%data
            self._seterror(data)
            raise self._error[0],self._error[1]
        self._recvbuf += data
        self._recv_callback_pending=False
        if self._recv_listener:
            t=self._recv_listener
            self._recv_listener=None
            t()
I tested this on my application and it works. I don't know if this affects on behavior of some standard Python libraries, but I think it should raise the exception so that the case can be handled.

Should I file a bug report?

Regards,

Teemu
Reply With Quote

#2 Old Re: Bug in socket.py? - 2007-05-09, 10:04

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Yes, there is a bug. I took a look at socket.py and it indeed fails to raise an exception in a particular case. Your fix is not correct, though. The exception can't be raised in that callback, but instead it must be raised in .recv() using _checkerror().

Could you post the code you are using? It could be useful as a test case.

We'll fix this, thanks for noticing.
Reply With Quote

#3 Old Re: Bug in socket.py? - 2007-05-09, 11:26

Join Date: Jul 2005
Posts: 66
Location: Espoo, Finland
tsharju
Offline
Regular Contributor
Quote:
Originally Posted by jplauril
Could you post the code you are using? It could be useful as a test case.
Well, my application has grown to be quite large and is not probably that suitable for this purpose. I'm using jabber.py library available from http://jabberpy.sourceforge.net/.

Here is the part from xmlstream.py that causes the problem. I use select and then I have callback that is called when the connection breaks.

Code:
    def process(self, timeout=0):
        """Receives incoming data (if any) and processes it.
           Waits for data no more than timeout seconds."""
        try:
            if select([self._reader],[],[],timeout)[0]:
                data = self.read()
                if data == '':
                    return len(data)
                self._parser.Parse(data)
                return len(data)
            return 0     # Zero means that nothing received but link is alive.
        except:
            self.DEBUG("xmlstream read threw error", DBG_CONN_ERROR)
            self.disconnected(self)

    def disconnected(self,conn):
        """Called when a Network Error or disconnection occurs."""
        try: self.disconnectHandler(conn)
        except TypeError: self.disconnectHandler()
So basically I loop process() and if it fails it calls the disconnected() callback. Currently it does not raise any exceptions, but it only prints the error. So it is the select() that should raise the exception in this case. Hopefully this provides some help.

- Teemu
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
RecordStore bug on Series 60 ncerezo2 Mobile Java General 20 2008-11-13 05:31
Serious BUG in Nokia phones!!! bartekn Mobile Java Media (Graphics & Sounds) 10 2004-03-28 23:09
A bug: setColor with offscreen graphics - PLEASE, REPLY THIS TIME palmcrust Mobile Java General 11 2003-12-04 13:43
Firmware bug or code bug displaying list on 3650 blackjack75 Mobile Java General 2 2003-09-24 20:52
** Important ** Event bug in phone and emulator. fnagaton General Symbian C++ 8 2003-07-11 13:56

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ