*** empty log message ***

This commit is contained in:
Martin Baulig
2000-01-02 17:15:15 +00:00
parent fa5d2af7ea
commit 386f66d7e2
11 changed files with 148 additions and 55 deletions

View File

@@ -41,6 +41,7 @@ glibtop_call_i (glibtop *server, glibtop_backend *backend, unsigned command,
int *retval_ptr) int *retval_ptr)
{ {
glibtop_command cmnd; glibtop_command cmnd;
glibtop_response resp;
#if 0 #if 0
int retval; int retval;
#endif #endif
@@ -48,6 +49,7 @@ glibtop_call_i (glibtop *server, glibtop_backend *backend, unsigned command,
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
memset (&cmnd, 0, sizeof (glibtop_command)); memset (&cmnd, 0, sizeof (glibtop_command));
memset (&resp, 0, sizeof (glibtop_response));
cmnd.command = command; cmnd.command = command;
@@ -64,22 +66,26 @@ glibtop_call_i (glibtop *server, glibtop_backend *backend, unsigned command,
glibtop_write_i (server, backend, sizeof (glibtop_command), &cmnd); glibtop_write_i (server, backend, sizeof (glibtop_command), &cmnd);
#if 0 glibtop_read_i (server, backend, sizeof (glibtop_response), &resp);
glibtop_read_i (server, backend, sizeof (glibtop_response), &response);
#ifdef DEBUG fprintf (stderr, "RESPONSE: %d - %d - %ld - %ld - %p - %ld\n",
fprintf (stderr, "RESPONSE: %lu - %d\n", resp.retval, resp.glibtop_errno,
response.offset, response.data_size); (long) resp.recv_size, (long) resp.data_size,
#endif recv_ptr, (long) recv_size);
glibtop_read_i (server, backend, sizeof (int), &retval);
if (retval_ptr) if (retval_ptr)
*retval_ptr = retval; *retval_ptr = resp.glibtop_errno;
if (recv_buf) if (resp.recv_size != recv_size) {
memcpy (recv_buf, ((char *) &response) + response.offset, glibtop_warn_r (server, "Expected %ld bytes, but got %ld.",
recv_size); (long) recv_size, (long) resp.recv_size);
return NULL;
}
if (recv_ptr)
glibtop_read_i (server, backend, recv_size, recv_ptr);
#if 0
if (response.data_size) { if (response.data_size) {
void *ptr = glibtop_malloc_r (server, response.data_size); void *ptr = glibtop_malloc_r (server, response.data_size);

View File

@@ -94,11 +94,13 @@ sub output {
$need_temp_storage = $always_use_temp_storage; $need_temp_storage = $always_use_temp_storage;
$first_param_name = ''; $first_param_name = '';
$size_code = "\t_LIBGTOP_SEND_len = 0;\n"; $size_code = "\t/* send size */\n";
$size_code .= "\t_LIBGTOP_SEND_len = 0;\n";
$local_var_decl_code = ''; $local_var_decl_code = '';
$local_var_decl_code .= "\tsize_t _LIBGTOP_SEND_len;\n"; $local_var_decl_code .= "\tsize_t _LIBGTOP_SEND_len, _LIBGTOP_RECV_len;\n";
$local_var_decl_code .= "\toff_t _LIBGTOP_SEND_offset;\n"; $local_var_decl_code .= "\toff_t _LIBGTOP_SEND_offset;\n";
$local_var_decl_code .= "\tchar *_LIBGTOP_RECV_buf, *_LIBGTOP_RECV_ptr;\n";
$local_var_decl_code .= "\tconst char *_LIBGTOP_SEND_ptr;\n"; $local_var_decl_code .= "\tconst char *_LIBGTOP_SEND_ptr;\n";
$local_var_decl_code .= sprintf $local_var_decl_code .= sprintf
(qq[\tglibtop_%s %s;\n], $feature, $feature); (qq[\tglibtop_%s %s;\n], $feature, $feature);
@@ -107,7 +109,7 @@ sub output {
$retval, $retval); $retval, $retval);
} }
$init_local_var_code = ''; $init_local_var_code = "\t/* variable initialization */\n";
$init_local_var_code .= sprintf $init_local_var_code .= sprintf
(qq[\tmemset (&%s, 0, sizeof (glibtop_%s));\n], $feature, $feature); (qq[\tmemset (&%s, 0, sizeof (glibtop_%s));\n], $feature, $feature);
$init_local_var_code .= "\t_LIBGTOP_SEND_offset = 0;\n"; $init_local_var_code .= "\t_LIBGTOP_SEND_offset = 0;\n";
@@ -191,7 +193,8 @@ sub output {
} }
if (!($demarshal_code eq '')) { if (!($demarshal_code eq '')) {
$demarshal_code .= "\n"; $demarshal_code = sprintf (qq[\t/* demarshal start */\n%s\n],
$demarshal_code);
} }
if ($need_temp_storage) { if ($need_temp_storage) {
@@ -237,11 +240,70 @@ sub output {
$size_code .= sprintf $size_code .= sprintf
(qq[\tif (_LIBGTOP_SEND_len != send_size)\n\t\treturn -GLIBTOP_ERROR_DEMARSHAL_ERROR;\n\n]); (qq[\tif (_LIBGTOP_SEND_len != send_size)\n\t\treturn -GLIBTOP_ERROR_DEMARSHAL_ERROR;\n\n]);
$size_code .= "\t/* recv size */\n";
$size_code .= "\t_LIBGTOP_RECV_len = 0;\n";
if ($line_fields[3] eq '') {
} elsif ($line_fields[3] eq 'array') {
$size_code .= "\t_LIBGTOP_RECV_len += sizeof (glibtop_array);\n";
} elsif ($line_fields[3] =~ /^array/) {
$size_code .= "\t_LIBGTOP_RECV_len += sizeof (glibtop_array);\n";
$size_code .= sprintf
(qq[\t_LIBGTOP_RECV_len += sizeof (glibtop_%s);\n], $feature);
} else {
$size_code .= sprintf
(qq[\t_LIBGTOP_RECV_len += sizeof (glibtop_%s);\n], $feature);
}
$size_code .= "\n";
$size_code .= "\t/* recv buffer */\n";
if ($line_fields[3] eq '') {
$size_code .= "\t_LIBGTOP_RECV_buf = NULL;\n";
} else {
$size_code .= "\t_LIBGTOP_RECV_buf = glibtop_malloc_r (server, _LIBGTOP_RECV_len);\n";
}
$size_code .= "\t_LIBGTOP_RECV_ptr = _LIBGTOP_RECV_buf;\n\n";
$recv_buf_code = '';
if ($line_fields[3] eq '') {
} elsif ($line_fields[3] eq 'array') {
$recv_buf_code = "\t/* write recv buffer */\n";
$recv_buf_code .= sprintf
(qq[\tmemcpy (_LIBGTOP_RECV_ptr, &array, sizeof (glibtop_array));\n]);
$recv_buf_code .= sprintf
(qq[\t_LIBGTOP_RECV_ptr += sizeof (glibtop_array);\n]);
} elsif ($line_fields[3] =~ /^array/) {
$recv_buf_code = "\t/* write recv buffer */\n";
$recv_buf_code .= sprintf
(qq[\tmemcpy (_LIBGTOP_RECV_ptr, &array, sizeof (glibtop_array));\n]);
$recv_buf_code .= sprintf
(qq[\t_LIBGTOP_RECV_ptr += sizeof (glibtop_array);\n]);
$recv_buf_code .= sprintf
(qq[\tmemcpy (_LIBGTOP_RECV_ptr, &%s, sizeof (glibtop_%s));\n],
$feature, $feature);
$recv_buf_code .= sprintf
(qq[\t_LIBGTOP_RECV_ptr += sizeof (glibtop_%s);\n], $feature);
} else {
$recv_buf_code = "\t/* write recv buffer */\n";
$recv_buf_code .= sprintf
(qq[\tmemcpy (_LIBGTOP_RECV_ptr, &%s, sizeof (glibtop_%s));\n],
$feature, $feature);
$recv_buf_code .= sprintf
(qq[\t_LIBGTOP_RECV_ptr += sizeof (glibtop_%s);\n], $feature);
}
$recv_buf_code .= "\n";
$recv_buf_code .= "\t*recv_buf_ptr = _LIBGTOP_RECV_buf;\n";
$recv_buf_code .= "\t*recv_size_ptr = _LIBGTOP_RECV_len;\n";
$func_decl_code = sprintf $func_decl_code = sprintf
(qq[static int\n_glibtop_demarshal_%s_i (glibtop *server, glibtop_backend *backend, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, int *retval_ptr)\n], $feature); (qq[static int\n_glibtop_demarshal_%s_i (glibtop *server, glibtop_backend *backend, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, void **recv_buf_ptr, size_t *recv_size_ptr, int *retval_ptr)\n], $feature);
if (!($call_code eq '')) {
$call_code .= "\n";
}
$func_body_code = sprintf $func_body_code = sprintf
(qq[%s%s%s], $size_code, $demarshal_code, $call_code); (qq[%s%s%s%s], $size_code, $demarshal_code, $call_code, $recv_buf_code);
$total_code = sprintf $total_code = sprintf
(qq[%s{\n%s\n%s\n%s\n\treturn 0;\n}\n], (qq[%s{\n%s\n%s\n%s\n\treturn 0;\n}\n],
@@ -252,7 +314,7 @@ sub output {
} }
$func_decl_code = sprintf $func_decl_code = sprintf
(qq[int\nglibtop_demarshal_func_i (glibtop *server, glibtop_backend *backend, unsigned command, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, int *retval_ptr)]); (qq[int\nglibtop_demarshal_func_i (glibtop *server, glibtop_backend *backend, unsigned command, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, void **recv_buf_ptr, size_t *recv_size_ptr, int *retval_ptr)]);
$switch_body_code = ''; $switch_body_code = '';
@@ -260,7 +322,7 @@ for ($nr = 1; $nr <= $feature_count; $nr++) {
$feature = $features{$nr}; $feature = $features{$nr};
$switch_body_code .= sprintf $switch_body_code .= sprintf
(qq[\tcase GLIBTOP_CMND_%s:\n\t\treturn _glibtop_demarshal_%s_i\n\t\t\t(server, backend, send_ptr, send_size,\n\t\t\t data_ptr, data_size, retval_ptr);\n], (qq[\tcase GLIBTOP_CMND_%s:\n\t\treturn _glibtop_demarshal_%s_i\n\t\t\t(server, backend, send_ptr, send_size,\n\t\t\t data_ptr, data_size,\n\t\t\t recv_buf_ptr, recv_size_ptr, retval_ptr);\n],
&toupper ($feature), $feature); &toupper ($feature), $feature);
} }

View File

@@ -25,20 +25,15 @@
#include "server.h" #include "server.h"
#if 0
void void
do_output (int s, glibtop_response *resp, off_t offset, do_output (int s, glibtop_response *resp, const void *recv_ptr,
size_t data_size, const void *data, int retval) const void *data_ptr)
{ {
#ifdef REAL_DEBUG #ifdef REAL_DEBUG
fprintf (stderr, "Really writing %d bytes at offset %lu.\n", fprintf (stderr, "Really writing %d bytes.\n",
sizeof (glibtop_response), offset); sizeof (glibtop_response));
#endif #endif
resp->offset = offset;
resp->data_size = data_size;
if (s == 0) { if (s == 0) {
if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0) if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0)
glibtop_warn_io ("write"); glibtop_warn_io ("write");
@@ -47,31 +42,37 @@ do_output (int s, glibtop_response *resp, off_t offset,
glibtop_warn_io ("send"); glibtop_warn_io ("send");
} }
if (resp->recv_size) {
#ifdef REAL_DEBUG
fprintf (stderr, "Writing %ld bytes of data.\n",
(long) resp->recv_size);
#endif
if (s == 0) { if (s == 0) {
if (write (1, &retval, sizeof (int)) < 0) if (write (1, recv_ptr, resp->recv_size) < 0)
glibtop_warn_io ("write retval"); glibtop_warn_io ("write");
} else { } else {
if (send (s, &retval, sizeof (int), 0) < 0) if (send (s, recv_ptr, resp->recv_size, 0) < 0)
glibtop_warn_io ("send retval"); glibtop_warn_io ("send");
}
} }
if (resp->data_size) { if (resp->data_size) {
#ifdef REAL_DEBUG #ifdef REAL_DEBUG
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size); fprintf (stderr, "Writing %ld bytes of extra data.\n",
(long) resp->data_size);
#endif #endif
if (s == 0) { if (s == 0) {
if (write (1, data, resp->data_size) < 0) if (write (1, data_ptr, resp->data_size) < 0)
glibtop_warn_io ("write"); glibtop_warn_io ("write");
} else { } else {
if (send (s, data, resp->data_size, 0) < 0) if (send (s, data_ptr, resp->data_size, 0) < 0)
glibtop_warn_io ("send"); glibtop_warn_io ("send");
} }
} }
}
#endif }
int int
do_read (int s, void *ptr, size_t total_size) do_read (int s, void *ptr, size_t total_size)

View File

@@ -42,11 +42,14 @@ glibtop_read_i (glibtop *server, glibtop_backend *backend,
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size); fprintf (stderr, "LIBRARY: really reading %d bytes from %d.\n",
size, backend->_priv->input [0]);
#endif #endif
ret = read (backend->_priv->input [0], buf, size); ret = read (backend->_priv->input [0], buf, size);
fprintf (stderr, "LIBRARY: read %d bytes.\n", ret);
if (ret < 0) if (ret < 0)
glibtop_error_io_r (server, _("read %d bytes"), size); glibtop_error_io_r (server, _("read %d bytes"), size);
} }

View File

@@ -108,12 +108,16 @@ void
handle_slave_connection (int input, int output) handle_slave_connection (int input, int output)
{ {
glibtop_command _cmnd, *cmnd = &_cmnd; glibtop_command _cmnd, *cmnd = &_cmnd;
char parameter [BUFSIZ];
size_t send_size = 0;
glibtop_send_version_i (glibtop_global_server, output); // glibtop_send_version_i (glibtop_global_server, output);
while (do_read (input, cmnd, sizeof (glibtop_command))) { while (do_read (input, cmnd, sizeof (glibtop_command))) {
size_t recv_size = 0, send_size = 0;
char parameter [BUFSIZ];
int retval, func_retval;
void *recv_ptr = NULL;
glibtop_response resp;
fprintf (stderr, "Slave %d received command " fprintf (stderr, "Slave %d received command "
"%ld from client.\n", getpid (), (long) cmnd->command); "%ld from client.\n", getpid (), (long) cmnd->command);
@@ -143,8 +147,22 @@ handle_slave_connection (int input, int output)
memcpy (parameter, cmnd->parameter, send_size); memcpy (parameter, cmnd->parameter, send_size);
} }
glibtop_demarshal_func_i (glibtop_global_server, NULL, retval = glibtop_demarshal_func_i (glibtop_global_server, NULL,
cmnd->command, parameter, cmnd->command, parameter,
send_size, NULL, 0, NULL); send_size, NULL, 0,
&recv_ptr, &recv_size,
&func_retval);
fprintf (stderr, "Retval %d / %d - %p - %d\n",
retval, func_retval, recv_ptr, recv_size);
memset (&resp, 0, sizeof (glibtop_response));
resp.retval = retval;
resp.glibtop_errno = func_retval;
resp.recv_size = recv_size;
resp.data_size = 0;
do_output (output, &resp, recv_ptr, NULL);
} }
} }

View File

@@ -55,6 +55,10 @@ BEGIN_LIBGTOP_DECLS
#define SLAGE_DEBUG #define SLAGE_DEBUG
#endif #endif
#ifndef REAL_DEBUG
#define REAL_DEBUG
#endif
/* Some don't have LOG_PERROR */ /* Some don't have LOG_PERROR */
#ifndef LOG_PERROR #ifndef LOG_PERROR
#define LOG_PERROR 0 #define LOG_PERROR 0
@@ -70,6 +74,10 @@ BEGIN_LIBGTOP_DECLS
#define GET_MAX_FDS() 256 #define GET_MAX_FDS() 256
#endif #endif
void
do_output (int s, glibtop_response *resp, const void *recv_ptr,
const void *data_ptr);
int int
do_read (int s, void *ptr, size_t total_size); do_read (int s, void *ptr, size_t total_size);
@@ -77,7 +85,7 @@ void
handle_slave_connection (int input, int output); handle_slave_connection (int input, int output);
int int
glibtop_demarshal_func_i (glibtop *server, glibtop_backend *backend, unsigned command, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, int *retval_ptr); glibtop_demarshal_func_i (glibtop *server, glibtop_backend *backend, unsigned command, const void *send_ptr, size_t send_size, void *data_ptr, size_t data_size, void **recv_buf_ptr, size_t *recv_size_ptr, int *retval_ptr);
void void
glibtop_send_version_i (glibtop *server, int fd); glibtop_send_version_i (glibtop *server, int fd);

View File

@@ -34,7 +34,7 @@ glibtop_send_version_i (glibtop *server, int fd)
sprintf (buffer, LIBGTOP_VERSION_STRING, sprintf (buffer, LIBGTOP_VERSION_STRING,
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION, LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
sizeof (glibtop_command), sizeof (glibtop_command),
0, sizeof (glibtop_response),
sizeof (glibtop_union), sizeof (glibtop_union),
sizeof (glibtop_sysdeps)); sizeof (glibtop_sysdeps));

View File

@@ -31,7 +31,6 @@ print '';
print '#include <glibtop/sysdeps.h>'; print '#include <glibtop/sysdeps.h>';
print '#include <glibtop/union.h>'; print '#include <glibtop/union.h>';
print ''; print '';
print '#include <glibtop/command.h>';
print '#include <glibtop/backend.h>'; print '#include <glibtop/backend.h>';
print ''; print '';
print '#include <glibtop-backend-private.h>'; print '#include <glibtop-backend-private.h>';

View File

@@ -26,7 +26,6 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/open.h> #include <glibtop/open.h>
#include <glibtop/close.h> #include <glibtop/close.h>
#include <glibtop/command.h>
/* Closes server. */ /* Closes server. */

View File

@@ -31,7 +31,6 @@ print '';
print '#include <glibtop/sysdeps.h>'; print '#include <glibtop/sysdeps.h>';
print '#include <glibtop/union.h>'; print '#include <glibtop/union.h>';
print ''; print '';
print '#include <glibtop/command.h>';
print '#include <glibtop/backend.h>'; print '#include <glibtop/backend.h>';
print ''; print '';

View File

@@ -25,9 +25,7 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/open.h> #include <glibtop/open.h>
#include <glibtop/version.h>
#include <glibtop/sysdeps.h> #include <glibtop/sysdeps.h>
#include <glibtop/command.h>
#include <glibtop/xmalloc.h> #include <glibtop/xmalloc.h>
#include <glibtop/gnuserv.h> #include <glibtop/gnuserv.h>