Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Call to external libyahoo2 freezes my app's GUI, help!

Call to external libyahoo2 freezes my app's GUI, help!
Thread Tools
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status: Offline
Reply With Quote
Oct 28, 2002, 06:58 PM
 
Hi Everyone,

So I finally got off my butt and decided to start *trying* to write some apps in a mix of Cocoa and C. I thought it would be fun to write and app that interfaces with yahoo, using the free libyahoo2 library (http://libyahoo2.sourceforge.net/).

I have successfully gotten my app to bring up a window, take your username/password, log you in, check for new mail, etc etc.

The problem is, that one of the things that the program does is send a command to yahoo letting it know it's ready to read data (yahoo_read_ready() function from the library).

I call this function, and the GUI from my program locks up, ie spinning rainbow wheel, while it waits for data.

I've isolated the call from the library where it "hangs" to the following:

len = read(fd, buf, sizeof(buf));

Where it reads from "fd" into "buf".

Okay, maybe that's really not enough to go on, but does anyone have any clue?

If I have my program send just one "yahoo_read_ready()" request, the GUI returns to responsiveness after this request is completed, but to continuously interact with yahoo it needs to call this function again and again.

Thanks for any suggestions,
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Oct 28, 2002, 10:21 PM
 
first of all, any network code should be executed in a seperate thread. (See NSThread in Apple's documentation). "read" is a a "blocking" function call -- by calling this in a seperate thread, you'll skip the whole spinning cursor thing while it waits for data.


When are you calling yahoo_read_ready()?
     
msykes  (op)
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status: Offline
Reply With Quote
Oct 28, 2002, 10:21 PM
 
Never mind, I fixed my own problem. Taking a cue from Proteus' implementation of imservices, I used an NSTimer to make the call, and that seems to let it run properly in the background.
     
msykes  (op)
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status: Offline
Reply With Quote
Oct 29, 2002, 05:28 PM
 
Originally posted by 00101001:
first of all, any network code should be executed in a seperate thread. (See NSThread in Apple's documentation). "read" is a a "blocking" function call -- by calling this in a seperate thread, you'll skip the whole spinning cursor thing while it waits for data.


When are you calling yahoo_read_ready()?
Strange... we must have at exactly the same time, I didn't see this when I posted my "followup".

In retrospect, I don't think the timer had anything to do with it, rather I figured out (ie borrowed a line of code) from one of the samples that checks to see if there is anything to read, and if not doesn't call the read function.

As far as separate threads... that sounds like the way to go, in my complete naivety (sp?) I guess I just hoped this was the kind of thing that might happen automatically.

http://homepage.mac.com/msykes/ if anyone wants to take a peek at the initial final product.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:16 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2