Skip to content

Commit

Permalink
Merge pull request #192 from JuliaWeb/tan/fix191
Browse files Browse the repository at this point in the history
avoid blocking on unnecessary eof check
  • Loading branch information
quinnj authored Jan 27, 2019
2 parents 0e65ee9 + bf86932 commit 6a72176
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ os:
- linux
- osx
julia:
- 1.0
- 0.7
- nightly
notifications:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1.0
- julia_version: latest

platform:
Expand Down
2 changes: 1 addition & 1 deletion src/ssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function Base.readbytes!(ctx::SSLContext, buf::Vector{UInt8}, nbytes::UInt;
nread = 0
while nread < nbytes
nread += ssl_unsafe_read(ctx, pointer(buf) + nread, nbytes - nread)
if !all || eof(ctx)
if (nread == nbytes) || !all || eof(ctx)
break
end
end ;@😬 "readbytes! ⬅️ $nread"
Expand Down
52 changes: 52 additions & 0 deletions test/clntsrvr/clntsrvr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Test
using Sockets
using MbedTLS

function sslaccept(server, certfile, keyfile)
sslconfig = MbedTLS.SSLConfig(certfile, keyfile)
conn = accept(server)
sslconn = MbedTLS.SSLContext()
MbedTLS.setup!(sslconn, sslconfig)
MbedTLS.associate!(sslconn, conn)
MbedTLS.handshake!(sslconn)
return sslconn
end

function sslconnect(dest, port)
conn = connect(dest, port)
sslconfig = MbedTLS.SSLConfig(false)
sslconn = MbedTLS.SSLContext()
MbedTLS.setup!(sslconn, sslconfig)
MbedTLS.set_bio!(sslconn, conn)
MbedTLS.handshake!(sslconn)
return sslconn
end

function testclntsrvr(certfile, keyfile)
outbuff = ones(UInt8, 100) * UInt8(65)
trigger = Channel{Bool}(1)
port = UInt16(0)

@async begin
(port, server) = listenany(8000)
@info("listening on port $port")
put!(trigger, true)
srvrconn = sslaccept(server, certfile, keyfile)
inbuff = read(srvrconn, 100)
@test inbuff == outbuff
put!(trigger, true)
end

take!(trigger)
@info("connecting to port $port")
clntconn = sslconnect("127.0.0.1", port)
@test write(clntconn, outbuff) == 100
@async begin
sleep(10)
put!(trigger, false)
end

@test take!(trigger)
end

testclntsrvr(joinpath(dirname(@__FILE__), "test.cert"), joinpath(dirname(@__FILE__), "test.key"))
32 changes: 32 additions & 0 deletions test/clntsrvr/test.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFgDCCA2igAwIBAgIJAPzuyJ6GLrRFMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV
BAYTAklOMRIwEAYDVQQIDAlLYXJuYXRha2ExEjAQBgNVBAcMCUJhbmdhbG9yZTEO
MAwGA1UECgwFSnVsaWExDjAMBgNVBAMMBXRhbmx0MB4XDTE5MDEyMzA2MzMwN1oX
DTI5MDEyMDA2MzMwN1owVTELMAkGA1UEBhMCSU4xEjAQBgNVBAgMCUthcm5hdGFr
YTESMBAGA1UEBwwJQmFuZ2Fsb3JlMQ4wDAYDVQQKDAVKdWxpYTEOMAwGA1UEAwwF
dGFubHQwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC/24addgduwK6H
qBK1QiC54gf48J6Y0OoMMTZzSiavFg74QASgoUwG2LLIt+9HDWMv/VysFJGG//5Y
6NECc9/87uULKpcPoIMf0oGOZ2pFbyVLxaVndUtsZK3xX+gesGhHQeMAkA5THXeo
FhU4JFE/UINwaxPJIoLc3hg9v/abT/25E+CrTxrgz82LOdboal+TjXN0Bl+s3xKP
NMtRe/P/EPZV+hV66V2D9hRabIgoiweJd7TvrPLaNsVzHwyANtyNTm3Uqfz37y43
BoHVzSzTp1qxwNvefTP1Y+CbS40VQ8YL2RQisaSLlRaTobeYvyjIqWVfBFq7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pAuMsVv3DNEmDpgx2dxCIHk/VtohBhN5/X
Yk+8+aUsMe1PsxiQ5XR0HnHk8cAmwCjDcZEoc0SffFXuJBaWJRea+TyjGKAJQuak
b/ONbolarLJICekZot3L9pTRYrk=
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions test/clntsrvr/test.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC/24addgduwK6H
qBK1QiC54gf48J6Y0OoMMTZzSiavFg74QASgoUwG2LLIt+9HDWMv/VysFJGG//5Y
6NECc9/87uULKpcPoIMf0oGOZ2pFbyVLxaVndUtsZK3xX+gesGhHQeMAkA5THXeo
FhU4JFE/UINwaxPJIoLc3hg9v/abT/25E+CrTxrgz82LOdboal+TjXN0Bl+s3xKP
NMtRe/P/EPZV+hV66V2D9hRabIgoiweJd7TvrPLaNsVzHwyANtyNTm3Uqfz37y43
BoHVzSzTp1qxwNvefTP1Y+CbS40VQ8YL2RQisaSLlRaTobeYvyjIqWVfBFq7TMSi
Xw6szsrxdKgnpDj+QIawzn0h2jvDGdcAxX/v4/AJy8kKpxHEi0xUW/uGW2LlsoNI
fDW4jrfAEBeMzsEsLwTEh0Oin0r3uWlYLl4UZsUpvurlWTlVbJ6wR93rn4yPQau6
I4T9hsAL5es88naVkgjQJnkeGXsrV23K61kfqyYIMA1hGKCh/JkXWm88IeBdJdwm
XI0sTexig5tJuLghWoas1abosHsFZoUFtDI/1N0HNfxsjx3D7hkdyzQ/gxr5EHVV
bWU1YaXe00erCjFZlawILuxgAjzuHmKTk5YSQ3R0bMv+dtOW0cXY4sLk78zOUUWN
qv+UHuO4d5Fov/iJ5D0RoIAPfyIKqQIDAQABAoICAFaA93AVoIJKNCcMG+tH9pN5
G1kdvJRwVabLpZ5Tx59X1cYOr0dxkmLf37RqYmNp4NfpZ5ha6caxs4+I4Xw2nL5h
RDpFqLiuCZEWi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/MuC76AA4yd9+wmGLtl/yeCV9yjJeegYOPrYvuI1Arftw1VBK0Lp1YVokm
Z2NPQTOa5XymnCzx4yoTZ/SBTetPSEu5XZ09Pnn152sBcE4xo1nlsXPWPkzpEgCM
wa/qaxFCuSCcGYXIWT0mN+Z9QPJtVf3T8DCNoY3lMb5AMrDKzMlO6RHNz5Qsm+qM
jcWJWBIQzJf4b0KYq5zewDH/ro66og==
-----END PRIVATE KEY-----
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,8 @@ mktempdir() do d
buf = String(read(ctx, 100))
@test occursin(r"^HTTP/1.1 200 OK", buf)
@test occursin(r"^CLIENT_RANDOM [0-9a-f]{64} [0-9a-f]{96}$", read(f, String))
end

let
include("clntsrvr/clntsrvr.jl")
end

0 comments on commit 6a72176

Please sign in to comment.