1
0
mirror of https://github.com/ubf/ubf.git synced 2026-04-30 00:28:28 +00:00

bugfix - ubf socket handling

This commit is contained in:
Joseph Wayne Norton
2009-06-05 00:38:19 +09:00
parent 8c97661c0a
commit 293dffa24f
6 changed files with 19 additions and 12 deletions

View File

@@ -37,7 +37,7 @@ loop(Socket, Pid, Timeout, Cont) ->
receive
{Pid, Term} ->
Data = erlang:term_to_binary(Term),
gen_tcp:send(Socket, Data),
ok = gen_tcp:send(Socket, Data),
loop(Socket, Pid, Timeout, Cont);
stop ->
Pid ! stop,
@@ -50,9 +50,9 @@ loop(Socket, Pid, Timeout, Cont) ->
{tcp_closed, Socket} ->
Pid ! stop,
exit(socket_closed);
{tcp_error, Socket} ->
{tcp_error, Socket, Reason} ->
gen_tcp:close(Socket),
exit(socket_error);
exit({socket_error,Reason});
{tcp, Socket, Data} ->
T = erlang:binary_to_term(Data),
handle_data(Socket, Pid, Timeout, {done, T});

View File

@@ -37,7 +37,7 @@ loop(Socket, Pid, Timeout, Cont, HandlerMod) ->
receive
{Pid, Term} ->
Data = jsf:encode(Term, HandlerMod),
gen_tcp:send(Socket, [Data,"\n"]),
ok = gen_tcp:send(Socket, [Data,"\n"]),
loop(Socket, Pid, Timeout, Cont, HandlerMod);
stop ->
Pid ! stop,
@@ -50,9 +50,9 @@ loop(Socket, Pid, Timeout, Cont, HandlerMod) ->
{tcp_closed, Socket} ->
Pid ! stop,
exit(socket_closed);
{tcp_error, Socket} ->
{tcp_error, Socket, Reason} ->
gen_tcp:close(Socket),
exit(socket_error);
exit({socket_error,Reason});
{tcp, Socket, Data} ->
T = binary_to_list(Data),
Cont1 = jsf:decode(lists:append(Cont, T), HandlerMod),

View File

@@ -65,7 +65,7 @@ cold_start(Port, Fun, Max, PacketType, PacketSize) ->
process_flag(trap_exit, true),
%% io:format("Starting a port server on ~p...~n",[Port]),
DefaultListenOptions =
[binary, {nodelay, true}, {active, true}, {reuseaddr, true}, {backlog, 100}],
[binary, {nodelay, true}, {active, false}, {reuseaddr, true}, {backlog, 100}],
ListenOptions =
case {PacketType, PacketSize} of
{0,0} ->
@@ -120,7 +120,6 @@ start_child(Parent, Listen, Fun) ->
case gen_tcp:accept(Listen) of
{ok, Socket} ->
Parent ! {started, self()}, % tell the controller
inet:setopts(Socket, [{active, true}]), % before we activate socket
%% Start the child
%% io:format("Starting a child on:~p~n",[Socket]),
case (catch Fun(Socket)) of
@@ -129,6 +128,7 @@ start_child(Parent, Listen, Fun) ->
{'EXIT', socket_closed} ->
true;
{'EXIT', Why} ->
gen_tcp:close(Socket),
exit(Why)
end;
_Other ->

View File

@@ -141,7 +141,10 @@ ubf_client(Parent, Host, Port, Options, Timeout)
gen_tcp:controlling_process(Socket, Driver),
%% Kick off the driver
Driver ! {start, Socket, self()}, % tell the controller
inet:setopts(Socket, [{active, true}]), % before we activate socket
inet:setopts(Socket, [{active, true}
%%, {send_timeout, Timeout}
%%, {send_timeout_close, true}
]),
%% wait for a startup message
receive
{Driver, {DriverVersion, Service, _}} ->

View File

@@ -37,7 +37,7 @@ loop(Socket, Pid, Timeout, Cont) ->
receive
{Pid, Term} ->
Data = ubf:encode(Term),
gen_tcp:send(Socket, [Data,"\n"]),
ok = gen_tcp:send(Socket, [Data,"\n"]),
loop(Socket, Pid, Timeout, Cont);
stop ->
Pid ! stop,
@@ -50,9 +50,9 @@ loop(Socket, Pid, Timeout, Cont) ->
{tcp_closed, Socket} ->
Pid ! stop,
exit(socket_closed);
{tcp_error, Socket} ->
{tcp_error, Socket, Reason} ->
gen_tcp:close(Socket),
exit(socket_error);
exit({socket_error,Reason});
{tcp, Socket, Data} ->
T = binary_to_list(Data),
Cont1 = ubf:decode(T, Cont),

View File

@@ -189,6 +189,10 @@ start_ubf_listener(MetaServerModule, Port, Server, Options) ->
Server, MetaServerModule},
%% and activate the loop that will now
%% execute the last two statements :-)
inet:setopts(Socket, [{active, true}
%%, {send_timeout, IdleTimer}
%%, {send_timeout_close, true}
]),
DriverModule:loop(Socket, self(), IdleTimer)
end,
proplists:get_value(maxconn,Options,10000),