GOODS "is an object oriented fully distrbuted database management system using an active client model." It is also described as a "language-neutral object database" with client interfaces for C++, Java and Perl. GOODS is written by Konstantin Knizhnik.
Avi Bryant developed a Squeak client for GOODS that allows transparent storage of Smalltalk objects. The client is now maintained for Pharo, Squeak and VisualWorks by David Shaffer and is hosted on SqueakSource3.
GOODS works over TCP and Unix domain sockets. However, the GOODS documentation doesn't actually describe how to configure for the latter. There is, however, a hint in the main configuration file "goodsrv.cfg":
In addition to the main configuration file, there is database-specific configuration file, which I've named "test.cfg", that looks like this:
This matches the configuration format:
Meaning, for test.cfg, I'm specifying one storage server, and it listens on TCP port 60060 on localhost.
But what about the Unix domain socket path? To find out, I set the server.remote.connections parameter to 0 and try it out:
What happened? Looking around, it is found that GOODS has created a Unix domain socket at "/tmp/localhost:60060". Yes, ":60060" is part of the socket's path name. Cute. Trying to use a more descriptive name like "goodsock" or whatever fails with "bad address". Hitting the GOODS source, unisock.cxx shows that that unix_socket_dir is hardcoded to "/tmp/", and that the file name format has to be "string:number".
Oh well. I've abstracted the procedure to obtain a Unix domain socket address from a path string from my previous post as follows:
However, asking for a Unix domain socket address for "/tmp/localhost:60060" causes primGetAddressInfoHost:blah:blah: to fail. Bummer.
Okay, it is easier to modify GOODS since I've been browsing its source, then to get well-acquainted with SocketPlugin. So, at line 107 of unisock.cxx, make this change:
The commented out line is the original. "hostname" is "address" minus the colon and port number that comes after it.
Rebuild GOODS, change the path in test.cfg to say "goodserver:60060", restart, and we see that the Unix domain socket is now called "/tmp/goodserver" and "NetNameResolver addressForSocketPath: '/tmp/goodserver'" duly returns a SocketAddress instance.
Next, load the Squeak/Pharo GOODS client from SS3. Subclass KKSqueakTCPSocketTransport as KKPharoIPCSocketTransport, with the single method:
Some other corresponding modifications are needed, such as in KKDatabase and KKConnection. Finally, in workspace, run this:
And it works!
Running "self logout" in the KKDatabase instance explorer from above results in additional output from GOODS:
A Unix domain socket "or IPC (inter-process communication) socket is a data communications endpoint for exchanging data between processes executing within the same host operating system."
The Squeak/Pharo VM's socket plugin has had support for Unix domain sockets, as per SocketPrims.pdf, written by Ian Piumarta, dated 2007, "The old API assumes 32-bit INET4 (host) addresses and numbered service (port) addresses throughought. The new API supports arbitray host address sizes and both numbered and symbolic host and service names. [...] SQ_SOCKET_FAMILY_LOCAL The lookup should only find local (some- times called "Unix") domain host addresses. In this case, the host name should be empty and the service name should be a path to a node in the filesystem associated with a named socket."
And in code, platforms/unix/plugins/SocketPlugin/sqUnixSocket.c:
On the Smalltalk side, the Socket class has no support though. The key part is in the following fragment in "Socket>>initialize":
Socket>>primSocketCreateNetwork:type:receiveBufferSize:sendBufSize:semdIndex: comments, "Return a new socket handle for a socket of the given type and buffer sizes. Return nil if socket creation fails. The netType parameter is platform dependent and can be used to encode both the protocol type (IP, Xerox XNS, etc.) and/or the physical network interface to use if this host is connected to multiple networks. A zero netType means to use IP protocols and the primary (or only) network interface."
Meaning, this bit "primSocketCreateNetwork: 0" hardcodes the use of TCP/IP. Easy enough to fix; let's rename Socket>>initialize to Socket>>initialize:withDomain:, changing the key part:
Change Socket>>initialize to preserve the default behaviour:
Next, create Socket class>>newIPC like this:
Here "TCPSocketType" really means SOCK_STREAM in the Unix C API parlance.
We'll need Socket>>connectTo: as well:
Now, how to get a Unix domain socket address? After some experimentation, this works:
To test, use some known-working Unix domain socket test programs. The following is a slightly modified, rather self-explanatory Python server from here:
There is a corresponding client program. Run the two to verify that the server works.
Back to Smalltalk, the following code run in a workspace will connect to above Python server, send, receive, then print "Hello, from Smalltalk!" on the transcript. Tested on OSX and Linux with Pharo 2.0.