[CONJ-37] Support custom SocketFactory which does not support an InetSocketAddress Created: 2013-05-16  Updated: 2013-07-05  Resolved: 2013-05-21

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.2
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Torsten Krah Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None
Environment:

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.



 Comments   
Comment by Vladislav Vaintroub [ 2013-05-16 ]

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?
Comment by Torsten Krah [ 2013-05-21 ]

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.

Comment by Vladislav Vaintroub [ 2013-05-21 ]

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.

Comment by Torsten Krah [ 2013-07-05 ]

Confirmed its fixed, thx.

Comment by Vladislav Vaintroub [ 2013-07-05 ]

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.

Generated at Thu Feb 08 03:12:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.