]> git.tdb.fi Git - libs/net.git/blob - source/http/client.h
Remove unnecessary destructors from exception classes
[libs/net.git] / source / http / client.h
1 #ifndef MSP_HTTP_CLIENT_H_
2 #define MSP_HTTP_CLIENT_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <msp/io/eventdispatcher.h>
7 #include <msp/net/resolve.h>
8 #include <msp/net/streamsocket.h>
9
10 namespace Msp {
11 namespace Http {
12
13 class client_busy: public std::logic_error
14 {
15 public:
16         client_busy(): std::logic_error(std::string()) { }
17 };
18
19 class Request;
20 class Response;
21
22 class Client
23 {
24 public:
25         sigc::signal<void, const Response &> signal_response_complete;
26         sigc::signal<void, const std::exception &> signal_socket_error;
27
28 private:
29         struct ResolveListener: public sigc::trackable
30         {
31                 Client &client;
32
33                 ResolveListener(Client &);
34
35                 void address_resolved(unsigned, const Net::SockAddr &);
36                 void resolve_failed(unsigned, const std::exception &);
37         };
38
39         Net::StreamSocket *sock;
40         IO::EventDispatcher *event_disp;
41         Net::Resolver *resolver;
42         ResolveListener *resolve_listener;
43         unsigned resolve_tag;
44         std::string user_agent;
45         Request *request;
46         Response *response;
47         std::string in_buf;
48
49         Client(const Client &);
50         Client &operator=(const Client &);
51 public:
52         Client();
53         ~Client();
54
55         void use_event_dispatcher(IO::EventDispatcher *);
56         void use_resolver(Net::Resolver *);
57         void set_user_agent(const std::string &);
58         void start_request(const Request &);
59         const Response *get_url(const std::string &);
60         void tick();
61         void wait_response();
62         void abort();
63         const Request *get_request() const { return request; }
64         const Response *get_response() const { return response; }
65 private:
66         void address_resolved(unsigned, const Net::SockAddr &);
67         void resolve_failed(unsigned, const std::exception &);
68         void connect_finished(const std::exception *);
69         void data_available();
70 };
71
72 } // namespace Http
73 } // namespace Msp
74
75 #endif