diff options
author | tilpner | 2018-08-12 21:10:30 +0200 |
---|---|---|
committer | tilpner | 2018-08-12 21:10:30 +0200 |
commit | 76561ca7b1ad923967af37da691c55bd8f8219e8 (patch) | |
tree | fb8c22eff33becf9887b32a4bff665492bcddb2d /irc/core.rkt | |
parent | 0a2aad6e928796e1fdb99120a768daa0ce7601a2 (diff) | |
download | meep-76561ca7b1ad923967af37da691c55bd8f8219e8.tar.gz meep-76561ca7b1ad923967af37da691c55bd8f8219e8.tar.xz meep-76561ca7b1ad923967af37da691c55bd8f8219e8.zip |
Warn on lossy message parsing-formatting roundtrip
Diffstat (limited to 'irc/core.rkt')
-rw-r--r-- | irc/core.rkt | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/irc/core.rkt b/irc/core.rkt index bbe6905..a24747e 100644 --- a/irc/core.rkt +++ b/irc/core.rkt @@ -55,10 +55,11 @@ [cmd (message-command msg)] [args (message-args msg)] [suff (message-suffix msg)]) - ; (when tags (fprintf out "@~A " tags)) - ; (if tags - ; (map (λ (t) (map clean t)) tags) - ; tags) + (when (pair? tags) + (fprintf out "@~A " + (string-join + (map (λ (t) (string-append (car t) "=" (cdr t))) tags) + ";"))) (when prefix (fprintf out ":~A " (clean prefix))) (fprintf out "~A" (clean (symbol->string cmd))) @@ -119,17 +120,23 @@ (message tags prefix cmd args suffix)) (define (send msg #:conn [conn (current-connection)]) + (define formatted (~a msg)) + (define capped (substring formatted 0 (min 510 (string-length formatted)))) (call-with-semaphore (connection-output-lock conn) - (thunk (log-irc-info "» ~a" msg) - (fprintf (connection-output conn) "~A\r\n" msg) - (flush-output (connection-output conn))))) + (thunk (log-irc-info "» ~a" capped) + (define out (connection-output conn)) + (display capped out) + (display "\r\n" out) + (flush-output out)))) (define (listen) (let ([input (connection-input (current-connection))]) (let loop () (let* ([l (read-line input 'any)] [msg (msg-parse l)]) - (log-irc-info "« ~a" msg) + (when (not (string=? (~a msg) l)) + (log-irc-warning "Message roundtrip lossy:\nActual: ~a\nParsed: ~a" l msg)) + (log-irc-info "« ~a" l) (thread (thunk (hook-process msg)))) (loop)))) |