Cocoa newb - Bus Error from TCP Server
-
Hello from a newb Cocoa developer and a newb to ObjC (but not programming). I've been trying to implement a SOAP server using the CocoaSOAP sample code on the Apple Developer site. Everything works fine except when sending 400/Bad Request messages. When this happens I receive a bus error on the server but my data gets passed to the client properly. Has anyone else seen this before?
Here's a snip of code (All variables are defined earlier in the code):
NSString *xml = [NSString stringWithFormat:@"<?xml version=\"1.0\"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=\"\"> <SOAP-ENV:Body> ...Stuff here... </SOAP-ENV:Body>
</SOAP-ENV:Envelope>"];
error = nil;
doc = [[[NSXMLDocument alloc] initWithXMLString:xml
options:NSXMLNodeOptionsNone error:&error] autorelease];
data = [doc XMLData];
CFHTTPMessageRef response =
CFHTTPMessageCreateResponse(kCFAllocatorDefault, 400, NULL,
kCFHTTPVersion1_1); // Bad Request
CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-Length",
(CFStringRef)[NSString stringWithFormat:@"%d", [data length]]);
CFHTTPMessageSetBody(response, (CFDataRef)data);
[mess setResponse:response];
CFRelease(response);
printf("** Sent 400:Bad Request Message **\n");
return;
The server prints out my "** Sent 400:Bad Request" message and then gives
the bus error on the return.
Has anyone else seen this or does anyone have any suggestions where to
look? I've checked everything on the client, and it looks fine. It appears
I'm creating the HTTP response correctly... I can provide more code if
necessary.
Thanks for the help and consideration.
________________________________________________________________________
Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit <A href="http://www.juno.com/value">http://www.juno.com/value to sign up today! -
On 10-Jun-06, at 12:53 PM, Christopher Bland wrote:> The server prints out my "** Sent 400:Bad Request" message and then
> gives the bus error on the return.
1) Can't you run the server under the debugger and thus figure out
the exact location of the line causing the bus error?
2) If the bus error is happening upon the return from that function,
it would seem that the problem is with the function that it returns
to (i.e. the caller). Is your function really a void function (not
supposed to return anything?)
3) Maybe something in this Apple doc about debugging will help:
http://developer.apple.com/technotes/tn2004/tn2124.html
--
Cameron Hayne
<hayne...> -
Cameron,
Thanks for the advice. I got too caught up in trying to step through the code to not only find the problem but learn ObjC that I hadn't thought of the debugger, duh...
Anyway, I found what is causing the error, thanks again.
________________________________________________________________________
Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today! -
Am 10.06.2006 um 15:30 schrieb Christopher Bland:> Thanks for the advice. I got too caught up in trying to step
> through the code to not only find the problem but learn ObjC that I
> hadn't thought of the debugger, duh...
>
> Anyway, I found what is causing the error, thanks again.
Don't keep us hanging! Tell us what the problem was for you.
Otherwise, someone with the same (or a very similar problem) arrives
at your message via Google only to find no solution in the archives! :-)
Cheers,
-- M. Uli Kusterer
http://www.zathras.de -
Well...I thought I had solved it. Running it through the debugger kept telling me:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xbf806ffc
0xffff0b36 in ___memcpy () at /System/Library/Frameworks/System.framework/PrivateHeaders/i386/cpu_capabilities.h:186
186 /System/Library/Frameworks/System.framework/PrivateHeaders/i386/cpu_capabilities.h: No such file or directory.
in /System/Library/Frameworks/System.framework/PrivateHeaders/i386/cpu_capabilities.h
I'm using an Intel based iMac and OS X 10.4.6 and Xcode 2.3.
I thought all I had to do was make some soft-links and I'd be done, but that wasn't the case. I'm still trying to figure out what the heck is going on. Instead I think it is a problem with the NSInputStream read function returning -1. I'm trying to figure out why it is returning -1 (and what a -1 return value means).
I'm using the CocoaSOAP example from the Apple Developer website (which I changed a bit, simply copying and pasting code to get a response for a particular request). My client machine is a Windows box running my custom C app using libcurl to do the POST and get the response from the server.
I've traced the processing to the following:
HTTP request comes in fine
I pull the body and determine what is being POST'ed
I create and send back a 400/Bad Request with a message in the body
enter processIncomingBytes - then return (** See Note below)
enter stream - then return;
enter stream - call processOutgoingBytes
return from processOutgoingBytes, return from stream
enter stream - call processOutgoingBytes
return from processOutgoingBytes, return from stream
enter stream - call processOutgoingBytes
**** ERROR HAPPENS SOMEWHERE IN processOutgoingBytes ****
During the stream call before calling processIncomingBytes it makes a call to NSInputStream read and it returns -1. The doc'n doesn't indicate what a negative return value is.
I've grown quite frustrated over this because other things work fine like using the SOAP Mac client bundled with the example and I can even request pages through the GET method. For some reason doing an HTTP post with libcurl is killing the app.
If I did not explain something good enough please let me know and I'll do my best to elaborate. At this point everything is mushing together and I've tried my best to describe everything completely.
If there are any other suggestions I'm open to just about anything. In the mean time I'm going to check out my client app.
Chris
________________________________________________________________________
Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today! -
Ok, I found my problem...and of course it was with my client code on my Windows box. I should have realized that when the web browsers and my Mac client piece worked fine. I added the following call to my C code after the curl_easy_perform:
curl_easy_getinfo (curl, CURLINFO_HTTP_CODE, &retcode);
And now everything works just fine. Hopefully someone else won't have the same troubles.
Chris
________________________________________________________________________
Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today!


