Skip to content
Browse files

the c-node will chop up reply list in bits of 1,000, to alleviate

  timeout problems.


git-svn-id: https://gtknode.googlecode.com/svn/trunk@27 9999ab98-4a1b-0410-ba6a-d90168ca9a37
  • Loading branch information...
1 parent 76e05b9 commit a9c14c5684ed1fb0bf7eaf84a4c1daf87bdaaedd @massemanet committed
Showing with 45 additions and 22 deletions.
  1. +30 −15 c_src/gtknode_cnode.c
  2. +15 −7 src/gtknode.erl
View
45 c_src/gtknode_cnode.c
@@ -87,34 +87,49 @@ static gboolean make_reply(ei_x_buff *xbuf, char *buff, int *index) {
return FALSE;
}
-static void make_reply_list(ei_x_buff *xbuf, char *buff, int *index) {
-
- gint arity, i;
-
+static void make_xbuf(ei_x_buff *xbuf) {
+ ei_x_new_with_version(xbuf);
gn_wrap_ans("reply",xbuf);
+}
- if ( ! ((arity = gn_get_list(xbuf, buff, index)) > -1) )
+static void send_xbuf(ei_x_buff *xbuf){
+ gn_send(xbuf);
+ ei_x_free(xbuf);
+}
+
+static void send_replies(char *buff, int *index) {
+ ei_x_buff xbuf;
+ gint arity, i;
+
+ make_xbuf(&xbuf);
+
+ if ( ! ((arity = gn_get_list(&xbuf, buff, index)) > -1) ) {
+ send_xbuf(&xbuf);
return;
+ }
for (i = 0; i < arity; i++) {
- ei_x_encode_list_header(xbuf, 1);
- if ( ! make_reply(xbuf, buff, index) )
+ if ( ((i+1)%1000) == 0 ) {
+ ei_x_encode_empty_list(&xbuf);
+ send_xbuf(&xbuf);
+ make_xbuf(&xbuf);
+ }
+ ei_x_encode_list_header(&xbuf, 1);
+ if ( ! make_reply(&xbuf, buff, index) )
break;
}
- ei_x_encode_empty_list(xbuf);
+
+ ei_x_encode_empty_list(&xbuf);
+ send_xbuf(&xbuf);
}
static void reply(erlang_msg *msg, ei_x_buff *recv_x_buf) {
- int i = 0;
+ int index = 0;
int version;
- ei_x_buff xbuf;
- ei_decode_version(recv_x_buf->buff, &i, &version);
- ei_x_new_with_version(&xbuf);
- make_reply_list(&xbuf, recv_x_buf->buff, &i);
- gn_send(&xbuf);
- ei_x_free(&xbuf);
+ ei_decode_version(recv_x_buf->buff, &index, &version);
+ send_replies(recv_x_buf->buff, &index);
}
/* called from gtk main loop when there's data on the cnode socket */
View
22 src/gtknode.erl
@@ -90,10 +90,13 @@ loopDBGH() ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cmd(GUI,C,As) -> cmd(GUI,[{C,As}]).
+cmd(_GUI,[]) ->
+ {'EXIT',{foobar,St}} = (catch erlang:error(foobar)), ?LOG({empty,St});
cmd(GUI,CAs) ->
GUI ! {self(),CAs},
receive
- {GUI,{reply,Reps}} -> filter_reps(Reps,CAs)
+ {GUI,{reply,Reps}} -> ?LOG([{l_ca,length(CAs)},{l_rep,length(Reps)}]),
+ filter_reps(Reps,CAs)
end.
filter_reps([{ok,Rep}],[_]) -> Rep;
@@ -180,7 +183,7 @@ idle(St = #st{gtk_pid=GtkPid, gtk_port=Port, handler_pid=HandPid}) ->
{Pid,CmdArgs} when pid(Pid) ->
%%from client
GtkPid ! CmdArgs,
- waiting(St#st{client_pid = Pid},CmdArgs);
+ waiting(St#st{client_pid = Pid},CmdArgs,[]);
{Port,PortData} ->
%%from the port
idle(handle_portdata(St, PortData));
@@ -194,19 +197,24 @@ idle(St = #st{gtk_pid=GtkPid, gtk_port=Port, handler_pid=HandPid}) ->
die(quitting)
end.
-waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port},CmdArgs) ->
+waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port},CmdArgs,OldReps) ->
receive
{{GtkPid,reply}, Ans}-> %from gtknode
- St#st.client_pid ! {St#st.name, {reply,Ans}},
- idle(St#st{client_pid = []});
+ case length(Reps=OldReps++Ans)-length(CmdArgs) of
+ 0 ->
+ St#st.client_pid ! {St#st.name, {reply,Reps}},
+ idle(St#st{client_pid = []});
+ _ ->
+ waiting(St,CmdArgs,Reps)
+ end;
{Port,{data,PortData}} -> %from the port
- waiting(handle_portdata(St, PortData),CmdArgs);
+ waiting(handle_portdata(St, PortData),CmdArgs,OldReps);
{'EXIT',Port,Reason} -> %port died, us too
die({port_died,{Reason,CmdArgs}});
quit ->
die(quitting)
after
- ?BORED -> waiting(bored(waiting,St),CmdArgs)
+ ?BORED -> waiting(bored(waiting,St),CmdArgs,OldReps)
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 comments on commit a9c14c5

Please sign in to comment.
Something went wrong with that request. Please try again.