Skip to content

Commit

Permalink
[sio][network] alloc 65535 bytes for write buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Aug 17, 2023
1 parent 59d01da commit 0c7b904
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/device/sio/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ void sioNetwork::sio_open()

sio_ack();

newData = (uint8_t *)malloc(NEWDATA_SIZE);

if (!newData)
{
Debug_printv("Could not allocate write buffer\n");
sio_error();
}

channelMode = PROTOCOL;

// Delete timer if already extant.
Expand Down Expand Up @@ -123,6 +131,9 @@ void sioNetwork::sio_open()
protocolParser = nullptr;
}

if (newData)
free(newData);

sio_error();
return;
}
Expand All @@ -139,6 +150,10 @@ void sioNetwork::sio_open()
delete protocolParser;
protocolParser = nullptr;
}

if (newData)
free(newData);

sio_error();
return;
}
Expand Down Expand Up @@ -198,6 +213,9 @@ void sioNetwork::sio_close()
if (json != nullptr)
delete json;

if (newData)
free(newData);

Debug_printv("After protocol delete %lu\n",esp_get_free_internal_heap_size());
}

Expand Down Expand Up @@ -293,7 +311,6 @@ void sioNetwork::sio_write()
unsigned short num_bytes = sio_get_aux();
bool err = false;

uint8_t *newData = (uint8_t *)malloc(num_bytes);
Debug_printf("sioNetwork::sio_write( %d bytes)\n", num_bytes);

if (newData == nullptr)
Expand All @@ -315,14 +332,12 @@ void sioNetwork::sio_write()
}
status.error = NETWORK_ERROR_NOT_CONNECTED;
sio_error();
free(newData);
return;
}

// Get the data from the Atari
bus_to_peripheral(newData, num_bytes);
*transmitBuffer += string((char *)newData, num_bytes);
free(newData);

// Do the channel write
err = sio_write_channel(num_bytes);
Expand Down
6 changes: 6 additions & 0 deletions lib/device/sio/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ class sioNetwork : public virtualDevice
*/
unsigned short json_bytes_remaining=0;

/**
* @brief the write buffer
*/
uint8_t *newData;
#define NEWDATA_SIZE 65535

/**
* Instantiate protocol object
* @return bool TRUE if protocol successfully called open(), FALSE if protocol could not open
Expand Down

0 comments on commit 0c7b904

Please sign in to comment.