diff options
author | Carlos Perelló Marín <carlos@gnome.org> | 2003-10-19 16:55:56 +0000 |
---|---|---|
committer | Carlos Perelló Marín <carlos@src.gnome.org> | 2003-10-19 16:55:56 +0000 |
commit | 4c8ae9e25c1940d8876ca3f2330426863cae4737 (patch) | |
tree | c43f97bc0647546b0ed87022db0749c137f24edc /lib | |
parent | bae16b467f90df94d80feae41dceb7e816f16c61 (diff) | |
download | libgtop-4c8ae9e25c1940d8876ca3f2330426863cae4737.tar.gz |
Reverted libgtop changes. It's a common module and I should not modify it.
2003-10-19 Carlos Perelló Marín <carlos@gnome.org>
* support/*: Reverted libgtop changes. It's a common module
and I should not modify it.
* Added/removed files. Now the move should be done.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/command.c | 77 | ||||
-rw-r--r-- | lib/read.c | 76 | ||||
-rw-r--r-- | lib/read_data.c | 69 | ||||
-rw-r--r-- | lib/write.c | 49 |
4 files changed, 271 insertions, 0 deletions
diff --git a/lib/command.c b/lib/command.c new file mode 100644 index 00000000..be59c38d --- /dev/null +++ b/lib/command.c @@ -0,0 +1,77 @@ +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <glibtop/read.h> +#include <glibtop/write.h> +#include <glibtop/read_data.h> + +#include <glibtop/command.h> +#include <glibtop/xmalloc.h> + +void * +glibtop_call_l (glibtop *server, unsigned command, size_t send_size, + const void *send_buf, size_t recv_size, void *recv_buf) +{ + glibtop_command cmnd; + glibtop_response response; + + glibtop_init_r (&server, 0, 0); + + memset (&cmnd, 0, sizeof (glibtop_command)); + + cmnd.command = command; + + /* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we + * send it together with command, so we only need one system call instead + * of two. */ + + if (send_size <= _GLIBTOP_PARAM_SIZE) { + memcpy (cmnd.parameter, send_buf, send_size); + cmnd.size = send_size; + } else { + cmnd.data_size = send_size; + } + + glibtop_write_l (server, sizeof (glibtop_command), &cmnd); + + glibtop_read_l (server, sizeof (glibtop_response), &response); + +#ifdef DEBUG + fprintf (stderr, "RESPONSE: %lu - %d\n", + response.offset, response.data_size); +#endif + + if (recv_buf) + memcpy (recv_buf, ((char *) &response) + response.offset, + recv_size); + + if (response.data_size) { + void *ptr = glibtop_malloc_r (server, response.data_size); + + glibtop_read_l (server, response.data_size, ptr); + + return ptr; + } + + return NULL; +} diff --git a/lib/read.c b/lib/read.c new file mode 100644 index 00000000..dd6af726 --- /dev/null +++ b/lib/read.c @@ -0,0 +1,76 @@ +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <glibtop/read.h> + +/* Reads some data from server. */ + +static void +do_read (int s, void *ptr, size_t total_size) +{ + int nread; + size_t already_read = 0, remaining = total_size; + char *tmp_ptr; + + while (already_read < total_size) { + nread = recv (s, ptr, remaining, 0); + + if (nread == 0) { + close (s); + continue; + } + + if (nread <= 0) { + glibtop_error_io ("recv"); + return; + } + + already_read += nread; + remaining -= nread; + /* (char *) ptr += nread; */ + tmp_ptr = ptr; + tmp_ptr += nread; + ptr = tmp_ptr; + } +} + +void +glibtop_read_l (glibtop *server, size_t size, void *buf) +{ + int ret = 0; + + glibtop_init_r (&server, 0, 0); + +#ifdef DEBUG + fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size); +#endif + + if (server->socket) { + do_read (server->socket, buf, size); + } else { + ret = read (server->input [0], buf, size); + } + + if (ret < 0) + glibtop_error_io_r (server, _("read %d bytes"), size); +} diff --git a/lib/read_data.c b/lib/read_data.c new file mode 100644 index 00000000..8c1bc416 --- /dev/null +++ b/lib/read_data.c @@ -0,0 +1,69 @@ +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <glibtop/xmalloc.h> +#include <glibtop/read_data.h> + +/* Reads some data from server. */ + +void * +glibtop_read_data_l (glibtop *server) +{ + size_t size; + void *ptr; + int ret; + + glibtop_init_r (&server, 0, 0); + +#ifdef DEBUG + fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t)); +#endif + + if (server->socket) { + ret = recv (server->socket, (void *)&size, sizeof (size_t), 0); + } else { + ret = read (server->input [0], (void *)&size, sizeof (size_t)); + } + + if (ret < 0) + glibtop_error_io_r (server, _("read data size")); + +#ifdef DEBUG + fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret); +#endif + + if (!size) return NULL; + + ptr = glibtop_malloc_r (server, size); + + if (server->socket) { + ret = recv (server->socket, ptr, size, 0); + } else { + ret = read (server->input [0], ptr, size); + } + + if (ret < 0) + glibtop_error_io_r (server, _("read data %d bytes")); + + return ptr; +} diff --git a/lib/write.c b/lib/write.c new file mode 100644 index 00000000..591badd2 --- /dev/null +++ b/lib/write.c @@ -0,0 +1,49 @@ +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <glibtop/write.h> + +/* Writes some data to server. */ + +void +glibtop_write_l (glibtop *server, size_t size, void *buf) +{ + int ret; + + glibtop_init_r (&server, 0, 0); + + if (size == 0) return; + +#ifdef DEBUG + fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size); +#endif + + if (server->socket) { + ret = send (server->socket, buf, size, 0); + } else { + ret = write (server->output [1], buf, size); + } + + if (ret < 0) + glibtop_error_io_r (server, _("write %d bytes"), size); +} |