1 | /* $Id: read_data.c,v 1.1.1.2 2004-10-03 04:59:56 ghudson Exp $ */ |
---|
2 | |
---|
3 | /* Copyright (C) 1998-99 Martin Baulig |
---|
4 | This file is part of LibGTop 1.0. |
---|
5 | |
---|
6 | Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. |
---|
7 | |
---|
8 | LibGTop is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, |
---|
11 | or (at your option) any later version. |
---|
12 | |
---|
13 | LibGTop is distributed in the hope that it will be useful, but WITHOUT |
---|
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
16 | for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with LibGTop; see the file COPYING. If not, write to the |
---|
20 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | |
---|
26 | #include <glibtop/read_data.h> |
---|
27 | #include "libgtop-i18n.h" |
---|
28 | |
---|
29 | /* Reads some data from server. */ |
---|
30 | |
---|
31 | void * |
---|
32 | glibtop_read_data_l (glibtop *server) |
---|
33 | { |
---|
34 | size_t size; |
---|
35 | void *ptr; |
---|
36 | int ret; |
---|
37 | |
---|
38 | glibtop_init_r (&server, 0, 0); |
---|
39 | |
---|
40 | #ifdef DEBUG |
---|
41 | fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t)); |
---|
42 | #endif |
---|
43 | |
---|
44 | if (server->socket) { |
---|
45 | ret = recv (server->socket, &size, sizeof (size_t), 0); |
---|
46 | } else { |
---|
47 | ret = read (server->input [0], &size, sizeof (size_t)); |
---|
48 | } |
---|
49 | |
---|
50 | if (ret < 0) |
---|
51 | glibtop_error_io_r (server, _("read data size")); |
---|
52 | |
---|
53 | #ifdef DEBUG |
---|
54 | fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret); |
---|
55 | #endif |
---|
56 | |
---|
57 | if (!size) return NULL; |
---|
58 | |
---|
59 | ptr = g_malloc (size); |
---|
60 | |
---|
61 | if (server->socket) { |
---|
62 | ret = recv (server->socket, ptr, size, 0); |
---|
63 | } else { |
---|
64 | ret = read (server->input [0], ptr, size); |
---|
65 | } |
---|
66 | |
---|
67 | if (ret < 0) |
---|
68 | glibtop_error_io_r (server, ngettext ("read data %d byte", "read data %d bytes", size)); |
---|
69 | |
---|
70 | return ptr; |
---|
71 | } |
---|