1 #ifndef MSP_NET_RESOLVE_H_
2 #define MSP_NET_RESOLVE_H_
5 #include <msp/core/mutex.h>
6 #include <msp/core/semaphore.h>
7 #include <msp/core/thread.h>
8 #include <msp/io/eventdispatcher.h>
9 #include <msp/io/pipe.h>
10 #include "constants.h"
17 /** Resolves host and service names into a socket address. If host is empty,
18 the loopback address will be used. If host is "*", the wildcard address will
19 be used. If service is empty, a socket address with a null service will be
20 returned. With the IP families, these are not very useful. */
21 SockAddr *resolve(const std::string &, const std::string &, Family = UNSPEC);
23 /** And overload of resolve() that takes host and service as a single string,
24 separated by a colon. If the host part contains colons, such as is the case
25 with a numeric IPv6 address, it must be enclosed in brackets. */
26 SockAddr *resolve(const std::string &, Family = UNSPEC);
30 An asynchronous name resolver. Blocking calls are performed in a thread and
31 completion is notified with one of the two signals.
43 std::runtime_error *error;
47 bool is_complete() const { return addr || error; }
50 class WorkerThread: public Thread
53 std::list<Task> queue;
63 void add_task(const Task &);
64 Task *get_complete_task();
65 void pop_complete_task();
67 IO::Pipe &get_notify_pipe() { return notify_pipe; }
74 sigc::signal<void, unsigned, const SockAddr &> signal_address_resolved;
75 sigc::signal<void, unsigned, const std::exception &> signal_resolve_failed;
78 IO::EventDispatcher *event_disp;
85 /** Sets the event dispatcher to use. With no event dispatcher, tick() must
86 be called regularly to emit the completion signals. */
87 void use_event_dispatcher(IO::EventDispatcher *);
89 /** Resolves host and service names into a socket address. Semantics are
90 the same as the namespace-scope resolve function. */
91 unsigned resolve(const std::string &, const std::string &, Family = UNSPEC);
93 unsigned resolve(const std::string &, Family = UNSPEC);
95 /** Checks for any completed tasks and emits the appropriate singals. */