Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-37

Support custom SocketFactory which does not support an InetSocketAddress

Details

    • Task
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 1.1.2
    • None
    • None
    • None
    • Linux, JDK 1.7

    Description

      Its possible to use a custom SocketFactory. To use unix Sockets theres exist a project called junixsocket here:

      http://code.google.com/p/junixsocket/

      I've writte a custom SocketFactory which does create unix sockets - but the code does force the connect to an

      InetSocketAddress sockAddr = new InetSocketAddress(host, port);

      in connect of MySQLProtocol class - which are of cause not supported and denied by the AFUnixSocket implementation.

      I've patched the Protocol class to read like this:

             String unixSocket = info.getProperty("unixsocket");
              if (unixSocket == null) {
                if (connectTimeout != null) {
                  socket.connect(sockAddr, connectTimeout * 1000);
                } else {
                  socket.connect(sockAddr);
                }    
              }

      and did specify the property unixsocket - value does not matter - to the properties given to the Driver class.
      After that i was able to use AF_UNIX Sockets.

      Would be nice if its possible to get some patch or property switch like this one, to make use of them.
      Or maybe use a custom SocketFactory interfae like connector/J does.

      Attachments

        Activity

          wlad Vladislav Vaintroub added a comment - - edited

          I might have misunderstood the issue (you did not attach the factory implementation) , however

          • Does your factory create an already connected socket?
            Also, can't you extend AFUnixSocket with a custom (perhaps anonymous) class that does implement connect() so it does not throw an Exception, if parameter is InetSocketAddr?
          wlad Vladislav Vaintroub added a comment - - edited I might have misunderstood the issue (you did not attach the factory implementation) , however Does your factory create an already connected socket? Also, can't you extend AFUnixSocket with a custom (perhaps anonymous) class that does implement connect() so it does not throw an Exception, if parameter is InetSocketAddr?
          tkrah Torsten Krah added a comment -

          Yes the factory does create AF_UNIX sockets which are already connected - there is no need to connect this socket at all.
          I am unable to extend the AFUNIXSocket class, it has a private constructor which i need to call. This maybe an option - i need to get an upstream patch on the other project to get a protected constructor constructor to be more extension friendly.

          Although it would be nice to not have the call to "connect" at all but let this handle the socket factory - like the mysql com.mysql.jdbc.Socketfactory class does.

          tkrah Torsten Krah added a comment - Yes the factory does create AF_UNIX sockets which are already connected - there is no need to connect this socket at all. I am unable to extend the AFUNIXSocket class, it has a private constructor which i need to call. This maybe an option - i need to get an upstream patch on the other project to get a protected constructor constructor to be more extension friendly. Although it would be nice to not have the call to "connect" at all but let this handle the socket factory - like the mysql com.mysql.jdbc.Socketfactory class does.

          I pushed a fix similar to yours, but instead of using dummy property, I just check if socket created by the factory is connected. If so, I skip connecting.
          Here is my patch http://lists.askmonty.org/pipermail/commits/2013-May/004736.html . I'm closing the bug assuming that it fixes the issue. If not, please reopen it.

          wlad Vladislav Vaintroub added a comment - I pushed a fix similar to yours, but instead of using dummy property, I just check if socket created by the factory is connected. If so, I skip connecting. Here is my patch http://lists.askmonty.org/pipermail/commits/2013-May/004736.html . I'm closing the bug assuming that it fixes the issue. If not, please reopen it.
          tkrah Torsten Krah added a comment -

          Confirmed its fixed, thx.

          tkrah Torsten Krah added a comment - Confirmed its fixed, thx.

          BTW, I recently implemented Unix domain socket support in the current trunk. Maybe you'll find it helpful. It needs JNA (Java Native Access) library to work (http://mvnrepository.com/artifact/net.java.dev.jna/jna). You'll need to use localSocket=/path/to/mysql.sock to connect via unix socket.

          wlad Vladislav Vaintroub added a comment - BTW, I recently implemented Unix domain socket support in the current trunk. Maybe you'll find it helpful. It needs JNA (Java Native Access) library to work ( http://mvnrepository.com/artifact/net.java.dev.jna/jna ). You'll need to use localSocket=/path/to/mysql.sock to connect via unix socket.

          People

            wlad Vladislav Vaintroub
            tkrah Torsten Krah
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.