crossroads / crossroads / low.py

Diff from to

crossroads/low.py

 '''Low level API for ctypes binding to Crossroads.IO.'''
 
 from functools import partial
-from ctypes import byref, sizeof, c_int, c_int64, c_char_p, c_size_t
+from ctypes import byref, sizeof, c_int, c_int64, c_char, c_size_t
 
 from stuf.utils import unique_id
 from stuf.desc import Setter, lazy
-from stuf.six import OrderedDict, items, tobytes
+from stuf.six import OrderedDict, items, tobytes, isstring
 
 from . import lowest as xs
 from . import constants as XS
         elif opt_key in XS.INT64:
             opt_type = c_int64
         elif opt_key in XS.BINARY:
-            opt_type = c_char_p
+            opt_type = c_char
         else:
             raise AttributeError(
                 '{0} is not a valid socket attribute'.format(key)
 
     def _set(self, key, value):
         opt_key, opt_type = self._opt_type(key)
-        value = opt_type(value)
+        if not value  and isstring(value):
+            new_value = c_char()
+        else:
+            new_value = opt_type(value)
         self.last_rc = self._setsockopt(
             opt_key,
-            byref(value),
-            0 if opt_key == XS.SUBSCRIBE else sizeof(value),
+            byref(new_value),
+            len(value) if opt_key == XS.SUBSCRIBE else sizeof(new_value),
         )
         return self.last_rc
 
         )
         return msg
 
-    def recv(self, size, nowait=False):
-        msg = Message(size)
+    def recv(self, size, nowait=False, char=False):
+        msg = Message(size, char=char)
         msg.last_rc = self.last_rc = self._recv(
             msg.dest, msg.size, XS.DONTWAIT if nowait else 0,
         )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.