connection.py : socket.MSG_WAITALL not available on windows version of python

Bug #437972 reported by analogue
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MySQL Connector/Python
Fix Released
Critical
Geert JM Vanderkelen

Bug Description

In connection.py, there are two references to socket.MSG_WAITALL.

1) header = self.sock.recv(4, socket.MSG_WAITALL)
2) buf = header + self.sock.recv(pktsize, socket.MSG_WAITALL)

This is not available on windows version of python and results in an error message: module' has no attribute socket.MSG_WAITALL

Workaround below:

def recv(self):
        """
        Receive packets using the socket from the server.
        """
        try:
            # HACK: MSG_WAITALL not available on windows
            #header = self.sock.recv(4, socket.MSG_WAITALL)
            header = self.read_exactly(self.sock, 4)

            (pktsize, pktnr) = self.protocol.handle_header(header)

            # HACK: MSG_WAITALL not available on windows
            #buf = header + self.sock.recv(pktsize, socket.MSG_WAITALL)
            buf = header + self.read_exactly(self.sock, pktsize)

            self.protocol.is_error(buf)
        except socket.timeout, errmsg:
            raise InterfaceError('Timed out reading from socket.')

        return (buf, pktsize, pktnr)

    def read_exactly(self, sock, size):
        buffer = ''
        while len(buffer) < size:
            data = sock.recv(size-len(buffer))
            if not data:
                break
            buffer+=data
        return buffer

Tags: windows
Changed in myconnpy:
assignee: nobody → Geert JM Vanderkelen (geertjmvdk)
importance: Undecided → Critical
status: New → In Progress
Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

Thanks for this report!

I've put it Critical as we need to get it working OK for Windows environment.

tags: added: windows
Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

Fixed using os.name to check if we are on Windows.
I tried to check if I could implement support for Named Pipes, but that's a bigger thing.

Changed in myconnpy:
status: In Progress → Fix Committed
Changed in myconnpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.