Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit076bdef

Browse files
authored
Remove and do not auto-add TCP option nodelay if not supported (#184)
1 parent927fec2 commit076bdef

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

‎src/mysql_conn.erl‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ connect(#state{connect_timeout = ConnectTimeout} = State) ->
159159

160160
connect_socket(#state{tcp_opts=TcpOpts,host=Host,port=Port}=State)->
161161
%% Connect socket
162-
SockOpts=sanitize_tcp_opts(TcpOpts),
162+
SockOpts=sanitize_tcp_opts(Host,TcpOpts),
163163
{ok,Socket}=gen_tcp:connect(Host,Port,SockOpts),
164164

165165
%% If buffer wasn't specifically defined make it at least as
@@ -175,26 +175,28 @@ connect_socket(#state{tcp_opts = TcpOpts, host = Host, port = Port} = State) ->
175175

176176
{ok,State#state{socket=Socket}}.
177177

178-
sanitize_tcp_opts([{inet_backend,_}=InetBackend |TcpOpts0])->
178+
sanitize_tcp_opts(Host,[{inet_backend,_}=InetBackend |TcpOpts0])->
179179
%% This option is be used to turn on the experimental socket backend for
180180
%% gen_tcp/inet (OTP/23). If given, it must remain the first option in the
181181
%% list.
182-
[InetBackend |sanitize_tcp_opts(TcpOpts0)];
183-
sanitize_tcp_opts(TcpOpts0)->
182+
[InetBackend |sanitize_tcp_opts(Host,TcpOpts0)];
183+
sanitize_tcp_opts(Host,TcpOpts0)->
184+
NodelaySupported=notis_tuple(Host)orelseelement(1,Host)=/=local,
184185
TcpOpts1=lists:filter(
185186
fun
186187
({mode,_})->false;
187188
(binary)->false;
188189
(list)->false;
189190
({packet,_})->false;
190191
({active,_})->false;
192+
({nodelay,_})->NodelaySupported;
191193
(_)->true
192194
end,
193195
TcpOpts0
194196
),
195-
TcpOpts2=caselists:keymember(nodelay,1,TcpOpts1)of
196-
true ->TcpOpts1;
197-
false ->[{nodelay,true} |TcpOpts1]
197+
TcpOpts2=caseNodelaySupportedandalsonotlists:keymember(nodelay,1,TcpOpts1)of
198+
true ->[{nodelay,true} |TcpOpts1];
199+
false ->TcpOpts1
198200
end,
199201
[binary, {packet,raw}, {active,false} |TcpOpts2].
200202

‎test/mysql_tests.erl‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,45 @@ unix_socket_test() ->
261261
"release could not be determined.~n")
262262
end.
263263

264+
socket_backend_test()->
265+
try
266+
list_to_integer(erlang:system_info(otp_release))
267+
of
268+
%% Supported in OTP >= 23
269+
OtpReleasewhenOtpRelease>=23 ->
270+
casemysql:start_link([{user,?user},
271+
{password,?password},
272+
{tcp_options, [{inet_backend,socket}]}])
273+
of
274+
{ok,Pid1} ->
275+
{ok, [<<"@@socket">>], [[SockFile]]}=
276+
mysql:query(Pid1, <<"SELECT @@socket">>),
277+
mysql:stop(Pid1),
278+
casemysql:start_link([{host, {local,SockFile}},
279+
{user,?user}, {password,?password},
280+
{tcp_options, [{inet_backend,socket}]}])of
281+
{ok,Pid2} ->
282+
?assertEqual({ok, [<<"1">>], [[1]]},
283+
mysql:query(Pid2, <<"SELECT 1">>)),
284+
mysql:stop(Pid2);
285+
{error,eafnotsupported} ->
286+
error_logger:info_msg("Skipping socket backend test."
287+
"Not supported on this OS.~n")
288+
end;
289+
{error,enotsup} ->
290+
error_logger:info_msg("Skipping socket backend test."
291+
"Not supported on this OS.~n")
292+
end;
293+
OtpRelease ->
294+
error_logger:info_msg("Skipping socket backend test. Current OTP"
295+
"release is~B. Required release is >= 23.~n",
296+
[OtpRelease])
297+
catch
298+
error:badarg ->
299+
error_logger:info_msg("Skipping socket backend tests. Current OTP"
300+
"release could not be determined.~n")
301+
end.
302+
264303
connect_queries_failure_test()->
265304
process_flag(trap_exit,true),
266305
{ok,Ret,Logged}=error_logger_acc:capture(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp