aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog16
-rw-r--r--src/algebra/net.spad.pamphlet9
-rw-r--r--src/etc/Makefile.in10
-rw-r--r--src/etc/asq.c.pamphlet1
-rw-r--r--src/include/sockio.h5
-rw-r--r--src/interp/sys-os.boot14
-rw-r--r--src/lib/sockio-c.c28
7 files changed, 81 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 1564b0ef..525b044c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,4 +1,18 @@
-2008-10-24 Alfredo Portes <doyenatccny@gmail.com>
+2008-10-24 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * interp/sys-os.boot: Import oa_socket_read_byte as
+ readByteFromStreamSocket. Import oa_socket_write_byte as
+ writeByteToStreamSocket.
+ * include/sockio.h (oa_socket_read_byte): Declare.
+ (oa_socket_write_byte): Likewise.
+ * lib/sockio-c.c (oa_socket_read_byte): Define.
+ (oa_socket_write_byte): Likewise.
+ * algebra/net.spad.pamphlet (readByteIfCan!$InetClientStreamSocket):
+ Implement.
+ (writeByteIfCan!$InetClientStreamSocket): Likewise.
+ * etc/asq.c.pamphlet: Update build rules for asq$(EXEEXT).
+
+2008-10-24 Alfredo Portes <doyenatccny@gmail.com>
* hyper/addfile.c: Use oa_getenv function.
* hyper/titlebar.c: Likewise.
diff --git a/src/algebra/net.spad.pamphlet b/src/algebra/net.spad.pamphlet
index a216a5fb..f73b278c 100644
--- a/src/algebra/net.spad.pamphlet
+++ b/src/algebra/net.spad.pamphlet
@@ -361,6 +361,10 @@ InetClientStreamSocket(): Public == Private where
if n <= 0 then close! x
else setLength!(b,n : NonNegativeInteger)
n
+ readByteIfCan! x ==
+ r: SingleInteger := readByteFromStreamSocket(rep(x).%sock)$Lisp
+ if r < 0 then close! x
+ r
writeBytes!(x,b) ==
n: SingleInteger :=
@@ -369,6 +373,11 @@ InetClientStreamSocket(): Public == Private where
else setLength!(b,n : NonNegativeInteger)
n
+ writeByteIfCan!(x,b) ==
+ r: SingleInteger := writeByteToStreamSocket(rep(x).%sock,b)$Lisp
+ if r < 0 then close! x
+ r
+
close! x ==
closeSocket(rep(x).%sock)$Lisp
rep(x).%sock := -1::SingleInteger
diff --git a/src/etc/Makefile.in b/src/etc/Makefile.in
index f34168cc..13510516 100644
--- a/src/etc/Makefile.in
+++ b/src/etc/Makefile.in
@@ -43,6 +43,12 @@ subdir = src/etc/
pamphlets = Makefile.pamphlet $(asq_SOURCES)
+build_libdir = $(top_builddir)/src/lib
+
+libspad_la = -L$(build_libdir) -lspad
+
+openaxiom_c_libs = -lopen-axiom-core @axiom_c_runtime_extra@ -lm
+
.PHONY: all all-asq
all: all-ax
@@ -81,10 +87,12 @@ bin_PROGRAMS = asq$(EXEEXT)
asq_sources = asq.c
asq_SOURCES = $(addsuffix .pamphlet, $(asq_sources))
asq_objects = $(asq_sources:.c=.$(OBJEXT))
+asq_LDADD = $(libspad_la) -L$(build_libdir) $(openaxiom_c_libs)
$(axiom_target_bindir)/asq$(EXEEXT): asq.c $(axiom_c_macros_h)
@echo making $@ from $<
- ${CC} ${CCF} $(axiom_includes) -o asq$(EXEEXT) asq.c
+ ${CC} ${CCF} $(axiom_includes) -o asq$(EXEEXT) asq.c \
+ $(asq_LDADD)
cp -p asq$(EXEEXT) $(axiom_target_bindir)
asq.c: $(srcdir)/asq.c.pamphlet
diff --git a/src/etc/asq.c.pamphlet b/src/etc/asq.c.pamphlet
index 19277b5c..034c35d3 100644
--- a/src/etc/asq.c.pamphlet
+++ b/src/etc/asq.c.pamphlet
@@ -530,6 +530,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include "openaxiom-c-macros.h"
+#include "cfuns.h"
/* we need to predeclare some functions so their signatures are known */
int printandor(char *list);
diff --git a/src/include/sockio.h b/src/include/sockio.h
index 7188f560..f618dbc4 100644
--- a/src/include/sockio.h
+++ b/src/include/sockio.h
@@ -92,10 +92,15 @@ OPENAXIOM_EXPORT int oa_get_host_address(const char*, int, openaxiom_byte*);
OPENAXIOM_EXPORT int oa_open_local_server_stream_socket(const char*);
OPENAXIOM_EXPORT openaxiom_socket
oa_connect_ip_port_stream(const openaxiom_byte*, int, openaxiom_port);
+
OPENAXIOM_EXPORT int oa_socket_write(openaxiom_socket,
const openaxiom_byte*, int);
+OPENAXIOM_EXPORT int oa_socket_write_byte(openaxiom_socket, openaxiom_byte);
+
OPENAXIOM_EXPORT int oa_socket_read(openaxiom_socket,
openaxiom_byte*, int);
+OPENAXIOM_EXPORT int oa_socket_read_byte(openaxiom_socket);
+
OPENAXIOM_EXPORT void oa_close_socket(openaxiom_socket);
OPENAXIOM_EXPORT int
diff --git a/src/interp/sys-os.boot b/src/interp/sys-os.boot
index bfa70eba..58e42706 100644
--- a/src/interp/sys-os.boot
+++ b/src/interp/sys-os.boot
@@ -126,12 +126,26 @@ import oa__get__host__address: (string, int, writeonly buffer byte) -> int
import oa__connect__ip__port__stream: (readonly buffer byte,int,int) -> int
for connectToHostAndPort
+++ Try to read bytes of data from socket.
+++ Return -1 for failure; number of read bytes, otherwise.
import oa__socket__read: (int,writeonly buffer byte,int) -> int
for readFromStreamSocket
+
+++ Try to read a byte socket from a socket.
+++ Return -1 on failure; byte read, otherwise.
+import oa__socket__read__byte: int -> int
+ for readByteFromStreamSocket
+++ Try to write bytes of data to socket.
+++ Return -1 on failure; actual bytes written, otherwise.
import oa__socket__write: (int,readonly buffer byte,int) -> int
for writeToStreamSocket
+++ Try to write a byte to socket.
+++ Return -1 on failure; the written byte, otherwise.
+import oa__socket__write__byte: (int,int) -> int
+ for writeByteToStreamSocket
+
import oa__close__socket: int -> int for closeSocket
--% OpenAxiom subsystem socket support
diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c
index c53d3981..51c04bfe 100644
--- a/src/lib/sockio-c.c
+++ b/src/lib/sockio-c.c
@@ -366,18 +366,46 @@ oa_connect_ip_port_stream(const openaxiom_byte* addr, int prot,
we restrict ourselves to the POSIX standard functions recv() and
send(). */
+
+/* Read some bytes of data into buffer `buf' with capacity `size'.
+ On failure, return -1; otherwise return the number of bytes
+ actually read. */
+
OPENAXIOM_EXPORT int
oa_socket_read(openaxiom_socket sock, openaxiom_byte* buf, int size)
{
return recv(sock, buf, size, 0);
}
+/* Attempt to read a byte from scoket `sock'.
+ On failure, return -1; otherwise the actual byte read. */
+
+OPENAXIOM_EXPORT int
+oa_socket_read_byte(openaxiom_socket sock)
+{
+ openaxiom_byte byte;
+ if(oa_socket_read(sock, &byte, 1) < 1)
+ return -1;
+ return byte;
+}
+
+
+/* Send `size' bytes of data contained in `buf' to the socket `sock'.
+ Return -1 on failured; the number of actualy write bytes on success. */
+
OPENAXIOM_EXPORT int
oa_socket_write(openaxiom_socket sock, const openaxiom_byte* buf, int size)
{
return send(sock, buf, size, 0);
}
+/* Send one byte to socket `sock'. */
+OPENAXIOM_EXPORT int
+oa_socket_write_byte(openaxiom_socket sock, openaxiom_byte byte)
+{
+ return oa_socket_write(sock, &byte, 1) < 1 ? -1 : byte;
+}
+
/* Return 1 is the last call was cancelled. */