Intro

fdsend is yet another file descriptor passing abstraction, specifically for Python. This package offers a few conveniences not commonly found together in other abstractions: sending multiple files at once, sending arbitrary data, and working with both files and file descriptors.

fdsend is free software, licensed under the GPL.

Requirements and Download

Python >= 2.2 is required, as is SCM_RIGHTS support on AF_UNIX sockets. Only Linux has been tested.

The current version is fdsend-0.1 (03 Nov 2004)

Example


    import fdsend
    import socket  # for socket.error    

    # -- sender; send 12 files
    #
    nulldevs = [ file('/dev/null') for i in xrange(12) ]
    fdsend.sendfds(sock, "here you go!", fds = nulldevs)

    # -- recipient; receive up to 128-byte message, and up to 32 files
    #
    (msg, fds) = fdsend.recvfds(sock, 128, numfds = 32)
    import os
    fds = [ os.fdopen(fileno) for fileno in fds ]

    # -- exception handling
    #
    import socket
    try:
	notasock = file("/dev/null")
        fdsend.sendfds(notasock, "This won't work!")
    except socket.error, e:
        import errno
        if e[0] == errno.ENOTSOCK:
            print "What did you expect? :)"

Feedback

Report problems, bugs, feature requests, successes to me at mjp-py@pilcrow.madison.wi.us.

Related Interest

  • scgi (python) contains a passfd module.
  • This sendmsg module (python) is a mostly complete sendmsg interface.
  • Socket::MsgHdr (perl) offers a full sendmsg interface.
  • bglibs provides a variety of UNIX-ish conveniences, including a socket_sendfd function.
  • The I_SENDFD ioctl is an alternative approach for streams-based systems