Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/stream/http.hpp
2 views
1
#ifdef NALL_STREAM_INTERNAL_HPP
2
3
namespace nall {
4
5
struct httpstream : stream {
6
inline bool seekable() const { return true; }
7
inline bool readable() const { return true; }
8
inline bool writable() const { return true; }
9
inline bool randomaccess() const { return true; }
10
11
inline unsigned size() const { return psize; }
12
inline unsigned offset() const { return poffset; }
13
inline void seek(unsigned offset) const { poffset = offset; }
14
15
inline uint8_t read() const { return pdata[poffset++]; }
16
inline void write(uint8_t data) const { pdata[poffset++] = data; }
17
18
inline uint8_t read(unsigned offset) const { return pdata[offset]; }
19
inline void write(unsigned offset, uint8_t data) const { pdata[offset] = data; }
20
21
inline httpstream(const string &url, unsigned port) : pdata(nullptr), psize(0), poffset(0) {
22
string uri = url;
23
uri.ltrim<1>("http://");
24
lstring part = uri.split<1>("/");
25
part[1] = { "/", part[1] };
26
27
http connection;
28
if(connection.connect(part[0], port) == false) return;
29
connection.download(part[1], pdata, psize);
30
}
31
32
inline ~httpstream() {
33
if(pdata) delete[] pdata;
34
}
35
36
private:
37
mutable uint8_t *pdata;
38
mutable unsigned psize, poffset;
39
};
40
41
}
42
43
#endif
44
45