[
https://issues.apache.org/jira/browse/THRIFT-582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13137700#comment-13137700
]
Christian Zimnick commented on THRIFT-582:
------------------------------------------
I tested c_glib client with a csharp server just for fun.
c_glib client calling a function on csharp-server and returns a big string.
On any time i get a segfault or block by reading the returning string from
server.
{code}
/*
* calling example from my test client...
* segfault by reading the returning string from server
*/
gchar *_return = NULL; /* found: allocation of string length in
lib/c_glib/src/thrift_binary_protocol.c:757 ??allocate some space by myself??
*/
testServer_if_run_test_function(service, &_return, argument, &err);
printf("after send |%s|\n", _return);
{code}
c_glib client runs on Ubuntu Server 11.04.
csharp server runs on Windows 7 64 Bit. (.NET)
I fixed this with some code changes in lib/c_glib/src/transport/thrift_socket.c
and lib/src/transport/thrift_buffered_transport.c. I hope its correct.
{code}
Index: lib/c_glib/src/transport/thrift_socket.c
===================================================================
--- lib/c_glib/src/transport/thrift_socket.c (revision 1190015)
+++ lib/c_glib/src/transport/thrift_socket.c (working copy)
@@ -127,7 +127,7 @@
while (got < len)
{
- ret = recv (socket->sd, buf, len, 0);
+ ret = recv (socket->sd, buf+got, len-got, 0);
if (ret < 0)
{
g_set_error (error, THRIFT_TRANSPORT_ERROR,
Index: lib/c_glib/src/transport/thrift_buffered_transport.c
===================================================================
--- lib/c_glib/src/transport/thrift_buffered_transport.c (revision 1190015)
+++ lib/c_glib/src/transport/thrift_buffered_transport.c (working copy)
@@ -71,7 +71,7 @@
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
guint32 want = len;
guint32 got = 0;
- guchar tmpdata[t->r_buf_size];
+ guchar tmpdata[len];
guint32 have = t->r_buf->len;
// we shouldn't hit this unless the buffer doesn't have enough to read
@@ -97,14 +97,14 @@
// copy the data starting from where we left off
memcpy (buf + have, tmpdata, got);
- return got + have;
+ return got + have;
} else {
got += THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
tmpdata,
- t->r_buf_size,
+ want,
error);
t->r_buf = g_byte_array_append (t->r_buf, tmpdata, got);
-
+
// hand over what we have up to what the caller wants
guint32 give = want < t->r_buf->len ? want : t->r_buf->len;
{code}
After this changes framed-transport and buffered-transport on binary-protocol
worked fine.
> C implementation of Thrift
> --------------------------
>
> Key: THRIFT-582
> URL: https://issues.apache.org/jira/browse/THRIFT-582
> Project: Thrift
> Issue Type: New Feature
> Components: C glib - Compiler, C glib - Library
> Reporter: David Reiss
> Assignee: Anatol Pomozov
> Priority: Minor
> Fix For: 0.6
>
> Attachments: c_glib_bindings.patch, t_c_generator.cc,
> thrift_582_c_glib_bindings.patch, thrift_582_c_glib_bindings_20100927.patch,
> thrift_582_c_glib_bindings_20101012.patch,
> thrift_582_c_glib_bindings_20101026.patch
>
>
> Create a usable implementation of Thrift that uses only C at runtime, no C++.
> The code is at
> http://svn.apache.org/repos/asf/incubator/thrift/branches/c-bindings/.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira