qmsk/net/socket/address.pxd
changeset 49 e2f79e68418a
parent 46 64b4ffb44754
--- a/qmsk/net/socket/address.pxd	Tue Sep 01 00:08:02 2009 +0300
+++ b/qmsk/net/socket/address.pxd	Fri Sep 25 21:34:04 2009 +0300
@@ -6,43 +6,9 @@
         endpoint    - human-readable network address, corresponding to multiple sockaddr's
 """
 
-cimport qmsk.net.libc as libc
-
 cimport qmsk.net.socket.platform as platform
 
-cdef class sockaddr :
-    """
-        A network-level socket address
-        
-        XXX: not abstract enough. Functions/properties like getnameinfo/addr/port do not work for e.g. sockaddr_un
-
-        >>> sockaddr().family
-        0
-        >>> sockaddr().port
-        Traceback (most recent call last):
-          ...
-        NotImplementedError
-        >>> sockaddr().getnameinfo()
-        Traceback (most recent call last):
-          ...
-        NotImplementedError
-    """
-    
-    # address family
-    # XXX: this should be a class constant! It's part of our type safety!
-    cdef readonly platform.sa_family_t family
-
-    cdef void _init_family (self, platform.sa_family_t family = ?)
-
-    # get the sockaddr/socklen
-    # each of these can be NULL to ignore it
-    cdef int _get_sockaddr (self, platform.sockaddr **sa_ptr, platform.socklen_t *sa_len) except -1
-
-    cdef platform.sockaddr* _get_sockaddr_ptr (self) except NULL
-    cdef platform.socklen_t _get_sockaddr_len (self) except -1
-    
-    # set the sockaddr, socklen must match
-    cdef int _set_sockaddr (self, platform.sockaddr *sa, size_t sa_len) except -1
+from qmsk.net.socket._address cimport sockaddr
 
 # build a sockaddr from the given sockaddr struct, based on sa_family
 cdef sockaddr build_sockaddr (platform.sockaddr *sa, size_t sa_len)
@@ -82,17 +48,13 @@
 
 cdef class endpoint :
     """
-        A network-level socket endpoint. This is the level that humans mostly work with, but the tricky bit is that
-        an endpoint can map to more than one sockaddr...
+        XXX: silly abstraction, just use the getaddrinfo function
 
-        Hence, endpoints are stored as human-readable hostname/service strings, which are then translated to sockaddrs
-        using getaddrinfo.
-
-        >>> from __future__ import absolute_import; import socket as _socket
+        >>> from qmsk.net.socket.constants import *
         >>> e = endpoint('127.0.0.1', 80)
         >>> str(e)
         'hostname=127.0.0.1, service=80'
-        >>> res = e.getaddrinfo(_socket.AF_UNSPEC, _socket.SOCK_STREAM)
+        >>> res = e.getaddrinfo(AF_UNSPEC, SOCK_STREAM)
         >>> len(res)
         1
         >>> str(res[0])
@@ -100,7 +62,7 @@
         >>> e = endpoint('2001::5', 80)
         >>> str(e)
         'hostname=2001::5, service=80'
-        >>> res = e.getaddrinfo(_socket.AF_UNSPEC, _socket.SOCK_STREAM)
+        >>> res = e.getaddrinfo(AF_UNSPEC, SOCK_STREAM)
         >>> len(res)
         1
         >>> str(res[0])