Skip to content

Commit bac0f5b

Browse files
ToxicFrogprogval
authored andcommitted
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 a 16k buffer; with the default settings, long commands sometimes get split across multiple reads, with unfortunate results.
1 parent 80dc1da commit bac0f5b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/irc/handler.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ defmodule M51.IrcConn.Handler do
607607
"CHANMODES=b,,,i",
608608
"CHANTYPES=#!",
609609
"CHATHISTORY=100",
610+
# Matrix limit is 64k for the whole event, so this is fairly conservative.
611+
"LINELEN=#{@multiline_max_bytes}",
610612
"MAXTARGETS=1",
611613
# https://github.com/ircv3/ircv3-specifications/pull/510
612614
"MSGREFTYPES=msgid",

lib/irc_server.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ defmodule M51.IrcServer do
4040
end
4141

4242
defp accept(port, retries_left \\ 10) do
43-
case :gen_tcp.listen(port, [:binary, :inet6, packet: :line, active: false, reuseaddr: true]) do
43+
opts = [
44+
:binary, :inet6,
45+
packet: :line,
46+
active: false,
47+
reuseaddr: true,
48+
buffer: M51.IrcConn.Handler.multiline_max_bytes * 2
49+
]
50+
case :gen_tcp.listen(port, opts) do
4451
{:ok, server_sock} ->
4552
Logger.info("Listening on port #{port}")
4653
loop_accept(server_sock)

test/irc/handler_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule M51.IrcConn.HandlerTest do
2020

2121
@cap_ls_302 ":server. CAP * LS :account-tag batch draft/account-registration=before-connect draft/channel-rename draft/chathistory draft/message-redaction draft/multiline=max-bytes=8192 draft/no-implicit-names draft/sasl-ir echo-message extended-join labeled-response message-tags sasl=PLAIN server-time soju.im/account-required standard-replies userhost-in-names\r\n"
2222
@cap_ls ":server. CAP * LS :account-tag batch draft/account-registration draft/channel-rename draft/chathistory draft/message-redaction draft/multiline draft/no-implicit-names draft/sasl-ir echo-message extended-join labeled-response message-tags sasl server-time soju.im/account-required standard-replies userhost-in-names\r\n"
23-
@isupport "CASEMAPPING=rfc3454 CLIENTTAGDENY=*,-draft/react,-draft/reply CHANLIMIT= CHANMODES=b,,,i CHANTYPES=#! CHATHISTORY=100 MAXTARGETS=1 MSGREFTYPES=msgid PREFIX= TARGMAX=JOIN:1,PART:1 UTF8ONLY :are supported by this server\r\n"
23+
@isupport "CASEMAPPING=rfc3454 CLIENTTAGDENY=*,-draft/react,-draft/reply CHANLIMIT= CHANMODES=b,,,i CHANTYPES=#! CHATHISTORY=100 LINELEN=8192 MAXTARGETS=1 MSGREFTYPES=msgid PREFIX= TARGMAX=JOIN:1,PART:1 UTF8ONLY :are supported by this server\r\n"
2424

2525
setup do
2626
start_supervised!({MockMatrixClient, {self()}})

0 commit comments

Comments
 (0)