ppsspp/net/http_client.h

67 lines
1.1 KiB
C
Raw Normal View History

#ifndef _NET_HTTP_HTTP_CLIENT
#define _NET_HTTP_HTTP_CLIENT
#include "base/basictypes.h"
#include "base/buffer.h"
#ifndef _WIN32
#include <arpa/inet.h>
#include <sys/socket.h>
#else
#include <winsock2.h>
#endif
namespace net {
class Connection {
2012-10-30 12:20:55 +00:00
public:
Connection();
virtual ~Connection();
2012-10-30 12:20:55 +00:00
// Inits the sockaddr_in.
bool Resolve(const char *host, int port);
2012-10-30 12:20:55 +00:00
void Connect();
void Disconnect();
2012-10-30 12:20:55 +00:00
// Disconnects, and connects. Doesn't re-resolve.
void Reconnect();
2012-10-30 12:20:55 +00:00
// Only to be used for bring-up and debugging.
uintptr_t sock() const { return sock_; }
2012-10-30 12:20:55 +00:00
protected:
// Store the remote host here, so we can send it along through HTTP/1.1 requests.
// TODO: Move to http::client?
std::string host_;
int port_;
2012-10-30 12:20:55 +00:00
sockaddr_in remote_;
private:
uintptr_t sock_;
};
2012-10-30 12:20:55 +00:00
} // namespace net
namespace http {
class Client : public net::Connection {
2012-10-30 12:20:55 +00:00
public:
Client();
~Client();
2012-10-30 12:20:55 +00:00
void GET(const char *resource, Buffer *output);
2012-10-30 12:20:55 +00:00
// Return value is the HTTP return code.
int POST(const char *resource, const std::string &data, Buffer *output);
2012-10-30 12:20:55 +00:00
// HEAD, PUT, DELETE aren't implemented yet.
};
2012-10-30 12:20:55 +00:00
} // http
2012-10-30 12:20:55 +00:00
#endif // _NET_HTTP_HTTP_CLIENT