Skip to content

Instantly share code, notes, and snippets.

@rdn32
rdn32 / recv_fds.py
Last active March 28, 2016 17:19
Read file descriptors from unix domain socket
"""
recv_fds reads file descriptors from a unix domain socket. This might be useful
if you were, say, wanting to implement short-circuit reads in an HDFS client.
The code is broadly based on DomainSocketImpl::receiveFileDescriptors in libhdfs3
and Java_org_apache_hadoop_net_unix_DomainSocket_receiveFileDescriptors0
in libhadoop.
The tricky thing here is that we need to call recvmsg, which isn't exposed in
the socket module for python 2.7. However, we can access it via ctypes. I've
tried the code here out on my machine (x86_64, Ubuntu 14.14, Python 2.7.6) and
@rdn32
rdn32 / gist:5554769
Last active December 17, 2015 04:59
My solution to the webcrawler exercise in "A Tour of Go" (http://tour.golang.org/#70)The sample solution involved explicit locking, whereas my solution is purely based on communication (although the way it achieves this does seem a little bit awkward...)The assumption is that fetching things is what will take the time, so the contention on the c…
// (I've ommitted the code supplied as part of the exercise)
type crawl_result struct {
url string
depth int
body string
urls []string
err error
}