Skip to content

Commit

Permalink
console: Use 2k buffer by default and add setBufferSize
Browse files Browse the repository at this point in the history
No need to append extra zeroes, so set the default to 2k exactly.
Allow clients to change the buffer size, convenient when reading large
amounts of data from a subprocess like a screenshot.
  • Loading branch information
Mike Looijmans authored and Schimmelreiter committed Jan 17, 2017
1 parent 2bf6322 commit 6add8cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/base/console.cpp
Expand Up @@ -60,7 +60,7 @@ DEFINE_REF(eConsoleAppContainer);
eConsoleAppContainer::eConsoleAppContainer():
pid(-1),
killstate(0),
buffer(2049)
buffer(2048)
{
for (int i=0; i < 3; ++i)
{
Expand All @@ -83,6 +83,12 @@ int eConsoleAppContainer::setCWD( const char *path )
return 0;
}

void eConsoleAppContainer::setBufferSize(int size)
{
if (size > 0)
buffer.resize(size);
}

int eConsoleAppContainer::execute( const char *cmd )
{
int argc = 3;
Expand Down Expand Up @@ -227,7 +233,7 @@ void eConsoleAppContainer::readyRead(int what)
// eDebug("what = %d");
char* buf = &buffer[0];
int rd;
while((rd = read(fd[0], buf, 2048)) > 0)
while((rd = read(fd[0], buf, buffer.size())) > 0)
{
buf[rd]=0;
/*emit*/ dataAvail(std::make_pair(buf, rd));
Expand Down Expand Up @@ -266,7 +272,7 @@ void eConsoleAppContainer::readyErrRead(int what)
// eDebug("what = %d");
char* buf = &buffer[0];
int rd;
while((rd = read(fd[2], buf, 2048)) > 0)
while((rd = read(fd[2], buf, buffer.size())) > 0)
{
/* for ( int i = 0; i < rd; i++ )
eDebug("%d = %c (%02x)", i, buf[i], buf[i] );*/
Expand Down Expand Up @@ -309,7 +315,7 @@ void eConsoleAppContainer::readyWrite(int what)
if ( filefd[0] >= 0 )
{
char* buf = &buffer[0];
int rsize = read(filefd[0], buf, 2048);
int rsize = read(filefd[0], buf, buffer.size());
if ( rsize > 0 )
write(buf, rsize);
else
Expand Down
1 change: 1 addition & 0 deletions lib/base/console.h
Expand Up @@ -38,6 +38,7 @@ class eConsoleAppContainer: public Object, public iObject
eConsoleAppContainer();
~eConsoleAppContainer();
int setCWD( const char *path );
void setBufferSize(int size);
int execute( const char *str );
int execute( const char *cmdline, const char *const argv[] );
int getPID() { return pid; }
Expand Down
13 changes: 13 additions & 0 deletions lib/python/python_console.i
Expand Up @@ -217,6 +217,16 @@ eConsolePy_setCWD(eConsolePy* self, PyObject *args)
Py_RETURN_NONE;
}

static PyObject *
eConsolePy_setBufferSize(eConsolePy* self, PyObject *args)
{
int size = 0;
if (!PyArg_ParseTuple(args, "i", &size))
return NULL;
self->cont->setBufferSize(size);
Py_RETURN_NONE;
}

static PyObject *
eConsolePy_kill(eConsolePy* self)
{
Expand Down Expand Up @@ -291,6 +301,9 @@ static PyMethodDef eConsolePy_methods[] = {
{"setCWD", (PyCFunction)eConsolePy_setCWD, METH_VARARGS,
"set working dir"
},
{"setBufferSize", (PyCFunction)eConsolePy_setBufferSize, METH_VARARGS,
"set transfer buffer size"
},
{"execute", (PyCFunction)eConsolePy_execute, METH_VARARGS,
"execute command"
},
Expand Down

3 comments on commit 6add8cf

@dvb-adenin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Schimmelreiter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sieht eher danach aus, als ob auf der Box noch ein altes e2 aber schon das neue OWIF läuft.

@Schimmelreiter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sieht man auch ganz klar im Log:

00:54:17.031 { D }   File "/home/oe1/nightly53/build-enviroment/builds/openatv/release/dags7362/tmp/work/all-oe-linux/enigma2-plugin-extensions-openwebif/1+gitAUTOINC+9ee5b2d86c-r1/git/plugin/controllers/models/grab.py", line 23, in __init__
00:54:17.032 { D } AttributeError: 'eConsoleImpl.eConsoleAppContainer' object has no attribute 'setBufferSize'

has no attribute 'setBufferSize'

Das Problem ist also nicht dieser Commit, sondern das Fehlen davon.

Please sign in to comment.