From 9aa224af3b5a7e6b22bb30ff1e14b265a9acc9f3 Mon Sep 17 00:00:00 2001 From: Rebecca Kelly Date: Sat, 3 Feb 2024 16:04:59 -0500 Subject: [PATCH] Set LINELEN to 8k for clients that support long messages This matches the value already negotiated for cap multiline. I think we could go up to 16k without difficulty, but 8k is probably sufficient. This also tells gen_tcp to use an 8k buffer; the default buffer size is about 1.5k (one TCP packet, maybe?) and cuts off longer commands, with tragic results. --- lib/irc/handler.ex | 2 ++ lib/irc_server.ex | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/irc/handler.ex b/lib/irc/handler.ex index ca99223..d988e9c 100644 --- a/lib/irc/handler.ex +++ b/lib/irc/handler.ex @@ -607,6 +607,8 @@ defmodule M51.IrcConn.Handler do "CHANMODES=b,,,i", "CHANTYPES=#!", "CHATHISTORY=100", + # Matrix limit is 64k for the whole event, so this is fairly conservative. + "LINELEN=8192", "MAXTARGETS=1", # https://github.com/ircv3/ircv3-specifications/pull/510 "MSGREFTYPES=msgid", diff --git a/lib/irc_server.ex b/lib/irc_server.ex index 948c417..0ce91fa 100644 --- a/lib/irc_server.ex +++ b/lib/irc_server.ex @@ -40,7 +40,7 @@ defmodule M51.IrcServer do end defp accept(port, retries_left \\ 10) do - case :gen_tcp.listen(port, [:binary, :inet6, packet: :line, active: false, reuseaddr: true]) do + case :gen_tcp.listen(port, [:binary, :inet6, packet: :line, active: false, reuseaddr: true, buffer: 8192]) do {:ok, server_sock} -> Logger.info("Listening on port #{port}") loop_accept(server_sock)