msgpack-rpc / msgpack-rpc-python

MessagePack RPC implementation for Python
205 stars 72 forks source link

Opportunity to select the protocol in a Address #4

Closed ConConovaloff closed 9 years ago

ConConovaloff commented 10 years ago

Hi.

You do not give for client code ability to change the attribute 'family' on method 'socket' of class 'Address'.

The method:

class Address(object):
  ...
    def socket(self, family=socket.AF_UNSPEC):
        res = socket.getaddrinfo(self._host, self._port, family,
                                 socket.SOCK_STREAM, 0, socket.AI_PASSIVE)[0]
        af, socktype, proto, canonname, sockaddr = res
        sock = socket.socket(af, socktype, proto)
        set_close_exec(sock.fileno())
        sock.setblocking(0)
        if af == socket.AF_INET6:
            if hasattr(socket, "IPPROTO_IPV6"):
                sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)

        return sock

And his single use:

class ClientTransport(object):
 ...
    def connect(self):
        stream = IOStream(self._address.socket(), io_loop=self._session._loop._ioloop)  # <-- here
        socket = ClientSocket(stream, self, self._encodings)
        socket.connect();

I have not found to influence the choice of protocol (AF_INET, AF_INET6). This can be a nuisance when the client connects to 'localhost' or another hostname where ipv6 is used. By default, 'Client' will be use ipv6, although it is likely the 'Server' listening ipv4. Additional Information: http://askubuntu.com/questions/32298/prefer-a-ipv4-dns-lookups-before-aaaaipv6-lookups

And your commit:

commit 886b26e18a5aca504c3ac8379095defaf90d5598
Author: Ken Sato <ksato9700@gmail.com>
Date:   Mon Nov 28 23:36:17 2011 -0800

    Found I'm getting IPv6 address for localhost.

    How can I bind both IPv4 and v6 address in the server side?

Maybe you could provide the choice of protocol in 'Address' class?

repeatedly commented 9 years ago

So sorry for the late reply. I will release v0.4 soon and v0.4 includes this PR. Thanks!

repeatedly commented 9 years ago

Released v0.4.0