[
https://issues.apache.org/jira/browse/THRIFT-900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915622#action_12915622
]
Christian Lavoie commented on THRIFT-900:
-----------------------------------------
Ok, I looked into this some more, I think you've got a few mugs when computing
addrlen to pass to {{bind}}:
# {{sprintf}} does NOT take into account the trailing \0 (at least you have an
off-by-one error here)
# you're manually the length of {{sun_path}} and {{sun_family}} instead of
calling {{sizeof}} -- which means you're missing out on other fields in the
struct, or for that matter, padding between fields
# using an {{int}} instead of {{socklen_t}} to hold the length of the socket
address (minor, but while you're at it...)
I changed the {{TServerSocket.cpp}} code thusly, which works on both my Mac and
my Linux virtual machine:
{noformat}
257 if (! path_.empty()) {
258 // Unix Domain Socket
259 struct sockaddr_un address;
260 socklen_t len;
261
262 if (path_.length() > sizeof(address.sun_path)) {
263 int errno_copy = errno;
264 GlobalOutput.perror("TSocket::listen() Unix Domain socket path too
long", errno_copy);
265 throw TTransportException(TTransportException::NOT_OPEN, " Unix
Domain socket path too long");
266 }
267
268 address.sun_family = AF_UNIX;
269 sprintf(address.sun_path, path_.c_str());
270 len = sizeof(address);
271 std::cerr << len << ": address.sun_path(" << address.sun_path << ")
path_(" << path_ << ")" << std::endl;
{noformat}
As it happens, it's also what my copy of Stevens says in its example for using
{{bind}} on {{AF_UNIX}} sockets with regards to {{addrlen}}.
The linux box (amd64 virtual machine) says:
{noformat}
$ ./server.linux /tmp/sock123
Starting the server...
TServerSocket::listen() IPV6_V6ONLY Operation not supported on socket
106: address.sun_path(/tmp/sock123) path_(/tmp/sock123)
{noformat}
and the mac (10.6, x86):
{noformat}
$ ./server.mac /tmp/sock123
Starting the server...
TServerSocket::listen() IPV6_V6ONLY Operation not supported on socket
110: address.sun_path(/tmp/sock123) path_(/tmp/sock123)
{noformat}
Not sure why they socket structure is of different length -- but it illustrates
my point above: doing it by hand is not an optimal approach.
> Unix domain socket
> ------------------
>
> Key: THRIFT-900
> URL: https://issues.apache.org/jira/browse/THRIFT-900
> Project: Thrift
> Issue Type: New Feature
> Components: C++ - Library
> Environment: Debian GNU/Linux Lenny
> Reporter: Roger Meier
> Fix For: 0.6
>
> Attachments: THRIFT-900_UnixDomainSockets.v2.patch,
> THRIFT-900_UnixDomainSockets.v3.patch, THRIFT-900_UnixDominSockets.patch
>
>
> I would like to use Unix domain sockets.
> client side:
> {code}
> shared_ptr<TSocket> socket(new TSocket("/tmp/ThriftTest.binary.thrift"));
> // as alternative to
> shared_ptr<TSocket> socket(new TSocket(host, port));
> {code}
> server side:
> {code}
> shared_ptr<TServerSocket> serverSocket(new
> TServerSocket("/tmp/ThriftTest.binary.thrift"));
> // as alternative to
> shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
> {code}
> further enhancement might be:
> use a RFC 3986 compliant URI parser e.g. by using
> http://uriparser.sourceforge.net/ (BSD License)
> and pass a real URI to the constructor, e.g.
> file:///tmp/ThriftTest.binary.thrift
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.