chiark / gitweb /
codec.pyx: New flag from upstream.
[mLib-python] / fdutils.pyx
CommitLineData
5b1830f3
MW
1### -*-pyrex-*-
2###
3### Messing with file descriptors
4###
5### (c) 2007 Straylight/Edgeware
6###
ae68e889 7
5b1830f3
MW
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of the Python interface to mLib.
11###
12### mLib/Python is free software; you can redistribute it and/or modify
13### it under the terms of the GNU General Public License as published by
14### the Free Software Foundation; either version 2 of the License, or
15### (at your option) any later version.
16###
17### mLib/Python is distributed in the hope that it will be useful,
18### but WITHOUT ANY WARRANTY; without even the implied warranty of
19### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20### GNU General Public License for more details.
21###
22### You should have received a copy of the GNU General Public License
23### along with mLib/Python; if not, write to the Free Software Foundation,
24### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ae68e889
MW
25
26def fdflags(file,
27 unsigned fbic = 0, unsigned fxor = 0,
28 unsigned fdbic = 0, unsigned fdxor = 0):
29 cdef int rc
30 rc = _fdflags(_getfd(fd), fbix, fxor, fdbic, fdxor)
31 if rc < 0:
32 _oserror()
33 return rc
34
35def fdsend(sock, file, buffer):
36 cdef void *p
37 cdef int len
38 cdef int rc
39 PyObject_AsReadBuffer(buffer, &p, &len)
40 rc = fdpass_send(_getfd(sock), _getfd(file), p, len)
41 if rc < 0:
42 _oserror()
43 return rc
44
45def fdrecv(sock, unsigned size):
46 cdef void *p
47 cdef buf
48 cdef int len
49 cdef PyObject *obj
50 cdef int fd
23bff39b 51 buf = PyString_FromStringAndSize(NULL, size)
ae68e889
MW
52 p = PyString_AS_STRING(buf)
53 len = fdpass_recv(_getfd(sock), &fd, p, size)
54 if len < 0:
55 _oserror()
56 obj = <PyObject *>buf
57 _PyString_Resize(&obj, len)
58 return fd, <object>obj
59
5b1830f3 60###----- That's all, folks --------------------------------------------------