|
128 | 128 | (as:close-tcp-server server)))) |
129 | 129 | (is-true first-successful-p))) |
130 | 130 |
|
| 131 | +(defun sha256 (byte-array) |
| 132 | + (let ((byte-array (if (typep byte-array '(simple-array (unsigned-byte 8) (*))) |
| 133 | + byte-array |
| 134 | + (coerce byte-array '(simple-array (unsigned-byte 8) (*))))) |
| 135 | + (hasher (ironclad:make-digest :sha256))) |
| 136 | + (ironclad:update-digest hasher byte-array) |
| 137 | + (ironclad:byte-array-to-hex-string (ironclad:produce-digest hasher)))) |
| 138 | + |
| 139 | +#| |
131 | 140 | (test no-overlap |
132 | 141 | "Make sure that requests/responses don't overlap." |
| 142 | + (format t "~%---~%") |
133 | 143 | (multiple-value-bind (res) |
134 | | - (async-let ((res (make-hash-table :test 'eq))) |
135 | | - (test-timeout 3) |
| 144 | + (async-let ((res (make-hash-table :test #'eq)) |
| 145 | + (size (+ as:*buffer-size* 20000)) |
| 146 | + (num-clients 4) |
| 147 | + (num-recv 0) |
| 148 | + (server nil)) |
| 149 | + (test-timeout 20) |
136 | 150 |
|
137 | | - (let ((counter 1)) |
| 151 | + (setf server |
138 | 152 | (as:tcp-server nil 31389 |
139 | 153 | (lambda (sock data) |
140 | | - (dotimes (i (length data)) |
141 | | - (assert (= (aref data 0) (aref data i)))) |
142 | | - (incf (getf (as:socket-data sock) :bytes) (length data)) |
143 | | - (when (<= (+ as:*buffer-size* 20000) (getf (as:socket-data sock) :bytes)) |
144 | | - (let ((res (make-array 500000 :initial-element (getf (as:socket-data sock) :id) |
145 | | - :element-type 'as:octet))) |
146 | | - (as:write-socket-data sock res)))) |
147 | | - :connect-cb (lambda (sock) |
148 | | - (setf (as:socket-data sock) (list :id counter :bytes 0)) |
149 | | - (incf counter)))) |
150 | | - (dotimes (i 4) |
151 | | - (let ((x i)) |
| 154 | + (unless (getf (as:socket-data sock) :id) |
| 155 | + (setf (getf (as:socket-data sock) :id) (aref data 0))) |
| 156 | + (unless (getf (as:socket-data sock) :bytes) |
| 157 | + (setf (getf (as:socket-data sock) :bytes) 0)) |
| 158 | + (let ((id (getf (as:socket-data sock) :id)) |
| 159 | + (undupe (remove-duplicates data))) |
| 160 | + (assert (and (= (length undupe) 1) |
| 161 | + (= (aref undupe 0) id))) |
| 162 | + (incf (getf (as:socket-data sock) :bytes) (length data)) |
| 163 | + (when (<= size (getf (as:socket-data sock) :bytes)) |
| 164 | + (format t "server: send: ~a ~a~%" id (* size 1)) |
| 165 | + (as:write-socket-data |
| 166 | + sock |
| 167 | + (make-array (* size 1) :initial-element id :element-type 'as:octet)) |
| 168 | + (incf num-recv) |
| 169 | + (when (<= num-clients num-recv) |
| 170 | + (as:with-delay () |
| 171 | + (format t "close server: t~%") |
| 172 | + (as:close-tcp-server server)))))))) |
| 173 | +
|
| 174 | + (dotimes (i num-clients) |
| 175 | + (let* ((x i) |
| 176 | + (data (make-array size |
| 177 | + :initial-element x |
| 178 | + :element-type '(unsigned-byte 8)))) |
| 179 | + (format t "client: send: ~a ~a~%" x (length data)) |
152 | 180 | (as:tcp-connect "127.0.0.1" 31389 |
153 | 181 | (lambda (sock data) |
154 | 182 | (declare (ignorable sock)) |
155 | | - (push data (gethash x res))) |
156 | | - :data (make-array (+ as:*buffer-size* 20000) |
157 | | - :initial-element x |
158 | | - :element-type '(unsigned-byte 8)))))) |
159 | | - (loop ;for k being the hash-keys of res |
| 183 | + (push data (gethash x res)) |
| 184 | + (format t "client: recv: ~a ~a ~a~%" x (length data) |
| 185 | + (reduce (lambda (acc x) (+ acc (length x))) (gethash x res) :initial-value 0))) |
| 186 | + :data data)))) |
| 187 | + (format t "res done~%")(force-output) |
| 188 | + (loop for x being the hash-keys of res |
160 | 189 | for v being the hash-values of res do |
161 | 190 | (let ((stream (flexi-streams:make-in-memory-output-stream :element-type '(unsigned-byte 8)))) |
162 | 191 | (dolist (part v) |
|
169 | 198 | (return))) |
170 | 199 | (is (eq is-eq t))))))) |
171 | 200 |
|
| 201 | +(setf *debug-on-error* t) |
| 202 | +(run! 'no-overlap) |
| 203 | +|# |
| 204 | + |
172 | 205 | (test write-seq-with-offset |
173 | 206 | "Make sure writing subsequences to a socket works properly" |
174 | 207 | (with-test-event-loop () |
|
0 commit comments