media/mtransport/nriceresolver.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7
michael@0 8 // Original authors: jib@mozilla.com, ekr@rtfm.com
michael@0 9
michael@0 10 // Some of this code is cut-and-pasted from nICEr. Copyright is:
michael@0 11
michael@0 12 /*
michael@0 13 Copyright (c) 2007, Adobe Systems, Incorporated
michael@0 14 All rights reserved.
michael@0 15
michael@0 16 Redistribution and use in source and binary forms, with or without
michael@0 17 modification, are permitted provided that the following conditions are
michael@0 18 met:
michael@0 19
michael@0 20 * Redistributions of source code must retain the above copyright
michael@0 21 notice, this list of conditions and the following disclaimer.
michael@0 22
michael@0 23 * Redistributions in binary form must reproduce the above copyright
michael@0 24 notice, this list of conditions and the following disclaimer in the
michael@0 25 documentation and/or other materials provided with the distribution.
michael@0 26
michael@0 27 * Neither the name of Adobe Systems, Network Resonance nor the names of its
michael@0 28 contributors may be used to endorse or promote products derived from
michael@0 29 this software without specific prior written permission.
michael@0 30
michael@0 31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 32 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 33 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 34 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 35 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 36 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 37 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 38 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 39 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 40 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 41 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 42 */
michael@0 43
michael@0 44 #ifndef nriceresolver_h__
michael@0 45 #define nriceresolver_h__
michael@0 46
michael@0 47 #include <map>
michael@0 48 #include <string>
michael@0 49 #include "nspr.h"
michael@0 50 #include "prnetdb.h"
michael@0 51 #include "nsIDNSService.h"
michael@0 52 #include "nsIDNSListener.h"
michael@0 53 #include "nsICancelable.h"
michael@0 54
michael@0 55 typedef struct nr_resolver_ nr_resolver;
michael@0 56 typedef struct nr_resolver_vtbl_ nr_resolver_vtbl;
michael@0 57 typedef struct nr_transport_addr_ nr_transport_addr;
michael@0 58 typedef struct nr_resolver_resource_ nr_resolver_resource;
michael@0 59
michael@0 60 namespace mozilla {
michael@0 61
michael@0 62 class NrIceResolver
michael@0 63 {
michael@0 64 public:
michael@0 65 NrIceResolver();
michael@0 66 ~NrIceResolver();
michael@0 67
michael@0 68 nsresult Init();
michael@0 69 nr_resolver *AllocateResolver();
michael@0 70 void DestroyResolver();
michael@0 71 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceResolver)
michael@0 72
michael@0 73 private:
michael@0 74 // Implementations of vtbl functions
michael@0 75 static int destroy(void **objp);
michael@0 76 static int resolve(void *obj, nr_resolver_resource *resource,
michael@0 77 int (*cb)(void *cb_arg, nr_transport_addr *addr),
michael@0 78 void *cb_arg, void **handle);
michael@0 79 static void resolve_cb(NR_SOCKET s, int how, void *cb_arg);
michael@0 80 static int cancel(void *obj, void *handle);
michael@0 81
michael@0 82 int resolve(nr_resolver_resource *resource,
michael@0 83 int (*cb)(void *cb_arg, nr_transport_addr *addr),
michael@0 84 void *cb_arg, void **handle);
michael@0 85
michael@0 86 class PendingResolution : public nsIDNSListener
michael@0 87 {
michael@0 88 public:
michael@0 89 PendingResolution(nsIEventTarget *thread,
michael@0 90 uint16_t port,
michael@0 91 int transport,
michael@0 92 int (*cb)(void *cb_arg, nr_transport_addr *addr),
michael@0 93 void *cb_arg) :
michael@0 94 thread_(thread),
michael@0 95 port_(port),
michael@0 96 transport_(transport),
michael@0 97 cb_(cb), cb_arg_(cb_arg),
michael@0 98 canceled_ (false) {}
michael@0 99 virtual ~PendingResolution(){};
michael@0 100 NS_IMETHOD OnLookupComplete(nsICancelable *request, nsIDNSRecord *record,
michael@0 101 nsresult status);
michael@0 102 int cancel();
michael@0 103 nsCOMPtr<nsICancelable> request_;
michael@0 104 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 105
michael@0 106 private:
michael@0 107 nsCOMPtr<nsIEventTarget> thread_;
michael@0 108 uint16_t port_;
michael@0 109 int transport_;
michael@0 110 int (*cb_)(void *cb_arg, nr_transport_addr *addr);
michael@0 111 void *cb_arg_;
michael@0 112 bool canceled_;
michael@0 113 };
michael@0 114
michael@0 115 nr_resolver_vtbl* vtbl_;
michael@0 116 nsCOMPtr<nsIEventTarget> sts_thread_;
michael@0 117 nsCOMPtr<nsIDNSService> dns_;
michael@0 118 #ifdef DEBUG
michael@0 119 int allocated_resolvers_;
michael@0 120 #endif
michael@0 121 };
michael@0 122
michael@0 123 } // End of namespace mozilla
michael@0 124 #endif

mercurial