~ubuntu-branches/ubuntu/natty/evolution-data-server/natty

« back to all changes in this revision

Viewing changes to camel/camel-net-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-03-01 22:47:15 UTC
  • mfrom: (1.1.77 upstream)
  • Revision ID: james.westby@ubuntu.com-20100301224715-drsxc2y3t8anz3c0
Tags: 2.28.3-0ubuntu1
* New upstream version:
  Bug Fixes:
  - #602723 - Contact list name doesn't get displayed in 'To' dialog 
  - #600322 - assertion failed: (reply == msg) in cs_waitinfo()
              (lp: #455020, #475147)
  - #564727 - Few memory leaks (lp: #305428)
  - #574940 - Always ref returned info from message_info_from_uid 
              (lp: #341909)
  - #429317 - Use the relative URI returned if the server 
              re-directs a request
  - #602820 - Test validity of a book_view before using it in LDAP 
  - #590762 - Recurring google calendar items are not changeable
  - #604236 - Slow GPG processing 
  - #597816 - Do not crash on incorrect parameters used in sexp to SQL 
              (lp: #444177)
  - #604544 - Try Exchange fallback authentication only once 
  - #600778 - Fix --enable-e2k-debug configure option resolution 
  - #260407 - 'endswith' address book search doesn't work 
  - #549221 - (bnc) delete, sync flags immediately
* debian/patches/99_reconfigure.patch:
  - new version update

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#endif
27
27
 
28
28
#include <errno.h>
29
 
#include <pthread.h>
30
29
#include <stdio.h>
31
30
 
32
31
#include <glib.h>
447
446
cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar *error, CamelException *ex)
448
447
{
449
448
        CamelMsgPort *reply_port;
450
 
        pthread_t id;
451
 
        gint err, cancel_fd, cancel = 0, fd;
 
449
        GThread *thread;
 
450
        GError *err = NULL;
 
451
        gint cancel_fd, cancel = 0, fd;
452
452
 
453
453
        cancel_fd = camel_operation_cancel_fd(NULL);
454
454
        if (cancel_fd == -1) {
458
458
 
459
459
        reply_port = msg->msg.reply_port = camel_msgport_new();
460
460
        fd = camel_msgport_fd(msg->msg.reply_port);
461
 
        if ((err = pthread_create(&id, NULL, worker, msg)) == 0) {
 
461
        if ((thread = g_thread_create (worker, msg, TRUE, &err)) != NULL) {
462
462
                gint status;
463
463
#ifndef G_OS_WIN32
464
464
                GPollFD polls[2];
506
506
                           We check the reply port incase we had a reply in the mean time, which we free later */
507
507
                        d(printf("Canceling lookup thread and leaving it\n"));
508
508
                        msg->cancelled = 1;
509
 
                        pthread_cancel(id);
510
 
                        pthread_join (id, NULL);
 
509
                        g_thread_join (thread);
511
510
                        cancel = 1;
512
511
                } else {
513
 
                        struct _addrinfo_msg *reply = (struct _addrinfo_msg *)camel_msgport_try_pop(reply_port);
 
512
                        struct _addrinfo_msg *reply;
514
513
 
515
 
                        g_assert(reply == msg);
516
514
                        d(printf("waiting for child to exit\n"));
517
 
                        pthread_join(id, NULL);
 
515
                        g_thread_join (thread);
518
516
                        d(printf("child done\n"));
 
517
 
 
518
                        reply = (struct _addrinfo_msg *)camel_msgport_try_pop(reply_port);
 
519
                        if (reply != msg)
 
520
                                g_warning ("%s: Received msg reply %p doesn't match msg %p", G_STRFUNC, reply, msg);
519
521
                }
520
522
        } else {
521
 
                camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), g_strerror(err));
 
523
                camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), err ? err->message : _("Unknown error"));
 
524
                if (err)
 
525
                        g_error_free (err);
522
526
        }
523
527
        camel_msgport_destroy(reply_port);
524
528
 
540
544
        /* This is a pretty simplistic emulation of getaddrinfo */
541
545
 
542
546
        while ((msg->result = camel_gethostbyname_r(msg->name, &h, msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
543
 
                pthread_testcancel();
 
547
                if (msg->cancelled)
 
548
                        break;
544
549
                msg->hostbuflen *= 2;
545
550
                msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
546
551
        }
547
552
 
548
 
        pthread_testcancel ();
549
 
 
550
553
        /* If we got cancelled, dont reply, just free it */
551
554
        if (msg->cancelled)
552
555
                goto cancel;
599
602
                }
600
603
        }
601
604
 
602
 
        pthread_testcancel ();
603
 
 
604
 
        for (i=0;h.h_addr_list[i];i++) {
 
605
        for (i = 0; h.h_addr_list[i] && !msg->cancelled; i++) {
605
606
                res = g_malloc0(sizeof(*res));
606
607
                if (msg->hints) {
607
608
                        res->ai_flags = msg->hints->ai_flags;
651
652
                        info->result = getaddrinfo(info->name, "443", info->hints, info->res);
652
653
        }
653
654
 
654
 
        pthread_testcancel ();
655
 
 
656
655
        if (!info->cancelled)
657
656
                camel_msgport_reply((CamelMsg *)info);
658
657
 
747
746
 
748
747
        while ((msg->result = camel_gethostbyaddr_r((const gchar *)&sin->sin_addr, sizeof(sin->sin_addr), AF_INET, &h,
749
748
                                                    msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
750
 
                pthread_testcancel ();
 
749
                if (msg->cancelled)
 
750
                        break;
751
751
                msg->hostbuflen *= 2;
752
752
                msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
753
753
        }
755
755
        if (msg->cancelled)
756
756
                goto cancel;
757
757
 
758
 
        pthread_testcancel ();
759
 
 
760
758
        if (msg->host) {
761
759
                g_free(msg->host);
762
760
                if (msg->result == 0 && h.h_name && h.h_name[0]) {
773
771
        if (msg->serv)
774
772
                sprintf(msg->serv, "%d", sin->sin_port);
775
773
 
776
 
        camel_msgport_reply((CamelMsg *)msg);
 
774
        if (!msg->cancelled)
 
775
                camel_msgport_reply ((CamelMsg *)msg);
777
776
cancel:
778
777
        return NULL;
779
778
}
786
785
        /* there doens't appear to be a return code which says host or serv buffers are too short, lengthen them */
787
786
        msg->result = getnameinfo(msg->addr, msg->addrlen, msg->host, msg->hostlen, msg->serv, msg->servlen, msg->flags);
788
787
 
789
 
        pthread_testcancel ();
790
 
 
791
788
        if (!msg->cancelled)
792
789
                camel_msgport_reply((CamelMsg *)msg);
793
790