-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/10/2010 11:18 AM, Weibin Yao wrote:
> I find the oauthexample.c is a block IO example, is there a no-block
> IO example?

Short answer: No, but there is libcurl example code for this.

Basically libOAuth only handles the OAuth part (parameter encoding,
signing), however it [optionally] includes a few convenient wrappers
around libcurl.

The HTTP/curl integration in libOAuth is very simple, it also does not
do any error handing and is basically just curl-example code.

It's very easy to to use [lib]curl directly.


One option for non-blocking requests with libOAuth is to simply start a
thread for the HTTP request. 'oauth_post_data_with_callback()' also
allows to update a progress-bar as the request is executed...

C++ code using pthreads would look like this:

- --8<-------------------
extern "C" {
#include <oauth.h>
#include <pthread.h>
}

void *http_get_thread (void *arg) {
  MyClass *m = static_cast<MyClass *>(arg);

  /* optional - if you'd like to be able to abort
     the request with pthread_cancel() */
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

  char *res = oauth_http_get2(m->signed_req_url, NULL, NULL);

  /* optional : don't allow to abort once the request
     is finished and we're processing the returned data */
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);

  m->http_download_done(res);

  pthread_exit(0);
  return 0;
}

void
MyClass::http_download_done (char *data){
  if (!data) { /* HTTP status != 200 */ return; }
  /* do something - still in background thread context. */
  free(data);
}

void
MyClass::launch_http_request() {
  pthread_create(&thread_id_tt, NULL, http_get_thread, this);
}
- --8<-------------------

HTH,
robin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkyLvwoACgkQeVUk8U+VK0LlaACgsiazvCjX4C5JqXYDues3Kr7/
QckAoKgPv5VgoruOyxfC6U43fc/B+NZu
=w9rb
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/oauth?hl=en.

Reply via email to