Hi,
I have some problems getting my c_glib client to work and I'm hoping
someone here can help.
I have attached both my client and my interface file. I'm using the master
branch of thrift, but I got the same error when I tried the 0.9.0 version
also.
So, the problem I'm having is that I get a segmentation fault when I try to
send my thrift struct to the server.
>From GDB:
user_storage_client_send_store (iface=0x6102c0, user=0x7fffffffe020,
error=0x7fffffffe060) at user_storage.c:119
119 xfer += ret;
(gdb) n
120 if ((ret = thrift_struct_write (THRIFT_STRUCT (user), protocol,
error)) < 0)
(gdb) s
thrift_struct_get_type () at src/thrift/c_glib/thrift_struct.c:23
23 G_DEFINE_ABSTRACT_TYPE(ThriftStruct, thrift_struct, G_TYPE_OBJECT)
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7992dec in g_type_check_instance_cast ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
And the stack trace:
#0 0x00007f72baae0dec in g_type_check_instance_cast () from
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#1 0x0000000000402709 in user_storage_client_send_store (iface=0x14702c0,
user=0x7fff23617580, error=0x7fff236175c0)
at user_storage.c:120
#2 0x0000000000402cb4 in user_storage_client_store (iface=0x14702c0,
user=0x7fff23617580, error=0x7fff236175c0)
at user_storage.c:259
#3 0x0000000000401b7d in main (argc=1, argv=0x7fff236176e8) at client.c:52
Should the variable be initialized in some way before I can use it? Or am I
doing something else wrong?
Thanks in advance.
Niclas Lockner
#include <stdio.h>
#include "thrift/c_glib/protocol/thrift_protocol.h"
#include "thrift/c_glib/protocol/thrift_binary_protocol.h"
#include "thrift/c_glib/transport/thrift_buffered_transport.h"
#include "thrift/c_glib/transport/thrift_transport.h"
#include "thrift/c_glib/transport/thrift_socket.h"
#include "test_types.h"
#include "user_storage.h"
int main(int argc, char** argv) {
ThriftSocket *tsocket;
ThriftTransport *transport;
ThriftProtocol *protocol;
UserStorageClient *client;
UserStorageIf *service;
GError *err = NULL;
UserProfile user;
g_type_init();
tsocket = THRIFT_SOCKET( g_object_new (THRIFT_TYPE_SOCKET,
"hostname", "localhost",
"port", 9090, 0) );
transport = THRIFT_TRANSPORT( g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
"transport", tsocket, 0) );
protocol = THRIFT_PROTOCOL ( g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
"transport", transport, 0) );
client = USER_STORAGE_CLIENT( g_object_new(TYPE_USER_STORAGE_CLIENT,
"input_protocol", protocol, /* ??? */
"output_protocol", protocol,
0) );
service = USER_STORAGE_IF(client);
if (
!thrift_transport_open(transport, 0) ||
!thrift_transport_is_open(transport)
) {
printf("Could not connect to server\n");
return 1;
}
user.uid = 0;
user.name = g_strdup_printf("name");
user.blurb = g_strdup_printf("blurb");
user.__isset_uid = TRUE;
user.__isset_name = TRUE;
user.__isset_blurb = TRUE;
if (!user_storage_client_store(service, &user, &err)) {
printf("Could not exec store: %s\n", err->message);
return 1;
}
g_free(user.name);
g_free(user.blurb);
thrift_transport_close(transport, 0);
g_object_unref (client);
g_object_unref (protocol);
g_object_unref (transport);
g_object_unref (tsocket);
return 0;
}