Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/distro-examples/tests/output/socket-io.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Client connection closed
Server connection closed
27 changes: 27 additions & 0 deletions samples/distro-examples/tests/socket-io-client.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!../../../src/platform/console/sbasic

' This file (socket_io_client.bas) will be called by socket_io.bas
' Shebang needs to link to correct sbasic file.

open "SOCL:127.0.0.1:10000" as #1

' Test bputc and bgetc
for byte = 0 to 255
bputc #1, byte
next

' Test print
print #1, "Test1234"
print #1, "Test-1234"
print #1, "Test1234"

' Test EOF bug
byte = 0
bputc #1, byte

' Test LOF
print #1, "Test1234"

close #1

print "Client connection closed"
36 changes: 36 additions & 0 deletions samples/distro-examples/tests/socket-io.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
' socket-io.bas will start a socket client. The client will send data.
' socket-io.bas will check if data was received correctly

' make socket-io-client.bas executable and then execute it
chmod "../../../samples/distro-examples/tests/socket-io-client.bas", 0o777
exec "../../../samples/distro-examples/tests/socket-io-client.bas"

open "SOCL:10000" as #1

' Test bputc and bgetc
for ii = 0 to 255
Recv = bgetc(1)
if(Recv != ii) then throw "BGETC: " + ii + " expected, received " + Recv
next

' Test print and input
input #1, ans
if(ans != "Test1234") then throw "INPUT: Test1234 expected, received " + ans

input #1, ans, "-", ans2
if(ans != "Test") then throw "INPUT: Test expected, received " + ans
if(ans2 != "1234") then throw "INPUT: 1234 expected, received " + ans2

ans = input(9, 1)
if(ans != "Test1234\n") then throw "INPUT: Test1234 expected, received " + "\"" + ans + "\""

' Test for bug in SB 12.25: when "0" is received, EOF should not return true
ans = bgetc(1)
if(EOF(1)) then throw "EOF: zero received and eof returns true"

' Test LOF
if(LOF(1) != 9) then throw "LOF: 9 bytes expected. " + LOF(1) + " bytes waiting."

close #1

print "Server connection closed"
2 changes: 1 addition & 1 deletion src/common/fs_socket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int sockcl_eof(dev_file_t *f) {
}

//
// returns the size of the data which are waiting in stream's queue
// returns the size of data waiting in stream's queue
//
int sockcl_length(dev_file_t *f) {
return net_peek((socket_t) (long) f->handle);
Expand Down
2 changes: 1 addition & 1 deletion src/common/inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void net_disconnect(socket_t s);
/**
* @ingroup net
*
* returns true if something is waiting in input-buffer
* returns number of bytes waiting in input-buffer
*
* @param s the socket
* @return non-zero if something is waiting in input-buffer; otherwise returns 0
Expand Down
9 changes: 3 additions & 6 deletions src/common/inet2.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ int net_input(socket_t s, char *buf, int size, const char *delim) {
if (bytes <= 0) {
return count; // no more data
} else {
if (ch == 0) {
return count;
}
if (delim) {
if ((strchr(delim, ch) != NULL)) {
return count; // delimiter found
Expand All @@ -178,19 +175,19 @@ int net_input(socket_t s, char *buf, int size, const char *delim) {
}

/**
* return true if there something waiting
* return available data in bytes
*/
int net_peek(socket_t s) {
#if defined(_Win32)
unsigned long bytes;

ioctlsocket(s, FIONREAD, &bytes);
return (bytes > 0);
return (bytes);
#else
int bytes;

ioctl(s, FIONREAD, &bytes);
return (bytes > 0);
return (bytes);
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/platform/console/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ TEST_DIR=../../../samples/distro-examples/tests
UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \
uds hash pass1 call_tau short-circuit strings stack-test \
replace-test read-data proc optchk letbug ptr ref input \
trycatch chain stream-files split-join sprint all scope goto keymap
trycatch chain stream-files split-join sprint all scope \
goto keymap socket-io

test: ${bin_PROGRAMS}
@for utest in $(UNIT_TESTS); do \
Expand Down