소스 검색

ft: 修改tcp 发送函数

master
SisMaker 1 년 전
부모
커밋
d1a11bc786
1개의 변경된 파일30개의 추가작업 그리고 0개의 파일을 삭제
  1. +30
    -0
      src/agVstCli/agMiscUtils.erl

+ 30
- 0
src/agVstCli/agMiscUtils.erl 파일 보기

@ -13,6 +13,7 @@
, randElement/1
, toBinary/1
, agMethod/1
, syncSend/2
]).
-spec parseUrl(binary()) -> dbOpts() | {error, invalidUrl}.
@ -103,3 +104,32 @@ 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) ->
syncSend(S, Data, []).
syncSend(S, Data, OptList) when is_port(S), is_list(OptList) ->
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], OptList)
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.

불러오는 중...
취소
저장