Moved 8 static error functions to sysdeps/common/error.c. This is the end
* include/glibtop/error.h: Moved 8 static error functions to sysdeps/common/error.c. This is the end of an big useless code bloat : expect ~8KB of object size reduction. * include/glibtop/procuid.h: s/int/gint32/g * lib/errors.c: (glibtop_error_quark): * lib/read.c: (do_read), (glibtop_read_l): * lib/read_data.c: (glibtop_read_data_l): Minor cleanups.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
||||
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* include/glibtop/error.h: Moved 8 static error functions to
|
||||
sysdeps/common/error.c. This is the end of an big useless code
|
||||
bloat : expect ~8KB of object size reduction.
|
||||
|
||||
* include/glibtop/procuid.h: s/int/gint32/g
|
||||
|
||||
* lib/errors.c: (glibtop_error_quark):
|
||||
* lib/read.c: (do_read), (glibtop_read_l):
|
||||
* lib/read_data.c: (glibtop_read_data_l): Minor cleanups.
|
||||
|
||||
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* sysdeps/names/netload.c:
|
||||
|
@@ -28,60 +28,17 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifndef G_GNUC_UNUSED
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
|
||||
#define G_GNUC_UNUSED \
|
||||
__attribute__((unused))
|
||||
#else /* !__GNUC__ */
|
||||
#define G_GNUC_UNUSED
|
||||
#endif /* !__GNUC__ */
|
||||
#endif /* defined G_GNUC_UNUSED */
|
||||
|
||||
void glibtop_error_vr (glibtop *server, char *format, va_list args);
|
||||
void glibtop_warn_vr (glibtop *server, char *format, va_list args);
|
||||
|
||||
void glibtop_error_io_vr (glibtop *server, char *format, int, va_list args);
|
||||
void glibtop_warn_io_vr (glibtop *server, char *format, int, va_list args);
|
||||
|
||||
static void G_GNUC_UNUSED
|
||||
glibtop_error_r (glibtop *server, char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
void G_GNUC_UNUSED glibtop_error_r (glibtop *server, char *format, ...);
|
||||
void G_GNUC_UNUSED glibtop_warn_r (glibtop *server, char *format, ...);
|
||||
void G_GNUC_UNUSED glibtop_error_io_r (glibtop *server, char *format, ...);
|
||||
void G_GNUC_UNUSED glibtop_warn_io_r (glibtop *server, char *format, ...);
|
||||
|
||||
va_start (args, format);
|
||||
glibtop_error_vr (server, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void G_GNUC_UNUSED
|
||||
glibtop_warn_r (glibtop *server, char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
glibtop_warn_vr (server, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void G_GNUC_UNUSED
|
||||
glibtop_error_io_r (glibtop *server, char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
glibtop_error_io_vr (server, format, errno, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void G_GNUC_UNUSED
|
||||
glibtop_warn_io_r (glibtop *server, char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
glibtop_warn_io_vr (server, format, errno, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
@@ -93,41 +50,10 @@ glibtop_warn_io_r (glibtop *server, char *format, ...)
|
||||
|
||||
#else /* no __GNUC__ */
|
||||
|
||||
static void
|
||||
glibtop_error (char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
glibtop_error_vr (glibtop_global_server, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void
|
||||
glibtop_warn (char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
glibtop_warn_vr (glibtop_global_server, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void
|
||||
glibtop_error_io (char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
glibtop_error_io_vr (glibtop_global_server, format, errno, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void
|
||||
glibtop_warn_io (char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
glibtop_warn_io_vr (glibtop_global_server, format, errno, args);
|
||||
va_end (args);
|
||||
}
|
||||
void glibtop_error (char *format, ...);
|
||||
void glibtop_warn (char *format, ...);
|
||||
void glibtop_error_io (char *format, ...);
|
||||
void glibtop_warn_io (char *format, ...);
|
||||
|
||||
#endif /* no __GNUC__ */
|
||||
|
||||
|
@@ -59,7 +59,7 @@ typedef struct _glibtop_proc_uid glibtop_proc_uid;
|
||||
struct _glibtop_proc_uid
|
||||
{
|
||||
guint64 flags;
|
||||
int uid, /* user id */
|
||||
gint32 uid, /* user id */
|
||||
euid, /* effective user id */
|
||||
gid, /* group id */
|
||||
egid, /* effective group id */
|
||||
|
@@ -32,7 +32,7 @@ GQuark
|
||||
glibtop_error_quark (void)
|
||||
{
|
||||
static GQuark q = 0;
|
||||
if (q == 0)
|
||||
if (G_UNLIKELY(q == 0))
|
||||
q = g_quark_from_static_string ("glibtop-error-quark");
|
||||
|
||||
return q;
|
||||
|
44
lib/read.c
44
lib/read.c
@@ -31,37 +31,25 @@
|
||||
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;
|
||||
ssize_t nread;
|
||||
|
||||
while (already_read < total_size) {
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
if(!total_size) return;
|
||||
|
||||
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;
|
||||
while (total_size && (nread = recv (s, ptr, total_size, 0)) > 0) {
|
||||
total_size -= nread;
|
||||
ptr = (char*)ptr + nread;
|
||||
}
|
||||
|
||||
if(nread == 0)
|
||||
close (s);
|
||||
|
||||
if (nread < 0)
|
||||
glibtop_error_io ("recv");
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_read_l (glibtop *server, size_t size, void *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -71,9 +59,11 @@ glibtop_read_l (glibtop *server, size_t size, void *buf)
|
||||
if (server->socket) {
|
||||
do_read (server->socket, buf, size);
|
||||
} else {
|
||||
ret = read (server->input [0], buf, size);
|
||||
if(read (server->input [0], buf, size) < 0)
|
||||
glibtop_error_io_r (
|
||||
server,
|
||||
ngettext ("read %d byte",
|
||||
"read %d bytes", size),
|
||||
size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, ngettext ("read %d byte", "read %d bytes", size), size);
|
||||
}
|
||||
|
@@ -42,9 +42,9 @@ glibtop_read_data_l (glibtop *server)
|
||||
#endif
|
||||
|
||||
if (server->socket) {
|
||||
ret = recv (server->socket, (void *)&size, sizeof (size_t), 0);
|
||||
ret = recv (server->socket, &size, sizeof (size_t), 0);
|
||||
} else {
|
||||
ret = read (server->input [0], (void *)&size, sizeof (size_t));
|
||||
ret = read (server->input [0], &size, sizeof (size_t));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
|
Reference in New Issue
Block a user