 |
 |
Call to external libyahoo2 freezes my app's GUI, help!
|
 |
|
 |
|
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status:
Offline
|
|
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
|
|
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()?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|