changeset 164:429afd920a23

Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
author Mike Pavone <pavone@retrodev.com>
date Mon, 10 Jan 2011 00:25:35 -0500
parents 9fab36cc706b
children 1bfc19076f1b
files net.rhope
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/net.rhope	Sun Jan 09 23:03:30 2011 -0500
+++ b/net.rhope	Mon Jan 10 00:25:35 2011 -0500
@@ -296,7 +296,15 @@
 {
 	If[[buffer]Length]
 	{
-		out,err <- [con]_Write[buffer,0]
+		If[[Raw Size[[buffer]Eltype >>]] > [1]]
+		{
+			bytelen <- [[buffer]Length]*[Raw Size[[buffer]Eltype >>]]
+			//Copy to a byte buffer until we have a better way of writing from an arbitrary byte offset
+			bbuffer <- [_internal_array_copychunk[buffer, 0, _internal_array_allocnaked[bytelen, UInt8()], 0, [buffer]Length]]Length <<[bytelen]
+		}{
+			bbuffer <- Val[buffer]
+		}
+		out,err <- [con]_Write[bbuffer,0]
 	}{
 		out <- con
 	}
@@ -382,6 +390,15 @@
 	}
 }
 
+Read Type@TCP Connection[con,toread(Int32),type(Blueprint):data,out con,err]
+{
+	toreadbytes <- [toread]*[Raw Size[type]]
+	,out con,err <- [con]Read[toreadbytes]
+	{
+		data <- [_internal_array_copychunk[~, 0, _internal_array_allocnaked[toread, type], 0, toreadbytes]]Length <<[toread] 
+	}
+}
+
 _Check Partial[buffer,delim,offset:partial,none]
 {
 	none <- If[[offset]=[[buffer]Length]] {}