comparison src/kaigo/horori/searcher/include/net.h @ 47:169936fed61b

small changes.
author pyon@macmini
date Tue, 21 Apr 2020 22:43:55 +0900
parents 20b42e2deae1
children 4e14902379da
comparison
equal deleted inserted replaced
46:6ec28d3c3e00 47:169936fed61b
1 // Filename : net.h 1 // Filename : net.h
2 // Last Change: 2020-03-30 ŒŽ 15:05:58. 2 // Last Change: 2020-04-21 ‰Î 13:44:57.
3 // 3 //
4 #pragma once 4 #pragma once
5 5
6 #include <wx/sstream.h> 6 #include <wx/sstream.h>
7 #include <wx/wfstream.h> 7 #include <wx/wfstream.h>
71 wxFileOutputStream file_ostream(wxString::Format(wxT("%s/%d"), dir, i++)); 71 wxFileOutputStream file_ostream(wxString::Format(wxT("%s/%d"), dir, i++));
72 file_ostream.Write(tar_istream); 72 file_ostream.Write(tar_istream);
73 file_ostream.Close(); 73 file_ostream.Close();
74 } 74 }
75 ret = true; 75 ret = true;
76 //wxDELETE(httpStream);
76 } 77 }
77 78
78 //wxDELETE(httpStream);
79 get.Close(); 79 get.Close();
80 return ret; 80 return ret;
81 }; 81 };
82 82
83 bool HttpPostFile(wxString addr, wxString port, wxString url, wxString file)
84 {
85 bool ret = false;
86
87 wxMemoryBuffer buf;
88 wxByte b[8192];
89 wxFFile f;
90 if (!f.Open(file, wxT("rb"))) {
91 wxMessageBox(wxT("Cannot open file."));
92 return ret;
93 }
94 for (;;) {
95 size_t len = f.Read(b, sizeof(b));
96 if ((size_t)wxInvalidOffset == len) {
97 return ret;
98 }
99 if (len == 0) break; // success
100 buf.AppendData(b, len);
101 }
102 f.Close();
103
104 wxHTTP post;
105 post.SetTimeout(30);
106 post.SetFlags(wxSOCKET_WAITALL|wxSOCKET_BLOCK);
107 post.SetPostBuffer(wxT("application/gzip"), buf);
108
109 while (!post.Connect(addr, wxAtoi(port)))
110 wxSleep(1);
111
112 wxInputStream *httpStream = post.GetInputStream(url);
113 if (httpStream != NULL) {
114 wxString res;
115 wxStringOutputStream out_stream(&res);
116 httpStream->Read(out_stream);
117 wxDELETE(httpStream);
118 //wxMessageBox(res);
119 ret = true;
120 }
121
122 post.Close();
123 return ret;
124 };
125