Skip to content

Commit

Permalink
fix(xod-client, xod-client-electron): clear the queued chunks of a re…
Browse files Browse the repository at this point in the history
…sponse data on connection close
  • Loading branch information
brusherru committed Jun 19, 2020
1 parent 219395c commit 8b34f9c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ const createListener = (dispatch, transmit, nodeId) =>

const isReadOkResponse = R.startsWith(ACK);

// In case that the connection is closed before than all request has been received
// there is no reason to continue sending the response data.
const clearQueueOnCloseConnection = R.curry((dispatch, command) =>
R.when(
R.equals('AT+CIPCLOSE'),
R.compose(dispatch, client.tetheringInetClearChunks)
)(command)
);

export default ({ getState, dispatch }) => next => action => {
const state = getState();
const result = next(action);
Expand All @@ -86,7 +95,10 @@ export default ({ getState, dispatch }) => next => action => {
const worker = action.payload.worker;
const transmit = createTransmitter(dispatch, worker.sendToWasm);
const listener = createListener(dispatch, transmit, nodeId);
const write = AtNet.create(listener);
const write = R.compose(
AtNet.create(listener),
R.tap(clearQueueOnCloseConnection(dispatch))
);
dispatch(
client.tetheringInetCreated(
action.payload.tetheringInetNodeId,
Expand Down
2 changes: 2 additions & 0 deletions packages/xod-client/src/debugger/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ export const TETHERING_INET_CREATED = 'TETHERING_INET_CREATED';
export const TETHERING_INET_CHUNKS_ADDED = 'TETHERING_INET_CHUNKS_ADDED';

export const TETHERING_INET_CHUNK_SENT = 'TETHERING_INET_CHUNK_SENT';

export const TETHERING_INET_CLEAR_CHUNKS = 'TETHERING_INET_CLEAR_CHUNKS';
4 changes: 4 additions & 0 deletions packages/xod-client/src/debugger/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ export const tetheringInetChunkSent = () => (dispatch, getState) => {
});
return maybeProp(0, chunksToSend);
};

export const tetheringInetClearChunks = () => ({
type: AT.TETHERING_INET_CLEAR_CHUNKS,
});
3 changes: 3 additions & 0 deletions packages/xod-client/src/debugger/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TETHERING_INET_CREATED,
TETHERING_INET_CHUNKS_ADDED,
TETHERING_INET_CHUNK_SENT,
TETHERING_INET_CLEAR_CHUNKS,
} from './actionTypes';

import * as EAT from '../editor/actionTypes';
Expand Down Expand Up @@ -531,6 +532,8 @@ export default (state = initialState, action) => {
R.tail,
state
);
case TETHERING_INET_CLEAR_CHUNKS:
return R.assocPath(['tetheringInet', 'chunksToSend'], [], state);

case EAT.TABTEST_RUN_REQUESTED:
return R.compose(
Expand Down

0 comments on commit 8b34f9c

Please sign in to comment.