}
bool CGIFormFile::saveData (MotorEnv* env) {
- static const int bsize = 65536 * 4;
+ static const size_t bsize = 65536 * 4;
size_t size = postSize ();
ustring b;
size_t s;
s = std::cin.read (&b[0], s).gcount ();
if (s <= 0)
break;
- s = ::write (fp.fd, &b[0], s);
+ ::write (fp.fd, &b[0], s);
size -= s;
mapsize += s;
- if (size > 0) {
- std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: reading " << mapsize << "Bytes...\n"; // cerrはバッファリングされない
- }
}
-// fp.close ();
- std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n";
+// fp.close (); mmapした後にクローズする。
+// std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n"; // 出力サイズが大きいと、デッドロックする。
mapdata = (char*)mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fp.fd, 0);
#ifdef DEBUG2
std::cerr << (void*) mapdata << ": " << mapsize << "\n";
}
void CGIFormFile::unlinkTmpFile () {
- if (mapdata > 0) {
+ if (mapdata != NULL) {
munmap (mapdata, mapsize);
mapdata = NULL;
}
};
void CGIFormFile::readMimeHead (char*& b, char* e, ustring& disp, ustring& name, ustring& filename, ustring& type) {
-// boost::match_results<char*> m;
ChSplitterNL sp (b, e);
boost::match_results<char*> m2;
-// char* x;
static uregex re_disp1 ("^Content-Disposition:\\s*(.*);\\s*name=\"(.*)\";\\s*filename=\"(.*)\"$");
static uregex re_disp2 ("^Content-Disposition:\\s*(.*);\\s*name=\"(.*)\"$");
static uregex re_type ("^Content-Type:\\s*([a-zA-Z_0-9/.+-]*)(;\\s*(.*))?$");
name.resize (0);
filename.resize (0);
type.resize (0);
-// while (b != e && regex_search (b, e, m, re_nl, boost::regex_constants::match_single_line)) {
-// x = m[0].first;
while (sp.next ()) {
#ifdef DEBUG2
-// std::cerr << "line:" << ustring (b, x) << "\n";
std::cerr << "line:" << sp.pre () << "\n";
#endif /* DEBUG */
-// if (b == x) { // empty line
-// b = m[0].second;
if (sp.b == sp.t) {
b = sp.u;
break;
}
-// if (regex_search (b, x, m2, re_disp1, boost::regex_constants::match_single_line)) {
if (regex_search (sp.b, sp.t, m2, re_disp1, boost::regex_constants::match_single_line)) {
disp.assign (m2[1].first, m2[1].second - m2[1].first);
name.assign (m2[2].first, m2[2].second - m2[2].first);
filename.assign (m2[3].first, m2[3].second - m2[3].first);
-// } else if (regex_search (b, x, m2, re_disp2, boost::regex_constants::match_single_line)) {
} else if (regex_search (sp.b, sp.t, m2, re_disp2, boost::regex_constants::match_single_line)) {
disp.assign (m2[1].first, m2[1].second - m2[1].first);
name.assign (m2[2].first, m2[2].second - m2[2].first);
-// } else if (regex_search (b, x, m2, re_type, boost::regex_constants::match_single_line)) {
} else if (regex_search (sp.b, sp.t, m2, re_type, boost::regex_constants::match_single_line)) {
type.assign (m2[1].first, m2[1].second - m2[1].first);
} else {
#ifdef DEBUG2
-// std::cerr << "not match:" << ustring (b, x) << "\n";
std::cerr << "not match:" << sp.pre () << "\n";
#endif /* DEBUG */
}
-// b = m[0].second;
}
}