( defun write-skkserv ( socket string ) ( loop for byte across ( babel:string-to-octets string :encoding :eucjp ) do ( write-byte byte ( usocket:socket-stream socket ))) ( force-output ( usocket:socket-stream socket ))) ( defun read-skkserv ( socket &key ( timeout-seconds 1 )) ( let (( len 0 ) ( product nil )) ( flet (( make-res-string ( len product ) ( babel:octets-to-string ( make-array len :element-type ' ( unsigned-byte 8 ) :initial-contents ( nreverse product )) :encoding :eucjp ))) ( portable-threads:with-timeout ( timeout-seconds ( error "Timeout in read-skkserv. Read data: ~A~%" ( make-res-string len product ))) ( let (( byte ( read-byte ( usocket:socket-stream socket ) nil nil ))) ( loop until ( or ( null byte ) ( = byte 10 )) do ( push byte product ) ( incf len ) ( setf byte ( read-byte ( usocket:socket-stream socket ) nil nil ))) ( make-res-string len product ))))))