def socketpair(space, family=rsocket.socketpair_default_family, type=rsocket.SOCK_STREAM, proto=0): """socketpair([family[, type[, proto]]]) -> (socket object, socket object) Create a pair of socket objects from the sockets returned by the platform socketpair() function. The arguments are the same as for socket() except the default family is AF_UNIX if defined on the platform; otherwise, the default is AF_INET. """ try: sock1, sock2 = rsocket.socketpair(family, type, proto) except SocketError, e: raise converted_error(space, e)
def test_sendfile_invalid_offset(): from rpython.rlib import rsocket s1, s2 = rsocket.socketpair() relpath = 'test_sendfile_invalid_offset' filename = str(udir.join(relpath)) fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0777) os.write(fd, 'abcdefghij') with py.test.raises(OSError) as excinfo: rposix.sendfile(s1.fd, fd, -1, 5) assert excinfo.value.errno == errno.EINVAL os.close(fd) s2.close() s1.close()
def test_sendfile(): from rpython.rlib import rsocket s1, s2 = rsocket.socketpair() relpath = 'test_sendfile' filename = str(udir.join(relpath)) fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0777) os.write(fd, 'abcdefghij') res = rposix.sendfile(s1.fd, fd, 3, 5) assert res == 5 data = os.read(s2.fd, 10) assert data == 'defgh' os.close(fd) s2.close() s1.close()
def socketpair(space, family=rsocket.socketpair_default_family, type =rsocket.SOCK_STREAM, proto =0): """socketpair([family[, type[, proto]]]) -> (socket object, socket object) Create a pair of socket objects from the sockets returned by the platform socketpair() function. The arguments are the same as for socket() except the default family is AF_UNIX if defined on the platform; otherwise, the default is AF_INET. """ try: sock1, sock2 = rsocket.socketpair(family, type, proto) except SocketError, e: raise converted_error(space, e)