Quellcode durchsuchen

ft: 修正tcp 发送函数

master
SisMaker vor 1 Jahr
Ursprung
Commit
40a172ceb6
4 geänderte Dateien mit 34 neuen und 6 gelöschten Zeilen
  1. +28
    -0
      src/agVstCli/agMiscUtils.erl
  2. +3
    -3
      src/agVstCli/agTcpAgency.erl
  3. +1
    -1
      src/agVstCli/agVstCli.erl
  4. +2
    -2
      src/eArango.erl

+ 28
- 0
src/agVstCli/agMiscUtils.erl Datei anzeigen

@ -13,6 +13,7 @@
, randElement/1
, toBinary/1
, agMethod/1
, syncSend/2
]).
-spec parseUrl(binary()) -> dbOpts() | {error, invalidUrl}.
@ -103,3 +104,30 @@ agMethod(4) -> <<"Head">>;
agMethod(5) -> <<"Patch">>;
agMethod(6) -> <<"Options">>.
%% This is a generic "port_command" interface used by TCP, UDP, SCTP, depending
%% on the driver it is mapped to, and the "Data". It actually sends out data,--
%% NOT delegating this task to any back-end. For SCTP, this function MUST NOT
%% be called directly -- use "sendmsg" instead:
%%
syncSend(S, Data) ->
MRef = monitor(port, S),
MRefBin = term_to_binary(MRef, [local]),
MRefBinSize = byte_size(MRefBin),
MRefBinSize = MRefBinSize band 16#FFFF,
try
erlang:port_command(S, [<<MRefBinSize:16, MRefBin/binary>>, Data], [])
of
false -> % Port busy when nosuspend option was passed
{error, busy};
true ->
receive
{inet_reply, S, Status, MRef} ->
demonitor(MRef, [flush]),
Status;
{'DOWN', MRef, _, _, _Reason} ->
{error, closed}
end
catch error: _ ->
{error, einval}
end.

+ 3
- 3
src/agVstCli/agTcpAgency.erl Datei anzeigen

@ -103,7 +103,7 @@ handleMsg(#agReq{method = Method, path = Path, queryPars = QueryPars, headers =
%erlang:put(MessageId, {FromPid, undefined, 0, <<>>}),
%Ret = agVstProto:response(?AgUndef, 0, 0, 0, 0, <<>>, BBBB),
%?AgErr(ServerName, "the request is response ret:~p~n", [Ret]),
case ntCom:syncSend(Socket, Request) of
case agMiscUtils:syncSend(Socket, Request) of
ok ->
TimerRef = case OverTime of
infinity ->
@ -159,9 +159,9 @@ handleMsg(?AgMDoDBConn,
#dbOpts{port = Port, hostname = HostName, dbName = DbName, user = User, password = Password, vstSize = VstSize} ->
case gen_tcp:connect(HostName, Port, ?AgDefSocketOpts, ?AgDefConnTimeout) of
{ok, Socket} ->
ntCom:syncSend(Socket, ?AgUpgradeInfo),
agMiscUtils:syncSend(Socket, ?AgUpgradeInfo),
AuthInfo = agVstProto:authInfo(User, Password),
ntCom:syncSend(Socket, AuthInfo),
agMiscUtils:syncSend(Socket, AuthInfo),
case agVstCli:receiveTcpData(#recvState{}, Socket) of
{200, _BodyMap, _HeaderMap} ->
{ok, SrvState#srvState{dbName = DbName, reConnState = agAgencyUtils:resetReConnState(ReConnState), socket = Socket, vstSize = VstSize}, CliState};

+ 1
- 1
src/agVstCli/agVstCli.erl Datei anzeigen

@ -91,7 +91,7 @@ castAgency(PoolNameOrSocket, Method, Path, QueryPars, Headers, Body, Pid, IsSyst
Request = agVstProto:request(IsSystem, MessageId, Method, DbName, Path, QueryPars, Headers, Body, VstSize),
case Protocol of
tcp ->
case ntCom:syncSend(PoolNameOrSocket, Request) of
case agMiscUtils:syncSend(PoolNameOrSocket, Request) of
ok ->
receiveTcpData(#recvState{messageId = MessageId}, PoolNameOrSocket);
_Err ->

+ 2
- 2
src/eArango.erl Datei anzeigen

@ -58,9 +58,9 @@ connDb(DbCfgs) ->
tcp ->
case gen_tcp:connect(HostName, Port, ?AgDefSocketOpts, ?AgDefConnTimeout) of
{ok, Socket} ->
ntCom:syncSend(Socket, ?AgUpgradeInfo),
agMiscUtils:syncSend(Socket, ?AgUpgradeInfo),
AuthInfo = agVstProto:authInfo(User, Password),
ntCom:syncSend(Socket, AuthInfo),
agMiscUtils:syncSend(Socket, AuthInfo),
case agVstCli:receiveTcpData(#recvState{}, Socket) of
{200, _BodyMap, _HeaderMap} ->
setCurDbInfo(Socket, DbName, VstSize, Protocol),

Laden…
Abbrechen
Speichern