MariaDB Client Library for Java Applications
  1. MariaDB Client Library for Java Applications
  2. CONJ-37

Support custom SocketFactory which does not support an InetSocketAddress

    Details

    • Type: Task Task
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: jdbc-1.1.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Linux, JDK 1.7
    • Global Rank:
      3021

      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.

        Activity

        Hide
        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?
        Show
        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?
        Hide
        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.

        Show
        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.
        Hide
        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.

        Show
        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.
        Hide
        Torsten Krah added a comment -

        Confirmed its fixed, thx.

        Show
        Torsten Krah added a comment - Confirmed its fixed, thx.
        Hide
        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.

        Show
        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

          • Assignee:
            Vladislav Vaintroub
            Reporter:
            Torsten Krah
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 3 hours
              3h