Close Stream bug files
This commit is contained in:
32
tests-pl/issue1046-close-stream-client.pl
Normal file
32
tests-pl/issue1046-close-stream-client.pl
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
:- use_module(library(sockets)).
|
||||||
|
:- use_module(library(time)).
|
||||||
|
:- use_module(library(format)).
|
||||||
|
:- use_module(library(charsio)).
|
||||||
|
|
||||||
|
test :-
|
||||||
|
Addr = '0.0.0.0',
|
||||||
|
Port = 5000,
|
||||||
|
socket_client_open(Addr:Port, Stream, [type(binary)]),
|
||||||
|
read_line(Stream, Line),
|
||||||
|
write(Line),
|
||||||
|
close(Stream).
|
||||||
|
|
||||||
|
|
||||||
|
read_line(Stream, Line) :-
|
||||||
|
get_byte(Stream, Char),
|
||||||
|
( Char = -1 ->
|
||||||
|
Line = []
|
||||||
|
; Char = 13 ->
|
||||||
|
read_line(Stream, Line)
|
||||||
|
; Char = 10 ->
|
||||||
|
Line = []
|
||||||
|
; (read_line(Stream, Line0), Line = [Char|Line0])
|
||||||
|
).
|
||||||
|
|
||||||
|
read_message(Stream, [Cs|Message]) :-
|
||||||
|
read_line(Stream, Bs),
|
||||||
|
chars_utf8bytes(Cs, Bs),
|
||||||
|
( Cs = "." ->
|
||||||
|
Message = []
|
||||||
|
; read_message(Stream, Message)
|
||||||
|
).
|
||||||
14
tests-pl/issue1046-close-stream.pl
Normal file
14
tests-pl/issue1046-close-stream.pl
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
:- use_module(library(sockets)).
|
||||||
|
:- use_module(library(time)).
|
||||||
|
:- use_module(library(format)).
|
||||||
|
|
||||||
|
test :-
|
||||||
|
Addr = '0.0.0.0',
|
||||||
|
Port = 5000,
|
||||||
|
once(socket_server_open(Addr:Port, Socket)),
|
||||||
|
format("Listening at port ~d\n", [Port]),
|
||||||
|
socket_server_accept(Socket, _Client, Stream, [type(binary)]),
|
||||||
|
format(Stream, "FIRST\r\n", []),
|
||||||
|
sleep(20),
|
||||||
|
format(Stream, "SECOND\r\n", []),
|
||||||
|
close(Stream).
|
||||||
Reference in New Issue
Block a user