Maximum message size allowed in dbus

Sumit Kumar Jain sumitskj_20 at yahoo.com
Mon Jan 21 01:13:44 PST 2008


Hi All,
I am using dbus glib binding. I have a code where i am trying to transfer a 5 MB file over dbus. I am getting an error which is 

"Failed to write file 'copy-client.JK5K5T': fwrite() failed: Bad address"

However for small file ( about 10-20 k), I am not getting the same problem. I looked up the dbus specs and that says that the max message size is 2 pow 27. I am not able to understand the reason of failure. I am attaching my code for your reference.

--------------- server-code------------
/* some-object.h */
#ifndef __SOME_OBJECT_H__
#define __SOME_OBJECT_H__

#include <glib-object.h>

typedef struct _SomeObject SomeObject;
struct _SomeObject
{
    GObject        parent_obj;
    gint         m_a;
    gchar*        m_b;
    gfloat        m_c;
};

typedef struct _SomeObjectClass SomeObjectClass;
struct _SomeObjectClass
{
    GObjectClass    parent_class;

    /* Some useful methods may follow. */
    gboolean    (*method1)    (SomeObject *self, gint x,gchar **y,gint *z,GError **error);
    void        (*method2)    (SomeObject *self, gchar*);
};

GType    some_object_get_type ();

gboolean some_object_method1 (SomeObject *self, gint x,gchar**y,gint *z,GError **);    /* virtual */
void    some_object_method2 (SomeObject *self, gchar*);    /* virtual */
void    some_object_method3 (SomeObject *self, gfloat);    /* non-virtual */


/* Handy macros */
#define SOME_OBJECT_TYPE        (some_object_get_type ())
#define SOME_OBJECT(obj)        (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOME_OBJECT_TYPE, SomeObject))
#define SOME_OBJECT_CLASS(c)        (G_TYPE_CHECK_CLASS_CAST ((c), SOME_OBJECT_TYPE, SomeObjectClass))
#define SOME_IS_OBJECT(obj)        (G_TYPE_CHECK_TYPE ((obj), SOME_OBJECT_TYPE))
#define SOME_IS_OBJECT_CLASS(c)        (G_TYPE_CHECK_CLASS_TYPE ((c), SOME_OBJECT_TYPE))
#define SOME_OBJECT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), SOME_OBJECT_TYPE, SomeObjectClass))

#endif



/* some-object.c */

#include "some-object.h"
#include "some-object-glue.h"
#include <dbus/dbus-glib-bindings.h>
#include <string.h>
#include <sys/stat.h>

static GObjectClass *parent_class = ((void *)0);
static void some_object_init (SomeObject *self);

char *FILENAME = NULL;

gboolean some_object_method1_impl (SomeObject *self, gint a, gchar **y,gint *z,GError **error)
{
    struct stat stat_buf;
    self->m_a = a;
    g_print ("Method1: %i\n", self->m_a);
/*    
    *y = (char *)g_malloc0(6);
    strcpy(*y,"sumit");
*/        
    stat(FILENAME,&stat_buf);
    *y = g_malloc(stat_buf.st_size + 100);
    if(g_file_get_contents(FILENAME,y,z,error))
    {
        g_print("Contents read\n");
        if(g_file_set_contents("copy-server",*y,*z,NULL))
            g_print("Contents written\n");
    }
    else
        g_print("Contents reading failed... %s \n",(*error)->message);

    return TRUE;
}

void some_object_method2_impl (SomeObject *self, gchar* b)
{
    self->m_b = b;
    g_print ("Method2: %s\n", self->m_b);
}


/* Public methods. */
gboolean some_object_method1 (SomeObject *self, gint a,gchar **y,gint *z,GError **error)
{
    return SOME_OBJECT_GET_CLASS (self)->method1 (self, a,y,z,error);
}

void    some_object_method2 (SomeObject *self, gchar* b)
{
    SOME_OBJECT_GET_CLASS (self)->method2 (self, b);
}

void    some_object_method3 (SomeObject *self, gfloat c)
{
    self->m_c = c;
    g_print ("Method3: %f\n", self->m_c);
}


void    some_object_dispose (GObject *self)
{
    static gboolean first_run = TRUE;

    if (first_run)
    {
        first_run = FALSE;
        
        /* Call g_object_unref on any GObjects that we hold, but don't break the object */

        parent_class-> dispose (self);
    }
}

void    some_object_finalize (GObject *self)
{
    parent_class-> finalize (self);
}

/* Here is where we override any functions. Since we have no properties or even fields, none of the below are needed. */
void    some_object_class_init        (gpointer g_class, gpointer class_data)
{
    GObjectClass    *object_class    = G_OBJECT_CLASS (g_class);
    SomeObjectClass    *this_class    = SOME_OBJECT_CLASS (g_class);
    
    //assign value to parent class
    parent_class = g_type_class_peek_parent (g_class);
    
    //assing pointer values to the base class members
    object_class-> dispose = &some_object_dispose;
    object_class-> finalize = &some_object_finalize;
    
    //assign value to derived class members
    this_class->method1 = &some_object_method1_impl;
    this_class->method2 = &some_object_method2_impl;

    dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(this_class),&dbus_glib__object_info);
}

void some_object_init (SomeObject *self)
{
    self->m_a = 1;
    self->m_c = 1.03f;
    self->m_b = "sumit";
}

GType some_object_get_type () 
{
    static GType g_define_type_id = 0; 
    if ((g_define_type_id == 0)) 
    { 
        static const GTypeInfo g_define_type_info = 
        { 
            sizeof (SomeObjectClass), 
            (GBaseInitFunc) ((void *)0), 
            (GBaseFinalizeFunc) ((void *)0), 
            (GClassInitFunc) some_object_class_init, 
            (GClassFinalizeFunc) ((void *)0), 
            ((void *)0), 
            sizeof (SomeObject), 
            0, 
            (GInstanceInitFunc) some_object_init, 
        }; 

        g_define_type_id = g_type_register_static 
        (
            G_TYPE_OBJECT, 
            "SomeObject", 
            &g_define_type_info, 
            (GTypeFlags) 0
        );
        
    } 

    return g_define_type_id; 
}

int main(int argc,char *argv[])
{
    SomeObject *so = NULL;
    DBusGConnection *bus;
    g_type_init();
    GMainLoop *mainLoop = NULL;
    int request_ret;
    GError *error = NULL;

    DBusGProxy *proxy = NULL;
    char *x;

    FILENAME = argv[1];

    so = g_object_new(SOME_OBJECT_TYPE,NULL);

    bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);

    proxy = dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);

    dbus_g_connection_register_g_object(bus,"/com/example/SomeObject",G_OBJECT(so));

    if(!org_freedesktop_DBus_request_name(proxy,"com.example.SomeObject",0,&request_ret,&error))
    {
        g_print("Unable to register service\n");
        return 1;
    }

    mainLoop = g_main_loop_new(NULL,FALSE);
    g_main_loop_run(mainLoop);
    
    return 0;
}
------------------- End server code --------------

---------- Client code -------------------
#define DBUS_API_SUBJECT_TO_CHANGE

#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h>
#include <stdio.h>
#include "some-object-bindings.h"

int main (int argc, char **argv)
{
  DBusGConnection *connection;
  GError *error;
  DBusGProxy *proxy;
  gchar *x;
  gint length;
  
  g_type_init ();

  error = NULL;
  connection = dbus_g_bus_get (DBUS_BUS_SESSION,
                               &error);
  if (connection == NULL)
    {
      g_printerr ("Failed to open connection to bus: %s\n",
                  error->message);
      g_error_free (error);
      exit (1);
    }

  proxy = dbus_g_proxy_new_for_name (connection,
                                     "com.example.SomeObject",
                                     "/com/example/SomeObject",
                                     "com.example.SomeObject");

  error = NULL;

  if(!com_example_SomeObject_method1(proxy,10,&x,&length,&error))
  {
    printf("Error --- %s\n",error->message);
    return 1;
  }

  printf("File details... length = %d\n",length);
  error = NULL;
  if(!g_file_set_contents("copy-client",x,length,&error))
      printf("Error message = %s\n",error->message);
  
  return 0;
}
------------ End Client  code -------------

--------- Introspection XML ------------
<?xml version="1.0" encoding="UTF-8" ?>

<node name="/com/example/SomeObject">

  <interface name="com.example.SomeObject">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="some_object"/>
    <method name="Method1">
      <!-- This is optional, and in this case is redunundant -->
      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="some_object_method1"/>
      <arg type="u" name="x" direction="in" />
      <arg type="s" name="y" direction="out" />
      <arg type="u" name="z" direction="out" />
    </method>
  </interface>
</node>
--------- End Introspection XML ------------


Please help.

Regads,
Sumit

       
---------------------------------
 Now you can chat without downloading messenger. Click here to know how.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080121/4d1cd98d/attachment.htm 


More information about the dbus mailing list