Plaster
New
List
Login
text
apl
aspx
asterisk
brainfuck
c
c++hdr
c++src
cassandra
ceylon
clojure
clojurescript
cmake
cobol
coffeescript
common-lisp
crystal
csharp
css
cypher-query
cython
d
dart
diff
django
dockerfile
dylan
ebnf
ecl
ecmascript
edn
eiffel
ejs
elm
erb
erlang
ez80
factor
fcl
feature
forth
fortran
fragment
gfm
go
gql
groovy
gss
haml
handlebars-template
haskell
haxe
hive
html
http
httpd-php
httpd-php-open
hxml
ini
java
javascript
json
jsp
jsx
julia
kotlin
latex
less
literate-haskell
lua
mariadb
markdown
mbox
mirc
mscgen
msgenny
mssql
mumps
mysql
n-triples
nesc
nginx-conf
nsis
objectivec
octave
oz
pascal
perl
pgp
pgp-keys
pgp-signature
pgsql
php
pig
plsql
properties
protobuf
puppet
python
q
rpm-changes
rpm-spec
rsrc
ruby
rustsrc
sas
sass
scala
scheme
scss
sieve
slim
smarty
solr
soy
sparql-query
spreadsheet
sql
squirrel
stex
styl
swift
systemverilog
tcl
textile
tiddlywiki
tiki
tlv
tornado
ttcn-asn
ttcn-cfg
turtle
twig
typescript
typescript-jsx
vb
vbscript
velocity
verilog
vertex
vhdl
vue
webidl
xml
xml-dtd
xquery
xu
yaml
z80
default
Visibility:
public
unlisted
private
(defun download-encrypted-packet (connection cipher) (declare (optimize (speed 3)(safety 1))) (handler-case (tlet* ((stream stream (c-stream connection)) (len u-byte (timed-non-block-read-byte stream)) (encrypted-packet byte-array (read-n-bytes len stream))) (flexi-streams:make-in-memory-input-stream (decrypt-byte-array cipher encrypted-packet))) (stream-error (c) (write-error c) :EOF) (SB-INT:SIMPLE-STREAM-ERROR () :EOF) (broken-packet () (sb-ext:atomic-incf (car oofs)) :EOF))) ;;;my three functions that read bytes from a stream ;;;these functions seem to get 'bound up' or freeze when used on the flexi-stream:memory-input-stream (defun non-block-read-byte (stream) "read byte that is non blocking, if there is nothing to read it simply returns nil" ;; (declare (optimize (speed 3)(safety 0)) ;; (type stream stream)) (the (or u-byte boolean) (and (listen stream) (tlet ((byte u-byte (read-byte stream t))) (the u-byte byte))))) (defun timed-non-block-read-byte (stream) "This is a non blocking version of read byte which is timed. loops *increment* amount of times and checks if there is anything on the stream to be read, if not it'll sleep for *sleep-time* if it eventually finds something to read it'll read and then return that byte. if it reaches the timeout it'll signal an error" ;; (declare (optimize (speed 3)(safety 1)) ;; (type stream stream)) (tlet ((byte (or u-byte boolean) (non-block-read-byte stream))) (or byte (the u-byte (loop :for x fixnum :from 1 :to *increment* :for byte? := (the (or boolean u-byte) (non-block-read-byte stream)) :then (the (or u-byte boolean) (non-block-read-byte stream)) :if byte? :do (return byte?) :else :do (sleep *sleep-time*) :finally (error 'stream-error :stream stream)))))) (defun read-n-bytes (n stream) "Reads n bytes from stream and puts them into an array of length n and type unsigned-byte 8" ;; (declare (optimize (speed 3)(safety 0)) ;; (type u-byte n) ;; (type stream stream)) (tlet ((data byte-array (make-array n :element-type 'u-byte))) (declare (type byte-array data)) (dotimes (i n (the byte-array data)) (declare (type fixnum i) (type fixnum n)) (the u-byte (setf (aref data i) (the u-byte (timed-non-block-read-byte stream)))))))