ó / SPc@sÆdZddlZddlZyddlZWnek rGdZnXddlmZmZd„Z d„Z edkrŒd„Z Z nd„Z d„Z d „Z d „Zd d d dgZdS(s< Utility functions for dealing with POSIX file descriptors. iÿÿÿÿN(tCONNECTION_LOSTtCONNECTION_DONEcCs<tj|tjƒ}|tjB}tj|tj|ƒdS(sP Set the file description of the given file descriptor to non-blocking. N(tfcntltF_GETFLtost O_NONBLOCKtF_SETFL(tfdtflags((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pytsetNonBlockings cCs=tj|tjƒ}|tj@}tj|tj|ƒdS(sL Set the file description of the given file descriptor to blocking. N(RRRRR(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt setBlockingscCsdS(N(tNone(R((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt*scCs<tj|tjƒ}|tjB}tj|tj|ƒdS(s7 Make a file descriptor close-on-exec. N(RtF_GETFDt FD_CLOEXECtF_SETFD(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt_setCloseOnExec,s cCs=tj|tjƒ}|tj@}tj|tj|ƒdS(s7 Make a file descriptor close-on-exec. N(RR RR(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt_unsetCloseOnExec5scCsqytj|dƒ}Wn@ttfk rX}|jdtjtjfkrQdStSnX|sct S||ƒdS(s Read from file descriptor, calling callback with resulting data. If successful, call 'callback' with a single argument: the resulting data. Returns same thing FileDescriptor.doRead would: CONNECTION_LOST, CONNECTION_DONE, or None. @type fd: C{int} @param fd: non-blocking file descriptor to be read from. @param callback: a callable which accepts a single argument. If data is read from the file descriptor it will be called with this data. Handling exceptions from calling the callback is up to the caller. Note that if the descriptor is still connected but no data is read, None will be returned but callback will not be called. @return: CONNECTION_LOST on error, CONNECTION_DONE when fd is closed, otherwise None. i iN( RtreadtOSErrortIOErrortargsterrnotEAGAINtEINTRRR(Rtcallbacktoutputtioe((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt readFromFD>scCsTytj||ƒSWn9ttfk rO}|jtjtjfkrKdStSXdS(s> Write data to file descriptor. Returns same thing FileDescriptor.writeSomeData would. @type fd: C{int} @param fd: non-blocking file descriptor to be written to. @type data: C{str} or C{buffer} @param data: bytes to write to fd. @return: number of bytes written, or CONNECTION_LOST. iN(RtwriteRRRRRR(Rtdatatio((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyt writeToFDas R R RR (t__doc__RRRt ImportErrorR ttwisted.internet.mainRRR R RRRR t__all__(((s:/usr/lib/python2.7/dist-packages/twisted/internet/fdesc.pyts       #