author | Tero Marttila <terom@fixme.fi> |
Mon, 17 Aug 2009 20:24:12 +0300 | |
changeset 22 | f6e8d5e37998 |
parent 19 | e6b670dbfe3b |
permissions | -rw-r--r-- |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Libc stuff |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
cdef extern from "stdint.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
# yes, these are "wrong" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
ctypedef unsigned char uint8_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
ctypedef unsigned short uint16_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
ctypedef unsigned int uint32_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
ctypedef signed char int8_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
ctypedef signed short int16_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
ctypedef signed int int32_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
cdef extern from "sys/types.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
# potentially wrong... |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
ctypedef signed long ssize_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
# <linux/types.h> |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
cdef extern from "linux/types.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
ctypedef uint8_t __u8 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
ctypedef uint16_t __u16 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
ctypedef uint32_t __u32 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
ctypedef int8_t __s8 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
ctypedef int16_t __s16 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
ctypedef int32_t __s32 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
cdef extern from "errno.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
int errno |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
cdef extern from "string.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
void* memcpy (void *dest, void *src, size_t n) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
void* memset (void *s, int c, size_t n) |
22
f6e8d5e37998
some __cmp__ and doctest love for socket.address
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
35 |
int memcmp (void *s1, void *s2, size_t n) |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
char* strerror (int errno) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
12
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
39 |
cdef extern from "unistd.h" : |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
40 |
ssize_t read (int fd, void *buf, size_t count) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
41 |
ssize_t write (int fd, void *buf, size_t count) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
42 |
|
13
a1091632a8a7
implement __cinit__, shutdown, close, __dealloc__ for socket, and also add a try-except to not leak client sock from accept()
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
43 |
int close (int fd) |
a1091632a8a7
implement __cinit__, shutdown, close, __dealloc__ for socket, and also add a try-except to not leak client sock from accept()
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
44 |
|
19 | 45 |
cdef extern from "fcntl.h" : |
46 |
int fcntl (int fd, int cmd, ...) |
|
47 |
||
48 |
enum : |
|
49 |
F_GETFL |
|
50 |
F_SETFL |
|
51 |
||
52 |
enum : |
|
53 |
O_NONBLOCK |
|
54 |
||
55 |
# set a specific flag(s) to the given value |
|
56 |
cdef fcntl_set_flag (int fd, int flag, bint value) |
|
57 |
||
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
cdef extern from "alloca.h" : |
14
c44754cc1ffe
some recv magic, still no PyString_Resize, though
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
59 |
# XXX: this is unsafe because there is it may fail nastily for allocations that won't fit on the stack - SIGSEGV |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
void* alloca (size_t size) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
cdef extern from "sys/uio.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
struct iovec : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
void *iov_base |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
size_t iov_len |
12
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
66 |
|
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
67 |
ssize_t readv (int fd, iovec *iov, int iovcnt) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
68 |
ssize_t writev (int fd, iovec *iov, int iovcnt) |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
## general errno-based errors |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
#cdef class Errno (py.OSError) : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
# Some libc function returned an error code: |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
# func - the name of the function called |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
# err - the system error code |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
# strerror - human-readable error code -> message |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
# cdef readonly char *func |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
# cdef readonly int err |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
# cdef readonly object strerror |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
#cdef class GAIError (py.OSError) : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
# Some libc GAI function returnd an error code: |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
# func - the name of the function called |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
# err - the GAI_* error code |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
# strerror - human-readable error code -> message |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
# cdef readonly char *func |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
# cdef readonly int err |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
# cdef readonly object strerror |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
# |