aboutsummaryrefslogtreecommitdiff
path: root/src/algebra
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2008-10-24 06:40:59 +0000
committerdos-reis <gdr@axiomatics.org>2008-10-24 06:40:59 +0000
commit3d4576ed847bfd84b3befaf7c5ae7ee62905ab2a (patch)
treee524e5791d71b812475aa2337690a7eb8a3c58b0 /src/algebra
parentecfc24269ea4455ec9c17a8fe5e45023e61fc7c0 (diff)
downloadopen-axiom-3d4576ed847bfd84b3befaf7c5ae7ee62905ab2a.tar.gz
Add basic support for stream client socket.
* lib/sockio-c.c (oa_inet_pton): Define. (oa_get_host_address): Likewise. * algebra/net.spad.pamphlet (IP4Address): New. (NetworkClientSocket): Likewise. (InetClientStreamSocket): Likewise. * algebra/data.spad.pamphlet (DataArray): Rename from DataBuffer. (ByteBuffer): Rename from ByteArray. Reimplement. * algebra/exposed.lsp.pamphlet: Expose IP4Address, InetClientStreamSocket, NetworkClientSocket.
Diffstat (limited to 'src/algebra')
-rw-r--r--src/algebra/Makefile.in11
-rw-r--r--src/algebra/Makefile.pamphlet11
-rw-r--r--src/algebra/array1.spad.pamphlet6
-rw-r--r--src/algebra/data.spad.pamphlet117
-rw-r--r--src/algebra/exposed.lsp.pamphlet7
-rw-r--r--src/algebra/net.spad.pamphlet120
6 files changed, 234 insertions, 38 deletions
diff --git a/src/algebra/Makefile.in b/src/algebra/Makefile.in
index 2bf2dc80..130b228f 100644
--- a/src/algebra/Makefile.in
+++ b/src/algebra/Makefile.in
@@ -376,7 +376,7 @@ axiom_algebra_layer_1 = \
PATAB PPCURVE PSCURVE REAL RESLATC RETRACT \
RETRACT- SEGCAT BINDING BMODULE LOGIC \
LOGIC- EVALAB EVALAB- FEVALAB FEVALAB- BYTE \
- OSGROUP MAYBE DATABUF PROPLOG
+ OSGROUP MAYBE DATAARY PROPLOG
axiom_algebra_layer_1_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_1))
@@ -550,7 +550,7 @@ axiom_algebra_layer_11_objects = \
axiom_algebra_layer_12 = \
DIOPS DIOPS- DIAGG DIAGG- BITS DIRPROD2 IMATRIX \
IVECTOR LPOLY LSMP LSMP1 MATCAT2 PTCAT TRIMAT \
- FSAGG FSAGG- SYSTEM BYTEARY HOSTNAME PORTNUM
+ FSAGG FSAGG- SYSTEM HOSTNAME PORTNUM
axiom_algebra_layer_12_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_12))
@@ -652,7 +652,7 @@ axiom_algebra_layer_15 = \
FRAMALG FRAMALG- MDAGG ODPOL \
PLOT RMCAT2 ROIRC SDPOL \
SMATCAT SMATCAT- TUBETOOL UPXSCCA \
- UPXSCCA- JAVACODE POLY
+ UPXSCCA- JAVACODE POLY BYTEBUF
axiom_algebra_layer_15_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_15))
@@ -827,7 +827,7 @@ axiom_algebra_layer_user = \
CASEAST HASAST ISAST CATAST WHEREAST COMMAAST \
QQUTAST DEFAST MACROAST SPADXPT SPADAST \
INBFILE OUTBFILE IOBFILE RGBCMDL RGBCSPC CTORKIND \
- CTOR
+ CTOR IP4ADDR NETCLT INETCLTS
axiom_algebra_layer_user_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_user))
@@ -893,6 +893,9 @@ IOBFILE.NRLIB/code.$(FASLEXT): $(OUT)/INBFILE.$(FASLEXT) \
CTOR.NRLIB/code.$(FASLEXT): $(OUT)/CTORKIND.$(FASLEXT) \
$(OUT)/IDENT.$(FASLEXT)
+NETCLT.NRLIB/code.$(FASLEXT): $(OUT)/IOBCON.$(FASLEXT)
+INETCLTS.NRLIB/code.$(FASLEXT): $(OUT)/NETCLT.$(FASLEXT)
+
.PHONY: all all-algebra mkdir-output-directory
all: all-ax
diff --git a/src/algebra/Makefile.pamphlet b/src/algebra/Makefile.pamphlet
index 16cb9d93..1a960216 100644
--- a/src/algebra/Makefile.pamphlet
+++ b/src/algebra/Makefile.pamphlet
@@ -219,7 +219,7 @@ axiom_algebra_layer_1 = \
PATAB PPCURVE PSCURVE REAL RESLATC RETRACT \
RETRACT- SEGCAT BINDING BMODULE LOGIC \
LOGIC- EVALAB EVALAB- FEVALAB FEVALAB- BYTE \
- OSGROUP MAYBE DATABUF PROPLOG
+ OSGROUP MAYBE DATAARY PROPLOG
axiom_algebra_layer_1_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_1))
@@ -545,7 +545,7 @@ axiom_algebra_layer_11_objects = \
axiom_algebra_layer_12 = \
DIOPS DIOPS- DIAGG DIAGG- BITS DIRPROD2 IMATRIX \
IVECTOR LPOLY LSMP LSMP1 MATCAT2 PTCAT TRIMAT \
- FSAGG FSAGG- SYSTEM BYTEARY HOSTNAME PORTNUM
+ FSAGG FSAGG- SYSTEM HOSTNAME PORTNUM
axiom_algebra_layer_12_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_12))
@@ -788,7 +788,7 @@ axiom_algebra_layer_15 = \
FRAMALG FRAMALG- MDAGG ODPOL \
PLOT RMCAT2 ROIRC SDPOL \
SMATCAT SMATCAT- TUBETOOL UPXSCCA \
- UPXSCCA- JAVACODE POLY
+ UPXSCCA- JAVACODE POLY BYTEBUF
axiom_algebra_layer_15_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_15))
@@ -1254,7 +1254,7 @@ axiom_algebra_layer_user = \
CASEAST HASAST ISAST CATAST WHEREAST COMMAAST \
QQUTAST DEFAST MACROAST SPADXPT SPADAST \
INBFILE OUTBFILE IOBFILE RGBCMDL RGBCSPC CTORKIND \
- CTOR
+ CTOR IP4ADDR NETCLT INETCLTS
axiom_algebra_layer_user_nrlibs = \
$(addsuffix .NRLIB/code.$(FASLEXT),$(axiom_algebra_layer_user))
@@ -1319,6 +1319,9 @@ IOBFILE.NRLIB/code.$(FASLEXT): $(OUT)/INBFILE.$(FASLEXT) \
CTOR.NRLIB/code.$(FASLEXT): $(OUT)/CTORKIND.$(FASLEXT) \
$(OUT)/IDENT.$(FASLEXT)
+
+NETCLT.NRLIB/code.$(FASLEXT): $(OUT)/IOBCON.$(FASLEXT)
+INETCLTS.NRLIB/code.$(FASLEXT): $(OUT)/NETCLT.$(FASLEXT)
@
\section{Broken Files}
diff --git a/src/algebra/array1.spad.pamphlet b/src/algebra/array1.spad.pamphlet
index 74039ad1..2d1d3a27 100644
--- a/src/algebra/array1.spad.pamphlet
+++ b/src/algebra/array1.spad.pamphlet
@@ -368,10 +368,8 @@ IndexedOneDimensionalArray(S:Type, mn:Integer):
OneDimensionalArrayAggregate S == add
Qmax ==> QVMAXINDEX$Lisp
Qsize ==> QVSIZE$Lisp
--- Qelt ==> QVELT$Lisp
--- Qsetelt ==> QSETVELT$Lisp
- Qelt ==> ELT$Lisp
- Qsetelt ==> SETELT$Lisp
+ Qelt ==> QVELT$Lisp
+ Qsetelt ==> QSETVELT$Lisp
-- Qelt1 ==> QVELT_-1$Lisp
-- Qsetelt1 ==> QSETVELT_-1$Lisp
Qnew ==> GETREFV$Lisp
diff --git a/src/algebra/data.spad.pamphlet b/src/algebra/data.spad.pamphlet
index 9a62ec4a..10fb2431 100644
--- a/src/algebra/data.spad.pamphlet
+++ b/src/algebra/data.spad.pamphlet
@@ -66,54 +66,137 @@ Byte(): Public == Private where
@
-\section{The ByteArray domain}
+\section{The ByteBuffer domain}
-<<domain BYTEARY ByteArray>>=
-import PrimitiveArray
+<<domain BYTEBUF ByteBuffer>>=
import Byte
-)abbrev domain BYTEARY ByteArray
+)abbrev domain BYTEBUF ByteBuffer
++ Author: Gabriel Dos Reis
++ Date Created: April 19, 2008
++ Related Constructor:
++ Description:
-++ ByteArray provides datatype for fix-sized buffer of bytes.
-ByteArray() == PrimitiveArray Byte
+++ ByteBuffer provides datatype for buffers of bytes. This domain
+++ differs from PrimitiveArray Byte in that it has it is not as rigid
+++ as PrimitiveArray Byte is. That is, the typical use of
+++ ByteBuffer is to pre-allocate a vector of Byte of some capacity
+++ `c'. The array can then store up to `c' bytes. The actual
+++ interesting bytes count (the length of the buffer) is therefore
+++ different from the capacity. The length is no more than the
+++ capacity, but it can be set dynamically as needed. This
+++ functionality is used for example when reading bytes from
+++ input/output devices where we use buffers to transfer data in and
+++ out of the system.
+++ Note: a value of type ByteBuffer is 0-based indexed, as opposed
+++ Vector, but not unlike PrimitiveArray Byte.
+ByteBuffer(): Public == Private where
+ Public == Join(OneDimensionalArrayAggregate Byte, CoercibleTo String) with
+ byteBuffer: NonNegativeInteger -> %
+ ++ byteBuffer(n) creates a buffer of capacity n, and length 0.
+ _#: % -> NonNegativeInteger
+ ++ #buf returns the number of active elements in the buffer.
+ capacity: % -> NonNegativeInteger
+ ++ capacity(buf) returns the pre-allocated maximum size of `buf'.
+ setLength!: (%,NonNegativeInteger) -> NonNegativeInteger
+ ++ setLength!(buf,n) sets the number of active bytes in the
+ ++ `buf'. Error if `n' is more than the capacity.
+ Private == add
+ byteBuffer n ==
+ buf := makeByteBuffer(n)$Lisp
+ setLength!(buf,0)
+ buf
+
+ empty() == byteBuffer 0
+
+ new(n,b) == makeByteBuffer(n,b)$Lisp
+
+ qelt(buf,i) ==
+ AREF(buf,i)$Lisp
+
+ elt(buf: %,i: Integer) ==
+ i >= capacity buf => error "index out of range"
+ qelt(buf,i)
+
+ qsetelt!(buf,i,b) ==
+ SETF(AREF(buf,i)$Lisp,b)$Lisp
+
+ setelt(buf: %,i: Integer, b: Byte) ==
+ i >= capacity buf => error "index out of range"
+ qsetelt!(buf,i,b)
+
+ capacity buf == ARRAY_-DIMENSION(buf,0)$Lisp
+
+ minIndex buf == 0
+
+ maxIndex buf == capacity(buf)::Integer - 1
+
+ # buf == LENGTH(buf)$Lisp
+
+ x = y ==
+ EQUAL(x,y)$Lisp
+
+ setLength!(buf,n) ==
+ n > capacity buf =>
+ error "attempt to set length higher than capacity"
+ SETF(FILL_-POINTER(buf)$Lisp,n)$Lisp
+
+ coerce(buf: %): String ==
+ s: String := MAKE_-STRING(#buf)$Lisp
+ for i in 0..(#buf - 1) repeat
+ qsetelt!(s,i + 1,qelt(buf,i)::Character)$String
+ s
+
+ construct l ==
+ buf := byteBuffer(#l)
+ for b in l for i in 0.. repeat
+ buf.i := b
+ buf
+
+ concat(x: %, y:%) ==
+ nx := #x
+ ny := #y
+ buf := byteBuffer(nx + ny)
+ for i in 0..(nx - 1) repeat
+ buf.i := x.i
+ for i in 0..(ny - 1) repeat
+ buf.(nx + i) := y.i
+ buf
+
@
-\section{The DataBuffer domain}
+\section{The DataArray domain}
-<<domain DATABUF DataBuffer>>=
-)abbrev domain DATABUF DataBuffer
+<<domain DATAARY DataArray>>=
+)abbrev domain DATAARY DataArray
++ Author: Gabriel Dos Reis
++ Date Created: August 23, 2008
++ Description:
++ This domain provides for a fixed-sized homogeneous data buffer.
-DataBuffer(N: PositiveInteger, T: SetCategory): Public == Private where
+DataArray(N: PositiveInteger, T: SetCategory): Public == Private where
Public == SetCategory with
new: () -> %
++ new() returns a fresly allocated data buffer or length N.
- elt: (%,NonNegativeInteger) -> T
+ qelt: (%,NonNegativeInteger) -> T
++ elt(b,i) returns the ith element in buffer `b'. Indexing
++ is 0-based.
- setelt: (%,NonNegativeInteger,T) -> T
+ qsetelt: (%,NonNegativeInteger,T) -> T
++ setelt(b,i,x) sets the ith entry of data buffer `b' to `x'.
++ Indexing is 0-based.
Private == add
new() ==
makeSimpleArray(getVMType(T)$Lisp,N)$Lisp
- elt(b,i) ==
+ qelt(b,i) ==
getSimpleArrayEntry(b,i)$Lisp
- setelt(b,i,x) ==
+ qsetelt(b,i,x) ==
setSimpleArrayEntry(b,i,x)$Lisp
x = y ==
EQUAL(x,y)$Lisp
coerce(b: %): OutputForm ==
- bracket([elt(b,i)::OutputForm for i in 0..(N-1)])
+ bracket([qelt(b,i)::OutputForm for i in 0..(N-1)])
@
@@ -155,7 +238,9 @@ DataBuffer(N: PositiveInteger, T: SetCategory): Public == Private where
<<*>>=
<<license>>
<<domain BYTE Byte>>
-<<domain BYTEARY ByteArray>>
+<<domain BYTEBUF ByteBuffer>>
+<<domain DATAARY DataArray>>
+
@
\end{document}
diff --git a/src/algebra/exposed.lsp.pamphlet b/src/algebra/exposed.lsp.pamphlet
index 615657c9..4b434a9d 100644
--- a/src/algebra/exposed.lsp.pamphlet
+++ b/src/algebra/exposed.lsp.pamphlet
@@ -76,7 +76,7 @@
(|Bits| . BITS)
(|Boolean| . BOOLEAN)
(|Byte| . BYTE)
- (|ByteArray| . BYTEARY)
+ (|ByteBuffer| . BYTEBUF)
(|CallAst| . CALLAST)
(|CapsuleAst| . CAPSLAST)
(|CardinalNumber| . CARD)
@@ -108,7 +108,7 @@
(|CRApackage| . CRAPACK)
(|CycleIndicators| . CYCLES)
(|Database| . DBASE)
- (|DataBuffer| . DATABUF)
+ (|DataArray| . DATABUF)
(|DataList| . DLIST)
(|DecimalExpansion| . DECIMAL)
(|DefinitionAst| . DEFAST)
@@ -216,6 +216,7 @@
(|InventorViewPort| . IVVIEW)
(|InventorRenderPackage| . IVREND)
(|InverseLaplaceTransform| . INVLAPLA)
+ (|IP4Address| . IP4ADDR)
(|IrrRepSymNatPackage| . IRSN)
(|IsAst| . ISAST)
(|JavaBytecode| . JAVACODE)
@@ -261,6 +262,7 @@
(|MultivariateFactorize| . MULTFACT)
(|MultivariatePolynomial| . MPOLY)
(|MultFiniteFactorize| . MFINFACT)
+ (|InetClientStreamSocket| . INETCLTS)
(|NoneFunctions1| . NONE1)
(|NonNegativeInteger| . NNI)
(|NormalizationPackage| . NORMPK)
@@ -689,6 +691,7 @@
(|MultiDictionary| . MDAGG)
(|MultisetAggregate| . MSETAGG)
(|MultivariateTaylorSeriesCategory| . MTSCAT)
+ (|NetworkClientSocket| . NETCLT)
(|NonAssociativeAlgebra| . NAALG)
(|NonAssociativeRing| . NASRING)
(|NonAssociativeRng| . NARNG)
diff --git a/src/algebra/net.spad.pamphlet b/src/algebra/net.spad.pamphlet
index ba8bfdc7..a216a5fb 100644
--- a/src/algebra/net.spad.pamphlet
+++ b/src/algebra/net.spad.pamphlet
@@ -44,16 +44,16 @@ InputByteConduit(): Category == Conduit with
++ Note: Ideally, the return value should have been of type
++ Maybe Byte; but that would have implied allocating
++ a cons cell for every read attempt, which is overkill.
- readBytes!: (%,ByteArray) -> SingleInteger
+ readBytes!: (%,ByteBuffer) -> SingleInteger
++ readBytes!(c,b) reads byte sequences from conduit `c' into
++ the byte buffer `b'. The actual number of bytes written
++ is returned.
add
- readBytes!(cond,ary) ==
+ readBytes!(cond,buf) ==
count: SingleInteger := 0
b : SingleInteger
- while count < #ary and ((b := readByteIfCan! cond) >= 0) repeat
- qsetelt!(ary,count,b : Byte)
+ while count < capacity buf and ((b := readByteIfCan! cond) >= 0) repeat
+ qsetelt!(buf,count,b : Byte)
count := count + 1
count
@@ -76,15 +76,15 @@ OutputByteConduit(): Category == Conduit with
++ Note: Ideally, the return value should have been of type
++ Maybe Byte; but that would have implied allocating
++ a cons cell for every write attempt, which is overkill.
- writeBytes!: (%,ByteArray) -> SingleInteger
+ writeBytes!: (%,ByteBuffer) -> SingleInteger
++ writeBytes!(c,b) write bytes from buffer `b'
++ onto the conduit `c'. The actual number of written
++ bytes is returned.
add
- writeBytes!(cond,ary) ==
+ writeBytes!(cond,buf) ==
count: SingleInteger := 0
- while count < #ary and
- writeByteIfCan!(cond,qelt(ary,count)) >= 0 repeat
+ while count < capacity buf and
+ writeByteIfCan!(cond,qelt(buf,count)) >= 0 repeat
count := count + 1
count
@@ -284,6 +284,106 @@ PortNumber(): Public == Private where
@
+\section{The IP4Address domain}
+
+<<domain IP4ADDR IP4Address>>=
+)abbrev domain IP4ADDR IP4Address
+++ Author: Gabriel Dos Reis
+++ Date Created: October 22, 2008
+++ Date Last Modified: October 22, 2008
+++ Description:
+++ This domain provides representation for ARPA Internet IP4 addresses.
+IP4Address(): Public == Private where
+ Public == SetCategory with
+ ip4Address: String -> %
+ ++ ip4Address(a) builds a numeric address out of the ASCII form `a'.
+ bytes: % -> DataArray(4,Byte)
+ ++ bytes(x) returns the bytes of the numeric address `x'.
+ resolve: Hostname -> Union(%,"failed")
+ ++ resolve(h) returns the IP4 address of host `h'.
+ Private == add
+ Rep == DataArray(4,Byte)
+ ip4Address a ==
+ n := new()$Rep
+ presentationToNumeric(a,4,n)$Lisp = 0@SingleInteger => per n
+ userError "invalid Internet IP4 address"
+ resolve h ==
+ n := new()$Rep
+ hostnameToNumeric(h::String,4,n)$Lisp = 0@SingleInteger => per n
+ "failed"
+ bytes x == rep x
+ x = y == rep x = rep y
+ coerce(x: %): OutputForm ==
+ infix('_.::OutputForm,
+ [qelt(rep x,i)::OutputForm for i in 0..3])$OutputForm
+@
+
+
+\section{The NetworkClientSocket category}
+
+<<category NETCLT NetworkClientSocket>>=
+)abbrev category NETCLT NetworkClientSocket
+NetworkClientSocket(T: SetCategory): Category == InputOutputByteConduit with
+ connectTo: (T, PortNumber) -> Union(%,"failed")
+ isConnected?: % -> Boolean
+@
+
+
+\section{The InetClientStreamSocket domain}
+
+<<domain INETCLTS InetClientStreamSocket>>=
+)abbrev domain INETCLTS InetClientStreamSocket
+InetClientStreamSocket(): Public == Private where
+ Public == Join(NetworkClientSocket IP4Address, CoercibleTo OutputForm) with
+ connectTo: (Hostname, PortNumber) -> Union(%,"failed")
+ Private == add
+ -- we hope that a small integer is OK on all platform
+ Host == Union(IP4Address,Hostname)
+ Rep == Record(%host: Host, %port: PortNumber, %sock: SingleInteger)
+
+ connectTo(ip: IP4Address, p: PortNumber) ==
+ s: SingleInteger := connectToHostAndPort(ip,4,p)$Lisp
+ s = -1::SingleInteger => "failed"
+ per [ip::Host,p,s]
+
+ connectTo(h: Hostname, p: PortNumber) ==
+ (ip := resolve(h)$IP4Address) case "failed" => "failed"
+ s: SingleInteger := connectToHostAndPort(ip::IP4Address,4,p)$Lisp
+ s = -1::SingleInteger => "failed"
+ per [h::Host,p,s]
+
+ isConnected? s ==
+ rep(s).%sock ~= -1::SingleInteger
+
+ readBytes!(x,b) ==
+ n: SingleInteger :=
+ readFromStreamSocket(rep(x).%sock,b, capacity b)$Lisp
+ if n <= 0 then close! x
+ else setLength!(b,n : NonNegativeInteger)
+ n
+
+ writeBytes!(x,b) ==
+ n: SingleInteger :=
+ writeToStreamSocket(rep(x).%sock,b, capacity b)$Lisp
+ if n <= 0 then close! x
+ else setLength!(b,n : NonNegativeInteger)
+ n
+
+ close! x ==
+ closeSocket(rep(x).%sock)$Lisp
+ rep(x).%sock := -1::SingleInteger
+ x
+
+ coerce(x: %): OutputForm ==
+ x' := rep x
+ h :=
+ x'.%host case IP4Address => x'.%host::IP4Address::OutputForm
+ x'.%host::Hostname::OutputForm
+ infix('_:::OutputForm,h,x'.%port::OutputForm)$OutputForm
+
+@
+
+
\section{License}
@@ -328,6 +428,7 @@ PortNumber(): Public == Private where
<<category INBCON InputByteConduit>>
<<category OUTBCON OutputByteConduit>>
<<category IOBCON InputOutputByteConduit>>
+<<category NETCLT NetworkClientSocket>>
<<domain INBFILE InputBinaryFile>>
<<domain OUTBFILE OutputBinaryFile>>
@@ -335,6 +436,9 @@ PortNumber(): Public == Private where
<<domain HOSTNAME Hostname>>
<<domain PORTNUM PortNumber>>
+<<domain IP4ADDR IP4Address>>
+
+<<domain INETCLTS InetClientStreamSocket>>
@